@wordpress/media-editor 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/build/components/media-editor/index.cjs +74 -21
- 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 +23 -3
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +6 -11
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +17 -1
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +4 -5
- 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 +1 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- 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 +0 -1
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +10 -4
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +32 -67
- 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-module/components/media-editor/index.mjs +78 -25
- 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 +23 -3
- 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 +1 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- 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 +0 -1
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +10 -5
- 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-style/style-rtl.css +104 -57
- package/build-style/style.css +103 -57
- package/build-types/components/media-editor/index.d.ts +17 -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-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 +33 -52
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +22 -23
- package/src/components/media-editor/index.tsx +163 -28
- 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 +1 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +0 -1
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +32 -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 +155 -240
- package/src/style.scss +2 -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,379 +0,0 @@
|
|
|
1
|
-
import { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';
|
|
2
|
-
import type { HandlePosition, NormalizedRect, Size } from './types';
|
|
3
|
-
|
|
4
|
-
export type { HandlePosition };
|
|
5
|
-
|
|
6
|
-
/** Axis whose resize distance controls the locked-ratio size projection. */
|
|
7
|
-
export type ResizeDriverAxis = 'width' | 'height';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Resolve the minimum crop dimension, in source-image pixels, for the current
|
|
11
|
-
* display scale.
|
|
12
|
-
*
|
|
13
|
-
* Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that
|
|
14
|
-
* avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that
|
|
15
|
-
* keeps the crop large enough to grab. The on-screen floor converted to source
|
|
16
|
-
* pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the
|
|
17
|
-
* larger of the two. When the image is shown small (small `displayScale`) the
|
|
18
|
-
* on-screen floor dominates; once it is shown large enough the source-pixel
|
|
19
|
-
* floor takes over.
|
|
20
|
-
*
|
|
21
|
-
* @param displayScale CSS pixels rendered per source pixel
|
|
22
|
-
* (fit scale × zoom × view scale).
|
|
23
|
-
* @return Minimum crop dimension in source-image pixels.
|
|
24
|
-
*/
|
|
25
|
-
export function getMinCropPixels( displayScale: number ): number {
|
|
26
|
-
if ( displayScale <= 0 ) {
|
|
27
|
-
return MIN_CROP_PIXELS;
|
|
28
|
-
}
|
|
29
|
-
return Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Default minimum crop rect dimension in normalized space, used when no
|
|
34
|
-
* explicit per-axis minimum is supplied (e.g. before the source image
|
|
35
|
-
* has loaded). Real usage derives a pixel-based min from the source
|
|
36
|
-
* image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.
|
|
37
|
-
*/
|
|
38
|
-
export const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Bounds within which the crop rect must stay.
|
|
42
|
-
*/
|
|
43
|
-
export interface CropBounds {
|
|
44
|
-
minX: number;
|
|
45
|
-
minY: number;
|
|
46
|
-
maxX: number;
|
|
47
|
-
maxY: number;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Drag state for tracking a resize interaction.
|
|
52
|
-
*/
|
|
53
|
-
export interface ResizeDragState {
|
|
54
|
-
/** Which handle is being dragged. */
|
|
55
|
-
handle: HandlePosition;
|
|
56
|
-
/** The mouse position (pixels) when the drag started. */
|
|
57
|
-
startX: number;
|
|
58
|
-
startY: number;
|
|
59
|
-
/** The crop rect (normalized) when the drag started. */
|
|
60
|
-
startRect: NormalizedRect;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Compute the new crop rect for a free (no aspect ratio) resize.
|
|
65
|
-
*
|
|
66
|
-
* Each edge moves independently based on the handle being dragged.
|
|
67
|
-
* Edges are clamped to the provided bounds and maintain a minimum size.
|
|
68
|
-
*
|
|
69
|
-
* @param drag The current drag state.
|
|
70
|
-
* @param clientX Current mouse/touch X position in pixels.
|
|
71
|
-
* @param clientY Current mouse/touch Y position in pixels.
|
|
72
|
-
* @param imageSize The rendered image dimensions in pixels.
|
|
73
|
-
* @param bounds The allowed crop area bounds.
|
|
74
|
-
* @param minCropSize Minimum crop rect dimension in normalized space, per axis.
|
|
75
|
-
* @return The new crop rect in normalized coordinates.
|
|
76
|
-
*/
|
|
77
|
-
export function computeFreeResizeRect(
|
|
78
|
-
drag: ResizeDragState,
|
|
79
|
-
clientX: number,
|
|
80
|
-
clientY: number,
|
|
81
|
-
imageSize: Size,
|
|
82
|
-
bounds: CropBounds,
|
|
83
|
-
minCropSize: Size = DEFAULT_MIN_CROP_SIZE
|
|
84
|
-
): NormalizedRect {
|
|
85
|
-
const dx =
|
|
86
|
-
imageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;
|
|
87
|
-
const dy =
|
|
88
|
-
imageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;
|
|
89
|
-
|
|
90
|
-
const s = drag.startRect;
|
|
91
|
-
const handle = drag.handle;
|
|
92
|
-
|
|
93
|
-
let edgeTop = s.y;
|
|
94
|
-
let edgeBottom = s.y + s.height;
|
|
95
|
-
let edgeLeft = s.x;
|
|
96
|
-
let edgeRight = s.x + s.width;
|
|
97
|
-
|
|
98
|
-
if ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {
|
|
99
|
-
edgeTop = Math.max(
|
|
100
|
-
bounds.minY,
|
|
101
|
-
Math.min( s.y + dy, edgeBottom - minCropSize.height )
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
if ( handle === 's' || handle === 'sw' || handle === 'se' ) {
|
|
105
|
-
edgeBottom = Math.max(
|
|
106
|
-
edgeTop + minCropSize.height,
|
|
107
|
-
Math.min( s.y + s.height + dy, bounds.maxY )
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
if ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {
|
|
111
|
-
edgeLeft = Math.max(
|
|
112
|
-
bounds.minX,
|
|
113
|
-
Math.min( s.x + dx, edgeRight - minCropSize.width )
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
if ( handle === 'e' || handle === 'ne' || handle === 'se' ) {
|
|
117
|
-
edgeRight = Math.max(
|
|
118
|
-
edgeLeft + minCropSize.width,
|
|
119
|
-
Math.min( s.x + s.width + dx, bounds.maxX )
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
x: edgeLeft,
|
|
125
|
-
y: edgeTop,
|
|
126
|
-
width: edgeRight - edgeLeft,
|
|
127
|
-
height: edgeBottom - edgeTop,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Compute the new crop rect for a locked-aspect-ratio corner resize.
|
|
133
|
-
*
|
|
134
|
-
* The opposite corner is the anchor. The dragged corner moves freely
|
|
135
|
-
* but the result is clamped to maintain the aspect ratio and stay
|
|
136
|
-
* within bounds.
|
|
137
|
-
*
|
|
138
|
-
* @param drag The current drag state.
|
|
139
|
-
* @param clientX Current mouse/touch X position in pixels.
|
|
140
|
-
* @param clientY Current mouse/touch Y position in pixels.
|
|
141
|
-
* @param imageSize The rendered image dimensions in pixels.
|
|
142
|
-
* @param bounds The allowed crop area bounds.
|
|
143
|
-
* @param normalizedRatio The locked aspect ratio (width / height in normalized space).
|
|
144
|
-
* @param minCropSize Minimum crop rect dimension in normalized space, per axis.
|
|
145
|
-
* @param driverAxis Optional explicit driver axis. Used for keyboard
|
|
146
|
-
* resize, where one arrow axis should determine the step.
|
|
147
|
-
* @return The new crop rect in normalized coordinates.
|
|
148
|
-
*/
|
|
149
|
-
export function computeLockedResizeRect(
|
|
150
|
-
drag: ResizeDragState,
|
|
151
|
-
clientX: number,
|
|
152
|
-
clientY: number,
|
|
153
|
-
imageSize: Size,
|
|
154
|
-
bounds: CropBounds,
|
|
155
|
-
normalizedRatio: number,
|
|
156
|
-
minCropSize: Size = DEFAULT_MIN_CROP_SIZE,
|
|
157
|
-
driverAxis?: ResizeDriverAxis
|
|
158
|
-
): NormalizedRect {
|
|
159
|
-
// The math below divides by `normalizedRatio` and `imageSize`, so
|
|
160
|
-
// bail out with the start rect when any of them is zero. This can
|
|
161
|
-
// happen if a resize is triggered (e.g. via keyboard arrows on a
|
|
162
|
-
// focused handle) before the image has loaded.
|
|
163
|
-
if (
|
|
164
|
-
normalizedRatio <= 0 ||
|
|
165
|
-
imageSize.width <= 0 ||
|
|
166
|
-
imageSize.height <= 0
|
|
167
|
-
) {
|
|
168
|
-
return { ...drag.startRect };
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const dx = ( clientX - drag.startX ) / imageSize.width;
|
|
172
|
-
const dy = ( clientY - drag.startY ) / imageSize.height;
|
|
173
|
-
|
|
174
|
-
const s = drag.startRect;
|
|
175
|
-
const handle = drag.handle;
|
|
176
|
-
|
|
177
|
-
// Determine the anchor corner (opposite to the dragged corner).
|
|
178
|
-
const anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;
|
|
179
|
-
const anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;
|
|
180
|
-
|
|
181
|
-
// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).
|
|
182
|
-
const dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;
|
|
183
|
-
const dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;
|
|
184
|
-
|
|
185
|
-
// Desired new position of the dragged corner.
|
|
186
|
-
const draggedX =
|
|
187
|
-
( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;
|
|
188
|
-
const draggedY =
|
|
189
|
-
( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;
|
|
190
|
-
|
|
191
|
-
// Raw distances from anchor to dragged corner.
|
|
192
|
-
let distW = ( draggedX - anchorX ) * dirX;
|
|
193
|
-
let distH = ( draggedY - anchorY ) * dirY;
|
|
194
|
-
|
|
195
|
-
// Enforce minimum size on both axes, projecting through the ratio so
|
|
196
|
-
// neither axis falls below its per-axis floor.
|
|
197
|
-
const minDistW = Math.max(
|
|
198
|
-
minCropSize.width,
|
|
199
|
-
minCropSize.height * normalizedRatio
|
|
200
|
-
);
|
|
201
|
-
const minDistH = minDistW / normalizedRatio;
|
|
202
|
-
distW = Math.max( distW, minDistW );
|
|
203
|
-
distH = Math.max( distH, minDistH );
|
|
204
|
-
|
|
205
|
-
// Determine which axis "drives". Pointer drags use the dragged-corner
|
|
206
|
-
// geometry so the projected crop changes continuously as the pointer moves.
|
|
207
|
-
// Keyboard resize passes an explicit axis because a single-axis arrow step
|
|
208
|
-
// should drive that axis instead of being cancelled by the unchanged axis.
|
|
209
|
-
const pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;
|
|
210
|
-
const isWidthDriver =
|
|
211
|
-
driverAxis === 'width' ||
|
|
212
|
-
( ! driverAxis &&
|
|
213
|
-
( distW * imageSize.width ) / ( distH * imageSize.height ) >
|
|
214
|
-
pixelRatio );
|
|
215
|
-
|
|
216
|
-
if ( isWidthDriver ) {
|
|
217
|
-
// Width is the driver — compute height from ratio.
|
|
218
|
-
distH = distW / normalizedRatio;
|
|
219
|
-
} else {
|
|
220
|
-
// Height is the driver — compute width from ratio.
|
|
221
|
-
distW = distH * normalizedRatio;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Clamp to image coverage bounds. If the rect would exceed,
|
|
225
|
-
// shrink it (maintaining ratio) to fit.
|
|
226
|
-
const maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;
|
|
227
|
-
const maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;
|
|
228
|
-
|
|
229
|
-
if ( distW > maxW ) {
|
|
230
|
-
distW = maxW;
|
|
231
|
-
distH = distW / normalizedRatio;
|
|
232
|
-
}
|
|
233
|
-
if ( distH > maxH ) {
|
|
234
|
-
distH = maxH;
|
|
235
|
-
distW = distH * normalizedRatio;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Enforce minimum after clamping.
|
|
239
|
-
distW = Math.max( distW, minDistW );
|
|
240
|
-
distH = Math.max( distH, minDistH );
|
|
241
|
-
|
|
242
|
-
// Compute the final rect position from the anchor.
|
|
243
|
-
const newX = dirX > 0 ? anchorX : anchorX - distW;
|
|
244
|
-
const newY = dirY > 0 ? anchorY : anchorY - distH;
|
|
245
|
-
|
|
246
|
-
return { x: newX, y: newY, width: distW, height: distH };
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Compute the new crop rect for a resize that temporarily locks the
|
|
251
|
-
* aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).
|
|
252
|
-
*
|
|
253
|
-
* Corner handles delegate to {@link computeLockedResizeRect}. Edge
|
|
254
|
-
* handles size the dragged axis freely, then expand the perpendicular
|
|
255
|
-
* axis symmetrically around the rect's center to preserve the ratio,
|
|
256
|
-
* clamping symmetrically so the rect stays within bounds.
|
|
257
|
-
*
|
|
258
|
-
* @param drag The current drag state.
|
|
259
|
-
* @param clientX Current mouse/touch X position in pixels.
|
|
260
|
-
* @param clientY Current mouse/touch Y position in pixels.
|
|
261
|
-
* @param imageSize The rendered image dimensions in pixels.
|
|
262
|
-
* @param bounds The allowed crop area bounds.
|
|
263
|
-
* @param minCropSize Minimum crop rect dimension in normalized space, per axis.
|
|
264
|
-
* @return The new crop rect in normalized coordinates.
|
|
265
|
-
*/
|
|
266
|
-
export function computeShiftLockedResizeRect(
|
|
267
|
-
drag: ResizeDragState,
|
|
268
|
-
clientX: number,
|
|
269
|
-
clientY: number,
|
|
270
|
-
imageSize: Size,
|
|
271
|
-
bounds: CropBounds,
|
|
272
|
-
minCropSize: Size = DEFAULT_MIN_CROP_SIZE
|
|
273
|
-
): NormalizedRect {
|
|
274
|
-
const s = drag.startRect;
|
|
275
|
-
const pixelW = s.width * imageSize.width;
|
|
276
|
-
const pixelH = s.height * imageSize.height;
|
|
277
|
-
if ( pixelH <= 0 || pixelW <= 0 ) {
|
|
278
|
-
return computeFreeResizeRect(
|
|
279
|
-
drag,
|
|
280
|
-
clientX,
|
|
281
|
-
clientY,
|
|
282
|
-
imageSize,
|
|
283
|
-
bounds,
|
|
284
|
-
minCropSize
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
const normalizedRatio = s.width / s.height;
|
|
288
|
-
|
|
289
|
-
const handle = drag.handle;
|
|
290
|
-
if (
|
|
291
|
-
handle === 'nw' ||
|
|
292
|
-
handle === 'ne' ||
|
|
293
|
-
handle === 'sw' ||
|
|
294
|
-
handle === 'se'
|
|
295
|
-
) {
|
|
296
|
-
return computeLockedResizeRect(
|
|
297
|
-
drag,
|
|
298
|
-
clientX,
|
|
299
|
-
clientY,
|
|
300
|
-
imageSize,
|
|
301
|
-
bounds,
|
|
302
|
-
normalizedRatio,
|
|
303
|
-
minCropSize
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Edge handle: size the dragged axis with free-resize logic, then
|
|
308
|
-
// expand the perpendicular axis symmetrically around the rect's center.
|
|
309
|
-
const free = computeFreeResizeRect(
|
|
310
|
-
drag,
|
|
311
|
-
clientX,
|
|
312
|
-
clientY,
|
|
313
|
-
imageSize,
|
|
314
|
-
bounds,
|
|
315
|
-
minCropSize
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
if ( handle === 'n' || handle === 's' ) {
|
|
319
|
-
// Height is the driver; derive width from ratio.
|
|
320
|
-
let newHeight = free.height;
|
|
321
|
-
let newWidth = newHeight * normalizedRatio;
|
|
322
|
-
const centerX = s.x + s.width / 2;
|
|
323
|
-
// Symmetric clamp: limit by the smaller of the two side gaps so
|
|
324
|
-
// the rect stays centered around centerX.
|
|
325
|
-
const maxWidth =
|
|
326
|
-
Math.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;
|
|
327
|
-
if ( newWidth > maxWidth ) {
|
|
328
|
-
newWidth = maxWidth;
|
|
329
|
-
newHeight = newWidth / normalizedRatio;
|
|
330
|
-
}
|
|
331
|
-
// Enforce the minimum on the driving axis, then derive the
|
|
332
|
-
// other axis from the ratio so it stays consistent. The
|
|
333
|
-
// effective minimum height has to satisfy the per-axis floor
|
|
334
|
-
// on both axes simultaneously.
|
|
335
|
-
const minHeight = Math.max(
|
|
336
|
-
minCropSize.height,
|
|
337
|
-
minCropSize.width / normalizedRatio
|
|
338
|
-
);
|
|
339
|
-
if ( newHeight < minHeight ) {
|
|
340
|
-
newHeight = minHeight;
|
|
341
|
-
newWidth = newHeight * normalizedRatio;
|
|
342
|
-
}
|
|
343
|
-
// Re-anchor the dragged axis to the opposite edge so the
|
|
344
|
-
// height adjustment after clamping keeps that edge fixed.
|
|
345
|
-
const newY = handle === 'n' ? s.y + s.height - newHeight : s.y;
|
|
346
|
-
return {
|
|
347
|
-
x: centerX - newWidth / 2,
|
|
348
|
-
y: newY,
|
|
349
|
-
width: newWidth,
|
|
350
|
-
height: newHeight,
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// 'e' or 'w': width is the driver; derive height from ratio.
|
|
355
|
-
let newWidth = free.width;
|
|
356
|
-
let newHeight = newWidth / normalizedRatio;
|
|
357
|
-
const centerY = s.y + s.height / 2;
|
|
358
|
-
const maxHeight =
|
|
359
|
-
Math.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;
|
|
360
|
-
if ( newHeight > maxHeight ) {
|
|
361
|
-
newHeight = maxHeight;
|
|
362
|
-
newWidth = newHeight * normalizedRatio;
|
|
363
|
-
}
|
|
364
|
-
const minWidth = Math.max(
|
|
365
|
-
minCropSize.width,
|
|
366
|
-
minCropSize.height * normalizedRatio
|
|
367
|
-
);
|
|
368
|
-
if ( newWidth < minWidth ) {
|
|
369
|
-
newWidth = minWidth;
|
|
370
|
-
newHeight = newWidth / normalizedRatio;
|
|
371
|
-
}
|
|
372
|
-
const newX = handle === 'w' ? s.x + s.width - newWidth : s.x;
|
|
373
|
-
return {
|
|
374
|
-
x: newX,
|
|
375
|
-
y: centerY - newHeight / 2,
|
|
376
|
-
width: newWidth,
|
|
377
|
-
height: newHeight,
|
|
378
|
-
};
|
|
379
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { CropperState, Size } from './types';
|
|
2
|
-
import { degreesToRadians } from './math/rotation';
|
|
3
|
-
import { isValidSize, sanitizeCropperState } from './math/sanitize';
|
|
4
|
-
|
|
5
|
-
/** Identity CSS transform — applied when inputs aren't safe to compose. */
|
|
6
|
-
const IDENTITY_MATRIX_STYLE = 'matrix(1, 0, 0, 1, 0, 0)';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Computes a CSS matrix() transform string from the cropper state.
|
|
10
|
-
*
|
|
11
|
-
* The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)
|
|
12
|
-
* expressed as a 2D CSS matrix(a, b, c, d, tx, ty).
|
|
13
|
-
*
|
|
14
|
-
* Flip is composed outside rotation so it is viewport-relative — horizontal
|
|
15
|
-
* flip mirrors across the viewport's vertical axis regardless of rotation.
|
|
16
|
-
* Must match the matrix order in `createCamera` / `getImageCropBounds`.
|
|
17
|
-
*
|
|
18
|
-
* This is a pure function with no framework dependencies. The React hook
|
|
19
|
-
* `useTransformStyle` wraps this in `useMemo` for memoization.
|
|
20
|
-
*
|
|
21
|
-
* @param state The current cropper state.
|
|
22
|
-
* @param imageSize The rendered image dimensions in pixels.
|
|
23
|
-
* @return A CSS transform string.
|
|
24
|
-
*/
|
|
25
|
-
export function computeTransformStyle(
|
|
26
|
-
state: CropperState,
|
|
27
|
-
imageSize: Size
|
|
28
|
-
): string {
|
|
29
|
-
// Match the identity short-circuit used by `createCamera` and
|
|
30
|
-
// `getSourceRegion` so the preview path stays consistent with the math
|
|
31
|
-
// path when `imageSize` itself is hostile (state sanitization below
|
|
32
|
-
// only guards the state fields, not these size arguments).
|
|
33
|
-
if ( ! isValidSize( imageSize ) ) {
|
|
34
|
-
return IDENTITY_MATRIX_STYLE;
|
|
35
|
-
}
|
|
36
|
-
// Sanitize so hostile state can't produce `matrix(NaN, NaN, ...)` here
|
|
37
|
-
// while the parallel `createCamera` path returns a finite matrix. Both
|
|
38
|
-
// paths must agree under defense-in-depth conditions.
|
|
39
|
-
const safeState = sanitizeCropperState( state );
|
|
40
|
-
const translateX = safeState.pan.x * imageSize.width;
|
|
41
|
-
const translateY = safeState.pan.y * imageSize.height;
|
|
42
|
-
const rad = degreesToRadians( safeState.rotation );
|
|
43
|
-
const cos = Math.cos( rad );
|
|
44
|
-
const sin = Math.sin( rad );
|
|
45
|
-
const sx = safeState.flip.horizontal ? -1 : 1;
|
|
46
|
-
const sy = safeState.flip.vertical ? -1 : 1;
|
|
47
|
-
const z = safeState.zoom;
|
|
48
|
-
|
|
49
|
-
// Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)
|
|
50
|
-
const a = sx * cos * z;
|
|
51
|
-
const b = sy * sin * z;
|
|
52
|
-
const c = -sx * sin * z;
|
|
53
|
-
const d = sy * cos * z;
|
|
54
|
-
|
|
55
|
-
return `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;
|
|
56
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { TransformOperation, CropperState } from '../types';
|
|
2
|
-
import { DEFAULT_STATE } from '../constants';
|
|
3
|
-
import { cropperReducer } from '../state';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Apply a single transform operation to a cropper state, returning
|
|
7
|
-
* a new state with the containment invariant enforced.
|
|
8
|
-
*
|
|
9
|
-
* Delegates to the reducer via APPLY_OPERATION so pipeline replay
|
|
10
|
-
* produces identical bounded state to UI interaction or setter
|
|
11
|
-
* calls. The same logical operation yields the same result
|
|
12
|
-
* regardless of entrypoint.
|
|
13
|
-
*
|
|
14
|
-
* @param state The current cropper state.
|
|
15
|
-
* @param op The operation to apply.
|
|
16
|
-
* @return A new cropper state with the operation applied.
|
|
17
|
-
*/
|
|
18
|
-
export function applyOperationToState(
|
|
19
|
-
state: CropperState,
|
|
20
|
-
op: TransformOperation
|
|
21
|
-
): CropperState {
|
|
22
|
-
return cropperReducer( state, { type: 'APPLY_OPERATION', payload: op } );
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Replay all operations from an initial state to produce the final state.
|
|
27
|
-
*
|
|
28
|
-
* @param pipeline The array of transform operations to replay.
|
|
29
|
-
* @param initialState The starting state. Defaults to DEFAULT_STATE.
|
|
30
|
-
* @return The resulting cropper state after all operations are applied.
|
|
31
|
-
*/
|
|
32
|
-
export function stateFromPipeline(
|
|
33
|
-
pipeline: TransformOperation[],
|
|
34
|
-
initialState: CropperState = { ...DEFAULT_STATE }
|
|
35
|
-
): CropperState {
|
|
36
|
-
return pipeline.reduce(
|
|
37
|
-
( state, op ) => applyOperationToState( state, op ),
|
|
38
|
-
initialState
|
|
39
|
-
);
|
|
40
|
-
}
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import type { mat2d } from 'gl-matrix';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A 2D camera represented as a 2×3 affine transformation matrix (`mat2d`).
|
|
5
|
-
*
|
|
6
|
-
* This is not a camera object with properties — it's a raw 6-element matrix
|
|
7
|
-
* `[a, b, c, d, tx, ty]` that maps normalized world coordinates [0,1] to
|
|
8
|
-
* screen pixels. It composes pan, rotation, flip, zoom, and contain-fit
|
|
9
|
-
* into a single transform.
|
|
10
|
-
*
|
|
11
|
-
* Use `createCamera()` to build one from `CropperState`, then pass it to
|
|
12
|
-
* `worldToScreen()` / `screenToWorld()` for coordinate conversion.
|
|
13
|
-
*
|
|
14
|
-
* A 3D camera would use `mat4`; this is strictly 2D (no perspective).
|
|
15
|
-
*/
|
|
16
|
-
export type Camera = mat2d;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A point with normalized coordinates (0-1 range relative to image dimensions).
|
|
20
|
-
*/
|
|
21
|
-
export interface NormalizedPoint {
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A rectangle with normalized coordinates (0-1 range).
|
|
28
|
-
* Origin is the top-left corner of the image.
|
|
29
|
-
*/
|
|
30
|
-
export interface NormalizedRect {
|
|
31
|
-
x: number;
|
|
32
|
-
y: number;
|
|
33
|
-
width: number;
|
|
34
|
-
height: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Width and height dimensions.
|
|
39
|
-
*/
|
|
40
|
-
export interface Size {
|
|
41
|
-
width: number;
|
|
42
|
-
height: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Flip state for horizontal and vertical axes.
|
|
47
|
-
*/
|
|
48
|
-
export interface Flip {
|
|
49
|
-
horizontal: boolean;
|
|
50
|
-
vertical: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* A JSON-serializable transform operation for the non-destructive pipeline.
|
|
55
|
-
*/
|
|
56
|
-
export type TransformOperation =
|
|
57
|
-
| { type: 'crop'; rect: NormalizedRect }
|
|
58
|
-
| { type: 'rotate'; degrees: number }
|
|
59
|
-
| { type: 'flip'; direction: 'horizontal' | 'vertical' }
|
|
60
|
-
| { type: 'zoom'; factor: number };
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Full cropper state.
|
|
64
|
-
*/
|
|
65
|
-
export interface CropperState {
|
|
66
|
-
/** The source image information. Null until an image is loaded. */
|
|
67
|
-
image: {
|
|
68
|
-
src: string;
|
|
69
|
-
naturalWidth: number;
|
|
70
|
-
naturalHeight: number;
|
|
71
|
-
} | null;
|
|
72
|
-
/**
|
|
73
|
-
* Image pan offset in normalized coordinates. Not the crop
|
|
74
|
-
* rectangle — that's `cropRect` below.
|
|
75
|
-
*/
|
|
76
|
-
pan: NormalizedPoint;
|
|
77
|
-
/** Zoom level. 1 = no zoom. */
|
|
78
|
-
zoom: number;
|
|
79
|
-
/** Rotation in degrees, normalized to 0-360. */
|
|
80
|
-
rotation: number;
|
|
81
|
-
/**
|
|
82
|
-
* Base pan/zoom/rotation — the pose the user last explicitly set.
|
|
83
|
-
*
|
|
84
|
-
* During continuous fine rotation (SET_ROTATION), every tick
|
|
85
|
-
* re-derives the transient `pan`/`zoom` from these base values
|
|
86
|
-
* rather than compounding on the previous tick. This prevents
|
|
87
|
-
* drift from accumulated containment clamping near image edges:
|
|
88
|
-
* rotating 0°→30°→0° returns to the exact starting pan, not a
|
|
89
|
-
* slightly-nudged version of it.
|
|
90
|
-
*
|
|
91
|
-
* These are updated by every action except SET_ROTATION itself —
|
|
92
|
-
* explicit zoom, pan, crop-rect, flip, and 90° snap all commit
|
|
93
|
-
* the post-containment state into base. SET_ROTATION reads from
|
|
94
|
-
* `basePan` and `baseRotation` to compute the new pan, and reads
|
|
95
|
-
* `baseZoom` as the zoom floor (enforceContainment may bump it up
|
|
96
|
-
* to cover the rotated crop, but never leaves it above baseZoom).
|
|
97
|
-
*/
|
|
98
|
-
basePan: NormalizedPoint;
|
|
99
|
-
baseZoom: number;
|
|
100
|
-
baseRotation: number;
|
|
101
|
-
/** Flip state. */
|
|
102
|
-
flip: Flip;
|
|
103
|
-
/** The crop rectangle in normalized coordinates. */
|
|
104
|
-
cropRect: NormalizedRect;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Internal reducer action union.
|
|
109
|
-
*
|
|
110
|
-
* This type is intentionally not exported from the image-editor public barrel.
|
|
111
|
-
* Consumers should drive state through the controller returned by
|
|
112
|
-
* `useCropperController()` (or a composite store) or through serializable
|
|
113
|
-
* `TransformOperation` values.
|
|
114
|
-
*/
|
|
115
|
-
export type CropperAction =
|
|
116
|
-
/** Sets the loaded image metadata (natural size, src). */
|
|
117
|
-
| { type: 'SET_IMAGE'; payload: CropperState[ 'image' ] }
|
|
118
|
-
/** Sets the image pan offset. (Crop rectangle is SET_CROP_RECT.) */
|
|
119
|
-
| { type: 'SET_PAN'; payload: NormalizedPoint }
|
|
120
|
-
/** Sets the zoom level, clamped to [coverage-aware min, MAX_ZOOM]. */
|
|
121
|
-
| { type: 'SET_ZOOM'; payload: number }
|
|
122
|
-
/**
|
|
123
|
-
* Sets zoom and pan together atomically. Used by focal-point
|
|
124
|
-
* zoom (wheel, pinch) to keep a target point stationary while
|
|
125
|
-
* zoom changes.
|
|
126
|
-
*/
|
|
127
|
-
| {
|
|
128
|
-
type: 'SET_ZOOM_AT_POINT';
|
|
129
|
-
payload: { zoom: number; pan: NormalizedPoint };
|
|
130
|
-
}
|
|
131
|
-
/** Sets the absolute rotation angle in degrees. */
|
|
132
|
-
| { type: 'SET_ROTATION'; payload: number }
|
|
133
|
-
/** Rotates by +/-90 degrees (snap). */
|
|
134
|
-
| { type: 'SNAP_ROTATE_90'; payload: { direction: 1 | -1 } }
|
|
135
|
-
/** Sets the flip state. */
|
|
136
|
-
| { type: 'SET_FLIP'; payload: Flip }
|
|
137
|
-
/** Sets the crop rectangle. */
|
|
138
|
-
| { type: 'SET_CROP_RECT'; payload: NormalizedRect }
|
|
139
|
-
/** Settle animation after resize drag, recentering the crop rect. */
|
|
140
|
-
| { type: 'SETTLE_CROP' }
|
|
141
|
-
/** Applies a single pipeline transform via the reducer. */
|
|
142
|
-
| { type: 'APPLY_OPERATION'; payload: TransformOperation }
|
|
143
|
-
/** Resets to DEFAULT_STATE, optionally merging a partial override. */
|
|
144
|
-
| { type: 'RESET'; payload?: Partial< CropperState > };
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Viewport camera state — display-only, does not affect export or undo.
|
|
148
|
-
*
|
|
149
|
-
* Applied as a CSS transform on the inner stage div so the user can scroll
|
|
150
|
-
* the view independently of the crop. zoom > 1 magnifies; pan shifts in CSS px.
|
|
151
|
-
*/
|
|
152
|
-
export interface ViewportState {
|
|
153
|
-
zoom: number;
|
|
154
|
-
pan: { x: number; y: number };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export type ViewportAction =
|
|
158
|
-
| { type: 'SET_VIEWPORT_ZOOM'; payload: number }
|
|
159
|
-
| { type: 'SET_VIEWPORT_PAN'; payload: { x: number; y: number } }
|
|
160
|
-
| { type: 'RESET_VIEWPORT' };
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Direction of a crop resize handle. Eight compass positions: four
|
|
164
|
-
* corners and four edge midpoints. Used by stencil callbacks and any
|
|
165
|
-
* overlay that needs to know which handle the user is dragging.
|
|
166
|
-
*/
|
|
167
|
-
export type HandlePosition = 'n' | 's' | 'e' | 'w' | 'nw' | 'ne' | 'sw' | 'se';
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* The contract for a pluggable stencil component.
|
|
171
|
-
* Stencils render the crop area overlay and handle resize interactions.
|
|
172
|
-
*/
|
|
173
|
-
export interface StencilProps {
|
|
174
|
-
/** The current crop rectangle in normalized coordinates. */
|
|
175
|
-
cropRect: NormalizedRect;
|
|
176
|
-
/** The container element dimensions in pixels. */
|
|
177
|
-
containerSize: Size;
|
|
178
|
-
/** The rendered image dimensions in pixels within the container. */
|
|
179
|
-
imageSize: Size;
|
|
180
|
-
/** Callback when the crop rectangle changes (during drag). */
|
|
181
|
-
onCropChange: ( rect: NormalizedRect ) => void;
|
|
182
|
-
/**
|
|
183
|
-
* Callback when a resize interaction starts — pointerdown on a handle
|
|
184
|
-
* or the first arrow-key press on a focused handle. The handle direction
|
|
185
|
-
* is passed so downstream overlays can anchor to it. The argument is
|
|
186
|
-
* optional to keep custom stencils that don't track a direction
|
|
187
|
-
* backward-compatible.
|
|
188
|
-
*/
|
|
189
|
-
onResizeStart?: ( handle?: HandlePosition ) => void;
|
|
190
|
-
/** Callback when a resize drag ends (mouseup after handle drag). */
|
|
191
|
-
onResizeEnd?: () => void;
|
|
192
|
-
/** Optional fixed aspect ratio (width / height) in pixel space. */
|
|
193
|
-
aspectRatio?: number;
|
|
194
|
-
/** Whether the crop handles are shown for freeform resizing. */
|
|
195
|
-
freeformCrop?: boolean;
|
|
196
|
-
/** Whether resize handles should ignore pointer and keyboard input. */
|
|
197
|
-
isResizeDisabled?: boolean;
|
|
198
|
-
/** CSS transition string for settle animation. */
|
|
199
|
-
stencilTransition?: string;
|
|
200
|
-
/** Maximum crop rect bounds based on current zoom/rotation. */
|
|
201
|
-
cropBounds?: {
|
|
202
|
-
minX: number;
|
|
203
|
-
minY: number;
|
|
204
|
-
maxX: number;
|
|
205
|
-
maxY: number;
|
|
206
|
-
};
|
|
207
|
-
/** Called when Escape is pressed on a resize handle. */
|
|
208
|
-
onEscape?: () => void;
|
|
209
|
-
/**
|
|
210
|
-
* Minimum crop rect dimension in normalized space, per axis. Derived
|
|
211
|
-
* by the host from a pixel-based floor (see `MIN_CROP_PIXELS`) and
|
|
212
|
-
* the source image dimensions. Omit to use the stencil's default.
|
|
213
|
-
*/
|
|
214
|
-
minCropSize?: Size;
|
|
215
|
-
/**
|
|
216
|
-
* Optional post-processor for freeform resize output. Hosts use this for
|
|
217
|
-
* display-gated behavior such as snapping visible pixel grids to source
|
|
218
|
-
* pixel boundaries.
|
|
219
|
-
*/
|
|
220
|
-
snapCropRect?: (
|
|
221
|
-
rect: NormalizedRect,
|
|
222
|
-
handle: HandlePosition
|
|
223
|
-
) => NormalizedRect;
|
|
224
|
-
/**
|
|
225
|
-
* Optional keyboard resize step in normalized space, per axis. Hosts use
|
|
226
|
-
* this when keyboard resize should follow the rendered image scale instead
|
|
227
|
-
* of the default percentage-based step.
|
|
228
|
-
*/
|
|
229
|
-
keyboardResizeStep?: Size;
|
|
230
|
-
}
|