@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,976 +0,0 @@
|
|
|
1
|
-
import type { CropperState, NormalizedPoint, Size } from './types';
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_KEYBOARD_STEP,
|
|
4
|
-
DEFAULT_WHEEL_ZOOM_SPEED,
|
|
5
|
-
KEYBOARD_SHIFT_STEP_MULTIPLIER,
|
|
6
|
-
MIN_ZOOM,
|
|
7
|
-
MAX_ZOOM,
|
|
8
|
-
} from './constants';
|
|
9
|
-
import { restrictPanZoom } from './containment';
|
|
10
|
-
|
|
11
|
-
/** Time window for detecting a double-tap gesture (ms). */
|
|
12
|
-
const DOUBLE_TAP_TIME = 300;
|
|
13
|
-
/** Max distance between taps to count as a double-tap (px). */
|
|
14
|
-
const DOUBLE_TAP_DISTANCE = 30;
|
|
15
|
-
/** Duration of the zoom animation state (ms). */
|
|
16
|
-
const ZOOM_ANIMATION_DURATION = 200;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get the natural image dimensions from cropper state, falling back to 1x1.
|
|
20
|
-
*
|
|
21
|
-
* @param state The current cropper state.
|
|
22
|
-
* @return The image dimensions.
|
|
23
|
-
*/
|
|
24
|
-
function getImageSizeFromState( state: CropperState ): {
|
|
25
|
-
width: number;
|
|
26
|
-
height: number;
|
|
27
|
-
} {
|
|
28
|
-
return state.image
|
|
29
|
-
? { width: state.image.naturalWidth, height: state.image.naturalHeight }
|
|
30
|
-
: { width: 1, height: 1 };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get the distance between two touch points.
|
|
35
|
-
*
|
|
36
|
-
* @param t1 The first touch.
|
|
37
|
-
* @param t2 The second touch.
|
|
38
|
-
* @return The pixel distance between the two touches.
|
|
39
|
-
*/
|
|
40
|
-
function getTouchDistance( t1: Touch, t2: Touch ): number {
|
|
41
|
-
const dx = t1.clientX - t2.clientX;
|
|
42
|
-
const dy = t1.clientY - t2.clientY;
|
|
43
|
-
return Math.sqrt( dx * dx + dy * dy );
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Status reported by the interaction controller when drag/zoom state changes.
|
|
48
|
-
*/
|
|
49
|
-
export interface InteractionStatus {
|
|
50
|
-
/** Whether a drag (pan) interaction is in progress. */
|
|
51
|
-
isDragging: boolean;
|
|
52
|
-
/** Whether a double-tap zoom animation is in progress. */
|
|
53
|
-
isZooming: boolean;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* State updates the interaction controller can request from its host UI.
|
|
58
|
-
*/
|
|
59
|
-
export interface CropperInteractionActions {
|
|
60
|
-
/** Set the image pan offset in normalized coordinates. */
|
|
61
|
-
setPan: ( pan: NormalizedPoint ) => void;
|
|
62
|
-
/**
|
|
63
|
-
* Set the zoom level. Cursorless surfaces (slider, keyboard `+`/`-`)
|
|
64
|
-
* rely on this anchoring at the crop center; pointer-driven zoom
|
|
65
|
-
* paths use `setZoomAtPoint` with an explicit focal point instead.
|
|
66
|
-
*/
|
|
67
|
-
setZoom: ( zoom: number ) => void;
|
|
68
|
-
/** Set zoom and pan together for focal-point zoom. */
|
|
69
|
-
setZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;
|
|
70
|
-
/** Snap rotate by 90 degrees. */
|
|
71
|
-
snapRotate90: ( direction: 1 | -1 ) => void;
|
|
72
|
-
/** Toggle flip on the given axis. */
|
|
73
|
-
toggleFlip?: ( direction: 'horizontal' | 'vertical' ) => void;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Options for creating an InteractionController.
|
|
78
|
-
*
|
|
79
|
-
* Scalar options (minZoom, maxZoom, etc.) are read lazily on each
|
|
80
|
-
* interaction, so changes to the options object take effect immediately
|
|
81
|
-
* without recreating the controller.
|
|
82
|
-
*/
|
|
83
|
-
export interface InteractionControllerOptions {
|
|
84
|
-
/** Returns the current cropper state. Called on every interaction. */
|
|
85
|
-
getState: () => CropperState;
|
|
86
|
-
/** State updates the interaction controller can request from its host UI. */
|
|
87
|
-
actions: CropperInteractionActions;
|
|
88
|
-
/** Returns the container dimensions in pixels. */
|
|
89
|
-
getContainerSize: () => Size;
|
|
90
|
-
/** Returns the rendered image dimensions in pixels, if available. */
|
|
91
|
-
getImageSize: () => Size | undefined;
|
|
92
|
-
/** Minimum zoom level. Defaults to MIN_ZOOM. Read lazily. */
|
|
93
|
-
minZoom?: number;
|
|
94
|
-
/** Maximum zoom level. Defaults to MAX_ZOOM. Read lazily. */
|
|
95
|
-
maxZoom?: number;
|
|
96
|
-
/** Zoom speed multiplier for wheel events. Defaults to 0.0025. Read lazily. */
|
|
97
|
-
zoomSpeed?: number;
|
|
98
|
-
/**
|
|
99
|
-
* Pan step size in normalized coords for keyboard events.
|
|
100
|
-
* Defaults to 0.01. Read lazily. Shift multiplies it by 10.
|
|
101
|
-
*/
|
|
102
|
-
keyboardStep?: number;
|
|
103
|
-
/** Zoom level for double-tap zoom. Defaults to 2. Read lazily. */
|
|
104
|
-
doubleTapZoom?: number;
|
|
105
|
-
/** Fires when a continuous gesture begins (pan drag, pinch zoom). */
|
|
106
|
-
onGestureStart?: () => void;
|
|
107
|
-
/** Fires when a continuous gesture ends (pointer release). */
|
|
108
|
-
onGestureEnd?: () => void;
|
|
109
|
-
/** Called when isDragging or isZooming changes. */
|
|
110
|
-
onStatusChange?: ( status: InteractionStatus ) => void;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Framework-agnostic imperative controller for image cropper interactions.
|
|
115
|
-
*
|
|
116
|
-
* Handles mouse, touch, and keyboard event processing for pan, zoom,
|
|
117
|
-
* and crop manipulation. Uses requestAnimationFrame for drag/pinch
|
|
118
|
-
* updates to avoid layout thrashing.
|
|
119
|
-
*
|
|
120
|
-
* The controller does not register DOM event listeners itself — that is the
|
|
121
|
-
* responsibility of the UI layer (React hook, Vue directive, or vanilla JS).
|
|
122
|
-
* Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,
|
|
123
|
-
* and `handleKeyDown` methods that the UI layer calls with native DOM events.
|
|
124
|
-
*
|
|
125
|
-
* Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)
|
|
126
|
-
* are read lazily from `this.options` on each interaction, so the UI layer
|
|
127
|
-
* can update them without recreating the controller.
|
|
128
|
-
*
|
|
129
|
-
* Call `destroy()` to clean up timers and pending animation frames.
|
|
130
|
-
*/
|
|
131
|
-
export class InteractionController {
|
|
132
|
-
private readonly options: InteractionControllerOptions;
|
|
133
|
-
|
|
134
|
-
/** Current drag/zoom status. */
|
|
135
|
-
private isDragging = false;
|
|
136
|
-
private isZooming = false;
|
|
137
|
-
|
|
138
|
-
/** Active drag state during pointer interactions. */
|
|
139
|
-
private drag: {
|
|
140
|
-
startX: number;
|
|
141
|
-
startY: number;
|
|
142
|
-
startPanX: number;
|
|
143
|
-
startPanY: number;
|
|
144
|
-
} | null = null;
|
|
145
|
-
|
|
146
|
-
/** Active touch state during touch interactions. */
|
|
147
|
-
private touch: {
|
|
148
|
-
/** Finger distance at pinch start (0 until pinch detected). */
|
|
149
|
-
startDistance: number;
|
|
150
|
-
/** Zoom level when pinch was detected. */
|
|
151
|
-
startZoom: number;
|
|
152
|
-
/** First touch X/Y (for single-finger pan delta). */
|
|
153
|
-
lastTouchX: number;
|
|
154
|
-
lastTouchY: number;
|
|
155
|
-
/** Pan when gesture started. */
|
|
156
|
-
startPanX: number;
|
|
157
|
-
startPanY: number;
|
|
158
|
-
/** Container rect snapshot for focal-point math. */
|
|
159
|
-
containerRect?: DOMRect;
|
|
160
|
-
/** Midpoint of two fingers when pinch was detected. */
|
|
161
|
-
startMidX: number;
|
|
162
|
-
startMidY: number;
|
|
163
|
-
/** Whether pinch was ever detected during this gesture. */
|
|
164
|
-
didPinch: boolean;
|
|
165
|
-
/** Whether any dispatch has occurred (prevents dispatching before first move). */
|
|
166
|
-
moved: boolean;
|
|
167
|
-
} | null = null;
|
|
168
|
-
|
|
169
|
-
/** Cleanup function for active touch listeners on document. */
|
|
170
|
-
private touchCleanup: ( () => void ) | null = null;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Cleanup function for active pointer-drag listeners on the
|
|
174
|
-
* captured element. Set while a pointer drag is in progress so
|
|
175
|
-
* `destroy()` can tear the drag down cleanly if the consumer
|
|
176
|
-
* unmounts mid-drag. Cleared on pointerup/lostpointercapture.
|
|
177
|
-
*/
|
|
178
|
-
private pointerCleanup: ( () => void ) | null = null;
|
|
179
|
-
|
|
180
|
-
/** Last tap info for double-tap detection. */
|
|
181
|
-
private lastTap: {
|
|
182
|
-
time: number;
|
|
183
|
-
x: number;
|
|
184
|
-
y: number;
|
|
185
|
-
} | null = null;
|
|
186
|
-
|
|
187
|
-
/** Timer for the zoom animation state (double-tap). */
|
|
188
|
-
private zoomTimer: ReturnType< typeof setTimeout > | undefined;
|
|
189
|
-
|
|
190
|
-
/** Timer for wheel gesture debounce. */
|
|
191
|
-
private wheelGestureTimer: ReturnType< typeof setTimeout > | undefined;
|
|
192
|
-
|
|
193
|
-
/** Whether a wheel gesture is currently active. */
|
|
194
|
-
private wheelGestureActive = false;
|
|
195
|
-
|
|
196
|
-
/** Current requestAnimationFrame ID. */
|
|
197
|
-
private rafId = 0;
|
|
198
|
-
|
|
199
|
-
constructor( options: InteractionControllerOptions ) {
|
|
200
|
-
this.options = options;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/** Read minZoom lazily so option changes take effect immediately. */
|
|
204
|
-
private get minZoom(): number {
|
|
205
|
-
return this.options.minZoom ?? MIN_ZOOM;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/** Read maxZoom lazily so option changes take effect immediately. */
|
|
209
|
-
private get maxZoom(): number {
|
|
210
|
-
return this.options.maxZoom ?? MAX_ZOOM;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** Read zoomSpeed lazily so option changes take effect immediately. */
|
|
214
|
-
private get zoomSpeed(): number {
|
|
215
|
-
return this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/** Read keyboardStep lazily so option changes take effect immediately. */
|
|
219
|
-
private get keyboardStep(): number {
|
|
220
|
-
return this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Get the keyboard pan step, including modifier-based coarse movement.
|
|
225
|
-
*
|
|
226
|
-
* @param event The native KeyboardEvent.
|
|
227
|
-
* @return The normalized pan step.
|
|
228
|
-
*/
|
|
229
|
-
private getKeyboardStep( event: KeyboardEvent ): number {
|
|
230
|
-
return event.shiftKey
|
|
231
|
-
? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER
|
|
232
|
-
: this.keyboardStep;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/** Read doubleTapZoom lazily so option changes take effect immediately. */
|
|
236
|
-
private get doubleTapZoom(): number {
|
|
237
|
-
return this.options.doubleTapZoom ?? 2;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Update the drag/zoom status and notify via callback if changed.
|
|
242
|
-
*
|
|
243
|
-
* @param update Partial status with isDragging and/or isZooming.
|
|
244
|
-
*/
|
|
245
|
-
private setStatus(
|
|
246
|
-
update: Partial< { isDragging: boolean; isZooming: boolean } >
|
|
247
|
-
): void {
|
|
248
|
-
let changed = false;
|
|
249
|
-
if (
|
|
250
|
-
update.isDragging !== undefined &&
|
|
251
|
-
update.isDragging !== this.isDragging
|
|
252
|
-
) {
|
|
253
|
-
this.isDragging = update.isDragging;
|
|
254
|
-
changed = true;
|
|
255
|
-
}
|
|
256
|
-
if (
|
|
257
|
-
update.isZooming !== undefined &&
|
|
258
|
-
update.isZooming !== this.isZooming
|
|
259
|
-
) {
|
|
260
|
-
this.isZooming = update.isZooming;
|
|
261
|
-
changed = true;
|
|
262
|
-
}
|
|
263
|
-
if ( changed ) {
|
|
264
|
-
this.options.onStatusChange?.( {
|
|
265
|
-
isDragging: this.isDragging,
|
|
266
|
-
isZooming: this.isZooming,
|
|
267
|
-
} );
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Handle a pointer-down event on the container element.
|
|
273
|
-
*
|
|
274
|
-
* Initiates a drag (pan) interaction. Captures the pointer on the
|
|
275
|
-
* provided element and registers pointermove/pointerup/lostpointercapture
|
|
276
|
-
* listeners for the duration of the drag.
|
|
277
|
-
*
|
|
278
|
-
* @param e The native PointerEvent.
|
|
279
|
-
* @param el The DOM element to capture the pointer on.
|
|
280
|
-
*/
|
|
281
|
-
handlePointerDown( e: PointerEvent, el: HTMLElement ): void {
|
|
282
|
-
// Only handle primary button (left click / first touch).
|
|
283
|
-
if ( e.button !== 0 ) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
// Touch gestures are handled by touchstart/touchmove. Starting the
|
|
287
|
-
// pointer drag path too can briefly toggle drag UI before pinch begins.
|
|
288
|
-
if ( e.pointerType === 'touch' ) {
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
e.preventDefault();
|
|
292
|
-
|
|
293
|
-
// Blur any focused handle so its focus ring doesn't linger,
|
|
294
|
-
// but leave the canvas itself alone so keyboard control works after drag.
|
|
295
|
-
const ownerDoc = el.ownerDocument;
|
|
296
|
-
if (
|
|
297
|
-
ownerDoc?.activeElement instanceof HTMLElement &&
|
|
298
|
-
ownerDoc.activeElement !== el
|
|
299
|
-
) {
|
|
300
|
-
ownerDoc.activeElement.blur();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
el.focus();
|
|
304
|
-
|
|
305
|
-
// Capture pointer so drag works across iframe boundaries.
|
|
306
|
-
el.setPointerCapture( e.pointerId );
|
|
307
|
-
|
|
308
|
-
// End a pending wheel gesture now, so its debounce timer cannot
|
|
309
|
-
// fire mid-drag and end the drag's gesture along with it.
|
|
310
|
-
if ( this.wheelGestureActive ) {
|
|
311
|
-
clearTimeout( this.wheelGestureTimer );
|
|
312
|
-
this.wheelGestureActive = false;
|
|
313
|
-
this.options.onGestureEnd?.();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
this.setStatus( { isDragging: true } );
|
|
317
|
-
this.options.onGestureStart?.();
|
|
318
|
-
|
|
319
|
-
const currentState = this.options.getState();
|
|
320
|
-
this.drag = {
|
|
321
|
-
startX: e.clientX,
|
|
322
|
-
startY: e.clientY,
|
|
323
|
-
startPanX: currentState.pan.x,
|
|
324
|
-
startPanY: currentState.pan.y,
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
const onPointerMove = ( moveEvent: Event ) => {
|
|
328
|
-
const drag = this.drag;
|
|
329
|
-
if ( ! drag ) {
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const pe = moveEvent as PointerEvent;
|
|
333
|
-
|
|
334
|
-
cancelAnimationFrame( this.rafId );
|
|
335
|
-
this.rafId = requestAnimationFrame( () => {
|
|
336
|
-
const s = this.options.getState();
|
|
337
|
-
const imgSize = this.options.getImageSize();
|
|
338
|
-
const containerSize = this.options.getContainerSize();
|
|
339
|
-
const panSize = imgSize ?? containerSize;
|
|
340
|
-
const deltaX =
|
|
341
|
-
panSize.width > 0
|
|
342
|
-
? ( pe.clientX - drag.startX ) / panSize.width
|
|
343
|
-
: 0;
|
|
344
|
-
const deltaY =
|
|
345
|
-
panSize.height > 0
|
|
346
|
-
? ( pe.clientY - drag.startY ) / panSize.height
|
|
347
|
-
: 0;
|
|
348
|
-
|
|
349
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
350
|
-
{
|
|
351
|
-
...s,
|
|
352
|
-
pan: {
|
|
353
|
-
x: drag.startPanX + deltaX,
|
|
354
|
-
y: drag.startPanY + deltaY,
|
|
355
|
-
},
|
|
356
|
-
},
|
|
357
|
-
getImageSizeFromState( s ),
|
|
358
|
-
s.cropRect
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
this.options.actions.setPan( newCrop );
|
|
362
|
-
} );
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
const removeListeners = () => {
|
|
366
|
-
el.removeEventListener( 'pointermove', onPointerMove );
|
|
367
|
-
el.removeEventListener( 'pointerup', onPointerUp );
|
|
368
|
-
el.removeEventListener( 'lostpointercapture', onPointerUp );
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
const onPointerUp = () => {
|
|
372
|
-
this.setStatus( { isDragging: false } );
|
|
373
|
-
this.options.onGestureEnd?.();
|
|
374
|
-
this.drag = null;
|
|
375
|
-
cancelAnimationFrame( this.rafId );
|
|
376
|
-
removeListeners();
|
|
377
|
-
this.pointerCleanup = null;
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
el.addEventListener( 'pointermove', onPointerMove );
|
|
381
|
-
el.addEventListener( 'pointerup', onPointerUp );
|
|
382
|
-
el.addEventListener( 'lostpointercapture', onPointerUp );
|
|
383
|
-
// Expose cleanup to destroy() in case the consumer unmounts
|
|
384
|
-
// mid-drag. The pending rAF is cancelled in destroy().
|
|
385
|
-
this.pointerCleanup = removeListeners;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Handle a wheel event on the container element.
|
|
390
|
-
*
|
|
391
|
-
* Implements focal-point zoom: the point under the cursor stays
|
|
392
|
-
* stationary on screen while the zoom level changes.
|
|
393
|
-
*
|
|
394
|
-
* Must be registered with `{ passive: false }` to allow preventDefault.
|
|
395
|
-
*
|
|
396
|
-
* @param e The native WheelEvent.
|
|
397
|
-
*/
|
|
398
|
-
handleWheel( e: WheelEvent ): void {
|
|
399
|
-
e.preventDefault();
|
|
400
|
-
|
|
401
|
-
if ( this.drag ) {
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// Debounced gesture boundaries for wheel zoom.
|
|
406
|
-
// Start on first wheel event, end after 300ms of no events.
|
|
407
|
-
if ( ! this.wheelGestureActive ) {
|
|
408
|
-
this.wheelGestureActive = true;
|
|
409
|
-
this.options.onGestureStart?.();
|
|
410
|
-
}
|
|
411
|
-
clearTimeout( this.wheelGestureTimer );
|
|
412
|
-
this.wheelGestureTimer = setTimeout( () => {
|
|
413
|
-
this.wheelGestureActive = false;
|
|
414
|
-
this.options.onGestureEnd?.();
|
|
415
|
-
}, DOUBLE_TAP_TIME );
|
|
416
|
-
|
|
417
|
-
const s = this.options.getState();
|
|
418
|
-
const delta = -e.deltaY * this.zoomSpeed;
|
|
419
|
-
const newZoom = Math.min(
|
|
420
|
-
this.maxZoom,
|
|
421
|
-
Math.max( this.minZoom, s.zoom + delta )
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
if ( newZoom === s.zoom ) {
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// Focal-point zoom: keep the point under the cursor stationary.
|
|
429
|
-
const containerSize = this.options.getContainerSize();
|
|
430
|
-
const imgSize = this.options.getImageSize();
|
|
431
|
-
const visSize = imgSize ?? containerSize;
|
|
432
|
-
const target = e.currentTarget;
|
|
433
|
-
const rect =
|
|
434
|
-
target instanceof Element
|
|
435
|
-
? target.getBoundingClientRect()
|
|
436
|
-
: undefined;
|
|
437
|
-
if ( visSize.width > 0 && visSize.height > 0 && rect ) {
|
|
438
|
-
const fx = e.clientX - rect.left - containerSize.width / 2;
|
|
439
|
-
const fy = e.clientY - rect.top - containerSize.height / 2;
|
|
440
|
-
|
|
441
|
-
const zoomRatio = 1 - newZoom / s.zoom;
|
|
442
|
-
const focalNormX = fx / visSize.width;
|
|
443
|
-
const focalNormY = fy / visSize.height;
|
|
444
|
-
const newCropX = s.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;
|
|
445
|
-
const newCropY = s.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;
|
|
446
|
-
|
|
447
|
-
const { pan: clampedCrop } = restrictPanZoom(
|
|
448
|
-
{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },
|
|
449
|
-
getImageSizeFromState( s ),
|
|
450
|
-
s.cropRect
|
|
451
|
-
);
|
|
452
|
-
this.options.actions.setZoomAtPoint( newZoom, clampedCrop );
|
|
453
|
-
} else {
|
|
454
|
-
this.options.actions.setZoom( newZoom );
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Handle a touch-start event on the container element.
|
|
460
|
-
*
|
|
461
|
-
* Supports single-finger pan, two-finger pinch zoom, and
|
|
462
|
-
* double-tap to toggle between fit and 2x zoom. Registers
|
|
463
|
-
* touchmove/touchend/touchcancel on the provided document for the
|
|
464
|
-
* duration of the gesture.
|
|
465
|
-
*
|
|
466
|
-
* @param e The native TouchEvent.
|
|
467
|
-
* @param containerRect The bounding rect of the container element.
|
|
468
|
-
* @param doc The document to register move/end listeners on.
|
|
469
|
-
* Defaults to globalThis.document. Pass the iframe's
|
|
470
|
-
* contentDocument when running inside an iframe.
|
|
471
|
-
*/
|
|
472
|
-
handleTouchStart(
|
|
473
|
-
e: TouchEvent,
|
|
474
|
-
containerRect: DOMRect,
|
|
475
|
-
doc: Document = document
|
|
476
|
-
): void {
|
|
477
|
-
// Second finger arriving during an existing gesture — snapshot
|
|
478
|
-
// pinch start values. handleTouchMove will detect 2 touches and
|
|
479
|
-
// handle pinch automatically.
|
|
480
|
-
if ( this.touch && e.touches.length === 2 ) {
|
|
481
|
-
const s = this.options.getState();
|
|
482
|
-
const distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );
|
|
483
|
-
const midX =
|
|
484
|
-
( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;
|
|
485
|
-
const midY =
|
|
486
|
-
( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;
|
|
487
|
-
this.touch.didPinch = true;
|
|
488
|
-
this.touch.startDistance = distance;
|
|
489
|
-
this.touch.startZoom = s.zoom;
|
|
490
|
-
this.touch.startPanX = s.pan.x;
|
|
491
|
-
this.touch.startPanY = s.pan.y;
|
|
492
|
-
this.touch.startMidX = midX;
|
|
493
|
-
this.touch.startMidY = midY;
|
|
494
|
-
this.touch.containerRect = containerRect;
|
|
495
|
-
this.setStatus( { isDragging: false } );
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
if ( e.touches.length === 1 ) {
|
|
500
|
-
const tapX = e.touches[ 0 ].clientX;
|
|
501
|
-
const tapY = e.touches[ 0 ].clientY;
|
|
502
|
-
if ( this.tryDoubleTap( e, tapX, tapY, containerRect ) ) {
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
const currentState = this.options.getState();
|
|
507
|
-
|
|
508
|
-
// Record touch state. Don't decide pan vs pinch yet —
|
|
509
|
-
// that happens in handleTouchMove based on touches.length.
|
|
510
|
-
this.touch = {
|
|
511
|
-
startDistance: 0,
|
|
512
|
-
startZoom: currentState.zoom,
|
|
513
|
-
lastTouchX: e.touches[ 0 ].clientX,
|
|
514
|
-
lastTouchY: e.touches[ 0 ].clientY,
|
|
515
|
-
startPanX: currentState.pan.x,
|
|
516
|
-
startPanY: currentState.pan.y,
|
|
517
|
-
containerRect,
|
|
518
|
-
startMidX: 0,
|
|
519
|
-
startMidY: 0,
|
|
520
|
-
didPinch: false,
|
|
521
|
-
moved: false,
|
|
522
|
-
};
|
|
523
|
-
this.options.onGestureStart?.();
|
|
524
|
-
} else if ( e.touches.length === 2 ) {
|
|
525
|
-
// Both fingers landed simultaneously (rare but possible).
|
|
526
|
-
const currentState = this.options.getState();
|
|
527
|
-
const distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );
|
|
528
|
-
const midX =
|
|
529
|
-
( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;
|
|
530
|
-
const midY =
|
|
531
|
-
( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;
|
|
532
|
-
this.touch = {
|
|
533
|
-
startDistance: distance,
|
|
534
|
-
startZoom: currentState.zoom,
|
|
535
|
-
lastTouchX: 0,
|
|
536
|
-
lastTouchY: 0,
|
|
537
|
-
startPanX: currentState.pan.x,
|
|
538
|
-
startPanY: currentState.pan.y,
|
|
539
|
-
containerRect,
|
|
540
|
-
startMidX: midX,
|
|
541
|
-
startMidY: midY,
|
|
542
|
-
didPinch: true,
|
|
543
|
-
moved: false,
|
|
544
|
-
};
|
|
545
|
-
this.options.onGestureStart?.();
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
const onTouchEnd = () => {
|
|
549
|
-
this.touch = null;
|
|
550
|
-
this.touchCleanup = null;
|
|
551
|
-
cancelAnimationFrame( this.rafId );
|
|
552
|
-
doc.removeEventListener( 'touchmove', this.handleTouchMove );
|
|
553
|
-
doc.removeEventListener( 'touchend', onTouchEnd );
|
|
554
|
-
doc.removeEventListener( 'touchcancel', onTouchEnd );
|
|
555
|
-
this.setStatus( { isDragging: false } );
|
|
556
|
-
this.options.onGestureEnd?.();
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
// Clean up any previous touch listeners before registering new ones.
|
|
560
|
-
this.touchCleanup?.();
|
|
561
|
-
|
|
562
|
-
doc.addEventListener( 'touchmove', this.handleTouchMove, {
|
|
563
|
-
passive: false,
|
|
564
|
-
} );
|
|
565
|
-
doc.addEventListener( 'touchend', onTouchEnd );
|
|
566
|
-
doc.addEventListener( 'touchcancel', onTouchEnd );
|
|
567
|
-
|
|
568
|
-
this.touchCleanup = onTouchEnd;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// Handle a touchmove event during an active touch gesture. Decides pinch
|
|
572
|
-
// vs. pan based on current `moveEvent.touches.length`, so the gesture
|
|
573
|
-
// can transition between modes without timing sensitivity (e.g. fingers
|
|
574
|
-
// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays
|
|
575
|
-
// attached when used as an event listener.
|
|
576
|
-
private handleTouchMove = ( moveEvent: TouchEvent ): void => {
|
|
577
|
-
const touch = this.touch;
|
|
578
|
-
if ( ! touch ) {
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
moveEvent.preventDefault();
|
|
582
|
-
|
|
583
|
-
cancelAnimationFrame( this.rafId );
|
|
584
|
-
this.rafId = requestAnimationFrame( () => {
|
|
585
|
-
const s = this.options.getState();
|
|
586
|
-
|
|
587
|
-
if ( moveEvent.touches.length === 2 ) {
|
|
588
|
-
// Two fingers → always pinch, regardless of how gesture
|
|
589
|
-
// started. Initialize pinch state on first 2-finger move.
|
|
590
|
-
if ( ! touch.didPinch ) {
|
|
591
|
-
touch.didPinch = true;
|
|
592
|
-
touch.startDistance = getTouchDistance(
|
|
593
|
-
moveEvent.touches[ 0 ],
|
|
594
|
-
moveEvent.touches[ 1 ]
|
|
595
|
-
);
|
|
596
|
-
touch.startZoom = s.zoom;
|
|
597
|
-
touch.startPanX = s.pan.x;
|
|
598
|
-
touch.startPanY = s.pan.y;
|
|
599
|
-
touch.startMidX =
|
|
600
|
-
( moveEvent.touches[ 0 ].clientX +
|
|
601
|
-
moveEvent.touches[ 1 ].clientX ) /
|
|
602
|
-
2;
|
|
603
|
-
touch.startMidY =
|
|
604
|
-
( moveEvent.touches[ 0 ].clientY +
|
|
605
|
-
moveEvent.touches[ 1 ].clientY ) /
|
|
606
|
-
2;
|
|
607
|
-
this.setStatus( { isDragging: false } );
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
const latestContainerSize = this.options.getContainerSize();
|
|
611
|
-
const latestImageSize = this.options.getImageSize();
|
|
612
|
-
|
|
613
|
-
// Pinch zoom with focal point at finger midpoint,
|
|
614
|
-
// plus simultaneous pan from midpoint drift.
|
|
615
|
-
const t0 = moveEvent.touches[ 0 ];
|
|
616
|
-
const t1 = moveEvent.touches[ 1 ];
|
|
617
|
-
const currentDistance = getTouchDistance( t0, t1 );
|
|
618
|
-
const ratio = currentDistance / touch.startDistance;
|
|
619
|
-
const newZoom = Math.min(
|
|
620
|
-
this.maxZoom,
|
|
621
|
-
Math.max( this.minZoom, touch.startZoom * ratio )
|
|
622
|
-
);
|
|
623
|
-
|
|
624
|
-
const visSize = latestImageSize ?? latestContainerSize;
|
|
625
|
-
const rect = touch.containerRect;
|
|
626
|
-
if ( visSize.width > 0 && visSize.height > 0 && rect ) {
|
|
627
|
-
// Current midpoint.
|
|
628
|
-
const mx =
|
|
629
|
-
( t0.clientX + t1.clientX ) / 2 -
|
|
630
|
-
rect.left -
|
|
631
|
-
latestContainerSize.width / 2;
|
|
632
|
-
const my =
|
|
633
|
-
( t0.clientY + t1.clientY ) / 2 -
|
|
634
|
-
rect.top -
|
|
635
|
-
latestContainerSize.height / 2;
|
|
636
|
-
|
|
637
|
-
// Pan from midpoint drift (fingers moving together).
|
|
638
|
-
const startMx =
|
|
639
|
-
touch.startMidX -
|
|
640
|
-
rect.left -
|
|
641
|
-
latestContainerSize.width / 2;
|
|
642
|
-
const startMy =
|
|
643
|
-
touch.startMidY -
|
|
644
|
-
rect.top -
|
|
645
|
-
latestContainerSize.height / 2;
|
|
646
|
-
const panDx =
|
|
647
|
-
visSize.width > 0
|
|
648
|
-
? ( mx - startMx ) / visSize.width
|
|
649
|
-
: 0;
|
|
650
|
-
const panDy =
|
|
651
|
-
visSize.height > 0
|
|
652
|
-
? ( my - startMy ) / visSize.height
|
|
653
|
-
: 0;
|
|
654
|
-
|
|
655
|
-
// Focal-point zoom correction. Keep this based on the
|
|
656
|
-
// pinch-start state; using the current reducer state here
|
|
657
|
-
// compounds prior touchmove frames and makes a fixed pinch
|
|
658
|
-
// center drift after the image is already zoomed or panned.
|
|
659
|
-
const zoomRatio =
|
|
660
|
-
touch.startZoom !== 0
|
|
661
|
-
? 1 - newZoom / touch.startZoom
|
|
662
|
-
: 0;
|
|
663
|
-
const startFocalNormX = startMx / visSize.width;
|
|
664
|
-
const startFocalNormY = startMy / visSize.height;
|
|
665
|
-
|
|
666
|
-
// Combined: midpoint drift + zoom around the pinch-start
|
|
667
|
-
// midpoint, so moving both fingers together pans while
|
|
668
|
-
// symmetric pinches keep the start center stationary.
|
|
669
|
-
const newCropX =
|
|
670
|
-
touch.startPanX +
|
|
671
|
-
panDx +
|
|
672
|
-
( startFocalNormX - touch.startPanX ) * zoomRatio;
|
|
673
|
-
const newCropY =
|
|
674
|
-
touch.startPanY +
|
|
675
|
-
panDy +
|
|
676
|
-
( startFocalNormY - touch.startPanY ) * zoomRatio;
|
|
677
|
-
|
|
678
|
-
const { pan: clampedCrop } = restrictPanZoom(
|
|
679
|
-
{
|
|
680
|
-
...s,
|
|
681
|
-
zoom: newZoom,
|
|
682
|
-
pan: { x: newCropX, y: newCropY },
|
|
683
|
-
},
|
|
684
|
-
getImageSizeFromState( s ),
|
|
685
|
-
s.cropRect
|
|
686
|
-
);
|
|
687
|
-
this.options.actions.setZoomAtPoint( newZoom, clampedCrop );
|
|
688
|
-
} else if ( newZoom !== s.zoom ) {
|
|
689
|
-
this.options.actions.setZoom( newZoom );
|
|
690
|
-
}
|
|
691
|
-
} else if ( moveEvent.touches.length === 1 && ! touch.didPinch ) {
|
|
692
|
-
// One finger and no pinch ever detected → pan.
|
|
693
|
-
// If fingers went 2→1 (didPinch is true), we do NOT
|
|
694
|
-
// switch to pan — avoids accidental pan after releasing
|
|
695
|
-
// one finger from a pinch.
|
|
696
|
-
if ( ! touch.moved ) {
|
|
697
|
-
touch.moved = true;
|
|
698
|
-
this.setStatus( { isDragging: true } );
|
|
699
|
-
}
|
|
700
|
-
const panImageSize = this.options.getImageSize();
|
|
701
|
-
const panContainerSize = this.options.getContainerSize();
|
|
702
|
-
const panSize = panImageSize ?? panContainerSize;
|
|
703
|
-
const deltaX =
|
|
704
|
-
panSize.width > 0
|
|
705
|
-
? ( moveEvent.touches[ 0 ].clientX -
|
|
706
|
-
touch.lastTouchX ) /
|
|
707
|
-
panSize.width
|
|
708
|
-
: 0;
|
|
709
|
-
const deltaY =
|
|
710
|
-
panSize.height > 0
|
|
711
|
-
? ( moveEvent.touches[ 0 ].clientY -
|
|
712
|
-
touch.lastTouchY ) /
|
|
713
|
-
panSize.height
|
|
714
|
-
: 0;
|
|
715
|
-
|
|
716
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
717
|
-
{
|
|
718
|
-
...s,
|
|
719
|
-
pan: {
|
|
720
|
-
x: touch.startPanX + deltaX,
|
|
721
|
-
y: touch.startPanY + deltaY,
|
|
722
|
-
},
|
|
723
|
-
},
|
|
724
|
-
getImageSizeFromState( s ),
|
|
725
|
-
s.cropRect
|
|
726
|
-
);
|
|
727
|
-
|
|
728
|
-
this.options.actions.setPan( newCrop );
|
|
729
|
-
}
|
|
730
|
-
} );
|
|
731
|
-
};
|
|
732
|
-
|
|
733
|
-
// Handle double-tap-to-toggle-zoom. On a second tap within the configured
|
|
734
|
-
// time/distance threshold, toggles zoom between `minZoom` and
|
|
735
|
-
// `doubleTapZoom` around the tap point and dispatches. Returns `true` if
|
|
736
|
-
// the tap was handled as a double-tap (caller should early-return),
|
|
737
|
-
// `false` otherwise (caller proceeds with normal single-tap handling).
|
|
738
|
-
// Either way, records the tap for next time.
|
|
739
|
-
private tryDoubleTap(
|
|
740
|
-
e: TouchEvent,
|
|
741
|
-
tapX: number,
|
|
742
|
-
tapY: number,
|
|
743
|
-
containerRect: DOMRect
|
|
744
|
-
): boolean {
|
|
745
|
-
const now = Date.now();
|
|
746
|
-
const lastTap = this.lastTap;
|
|
747
|
-
if ( ! lastTap ) {
|
|
748
|
-
this.lastTap = { time: now, x: tapX, y: tapY };
|
|
749
|
-
return false;
|
|
750
|
-
}
|
|
751
|
-
const timeDelta = now - lastTap.time;
|
|
752
|
-
const distDelta = Math.sqrt(
|
|
753
|
-
( tapX - lastTap.x ) ** 2 + ( tapY - lastTap.y ) ** 2
|
|
754
|
-
);
|
|
755
|
-
const isDoubleTap =
|
|
756
|
-
timeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;
|
|
757
|
-
if ( ! isDoubleTap ) {
|
|
758
|
-
this.lastTap = { time: now, x: tapX, y: tapY };
|
|
759
|
-
return false;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
// It's a double-tap — suppress browser zoom.
|
|
763
|
-
e.preventDefault();
|
|
764
|
-
this.lastTap = null;
|
|
765
|
-
|
|
766
|
-
const currentState = this.options.getState();
|
|
767
|
-
const containerSize = this.options.getContainerSize();
|
|
768
|
-
const imgSize = this.options.getImageSize();
|
|
769
|
-
|
|
770
|
-
// Toggle: if past halfway to doubleTapZoom, go back to 1x.
|
|
771
|
-
const targetZoom =
|
|
772
|
-
currentState.zoom > ( this.minZoom + this.doubleTapZoom ) / 2
|
|
773
|
-
? this.minZoom
|
|
774
|
-
: this.doubleTapZoom;
|
|
775
|
-
const visSize = imgSize ?? containerSize;
|
|
776
|
-
|
|
777
|
-
// Enable zoom animation before dispatching.
|
|
778
|
-
this.setStatus( { isZooming: true } );
|
|
779
|
-
clearTimeout( this.zoomTimer );
|
|
780
|
-
this.zoomTimer = setTimeout( () => {
|
|
781
|
-
this.setStatus( { isZooming: false } );
|
|
782
|
-
}, ZOOM_ANIMATION_DURATION );
|
|
783
|
-
|
|
784
|
-
// Double-tap bypasses the normal handleTouchStart gesture path so
|
|
785
|
-
// onGestureStart/End are never called — fire them here so undo
|
|
786
|
-
// receives a proper boundary around this discrete zoom action.
|
|
787
|
-
this.options.onGestureStart?.();
|
|
788
|
-
|
|
789
|
-
if ( visSize.width > 0 && visSize.height > 0 ) {
|
|
790
|
-
const fx = tapX - containerRect.left - containerSize.width / 2;
|
|
791
|
-
const fy = tapY - containerRect.top - containerSize.height / 2;
|
|
792
|
-
|
|
793
|
-
const zoomRatio = 1 - targetZoom / currentState.zoom;
|
|
794
|
-
const focalNormX = fx / visSize.width;
|
|
795
|
-
const focalNormY = fy / visSize.height;
|
|
796
|
-
const newCropX =
|
|
797
|
-
currentState.pan.x +
|
|
798
|
-
( focalNormX - currentState.pan.x ) * zoomRatio;
|
|
799
|
-
const newCropY =
|
|
800
|
-
currentState.pan.y +
|
|
801
|
-
( focalNormY - currentState.pan.y ) * zoomRatio;
|
|
802
|
-
|
|
803
|
-
const { pan: clampedCrop } = restrictPanZoom(
|
|
804
|
-
{
|
|
805
|
-
...currentState,
|
|
806
|
-
zoom: targetZoom,
|
|
807
|
-
pan: { x: newCropX, y: newCropY },
|
|
808
|
-
},
|
|
809
|
-
getImageSizeFromState( currentState ),
|
|
810
|
-
currentState.cropRect
|
|
811
|
-
);
|
|
812
|
-
this.options.actions.setZoomAtPoint( targetZoom, clampedCrop );
|
|
813
|
-
} else {
|
|
814
|
-
this.options.actions.setZoom( targetZoom );
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
this.options.onGestureEnd?.();
|
|
818
|
-
return true;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
/**
|
|
822
|
-
* Handle a keydown event on the container element.
|
|
823
|
-
*
|
|
824
|
-
* Supports arrow keys for panning, +/- for zoom, and r/R for rotation.
|
|
825
|
-
*
|
|
826
|
-
* @param e The native KeyboardEvent.
|
|
827
|
-
*/
|
|
828
|
-
handleKeyDown( e: KeyboardEvent ): void {
|
|
829
|
-
const currentState = this.options.getState();
|
|
830
|
-
|
|
831
|
-
switch ( e.key ) {
|
|
832
|
-
case 'ArrowUp': {
|
|
833
|
-
e.preventDefault();
|
|
834
|
-
const keyboardStep = this.getKeyboardStep( e );
|
|
835
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
836
|
-
{
|
|
837
|
-
...currentState,
|
|
838
|
-
pan: {
|
|
839
|
-
x: currentState.pan.x,
|
|
840
|
-
y: currentState.pan.y + keyboardStep,
|
|
841
|
-
},
|
|
842
|
-
},
|
|
843
|
-
getImageSizeFromState( currentState ),
|
|
844
|
-
currentState.cropRect
|
|
845
|
-
);
|
|
846
|
-
this.options.actions.setPan( newCrop );
|
|
847
|
-
break;
|
|
848
|
-
}
|
|
849
|
-
case 'ArrowDown': {
|
|
850
|
-
e.preventDefault();
|
|
851
|
-
const keyboardStep = this.getKeyboardStep( e );
|
|
852
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
853
|
-
{
|
|
854
|
-
...currentState,
|
|
855
|
-
pan: {
|
|
856
|
-
x: currentState.pan.x,
|
|
857
|
-
y: currentState.pan.y - keyboardStep,
|
|
858
|
-
},
|
|
859
|
-
},
|
|
860
|
-
getImageSizeFromState( currentState ),
|
|
861
|
-
currentState.cropRect
|
|
862
|
-
);
|
|
863
|
-
this.options.actions.setPan( newCrop );
|
|
864
|
-
break;
|
|
865
|
-
}
|
|
866
|
-
case 'ArrowLeft': {
|
|
867
|
-
e.preventDefault();
|
|
868
|
-
const keyboardStep = this.getKeyboardStep( e );
|
|
869
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
870
|
-
{
|
|
871
|
-
...currentState,
|
|
872
|
-
pan: {
|
|
873
|
-
x: currentState.pan.x + keyboardStep,
|
|
874
|
-
y: currentState.pan.y,
|
|
875
|
-
},
|
|
876
|
-
},
|
|
877
|
-
getImageSizeFromState( currentState ),
|
|
878
|
-
currentState.cropRect
|
|
879
|
-
);
|
|
880
|
-
this.options.actions.setPan( newCrop );
|
|
881
|
-
break;
|
|
882
|
-
}
|
|
883
|
-
case 'ArrowRight': {
|
|
884
|
-
e.preventDefault();
|
|
885
|
-
const keyboardStep = this.getKeyboardStep( e );
|
|
886
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
887
|
-
{
|
|
888
|
-
...currentState,
|
|
889
|
-
pan: {
|
|
890
|
-
x: currentState.pan.x - keyboardStep,
|
|
891
|
-
y: currentState.pan.y,
|
|
892
|
-
},
|
|
893
|
-
},
|
|
894
|
-
getImageSizeFromState( currentState ),
|
|
895
|
-
currentState.cropRect
|
|
896
|
-
);
|
|
897
|
-
this.options.actions.setPan( newCrop );
|
|
898
|
-
break;
|
|
899
|
-
}
|
|
900
|
-
case '+':
|
|
901
|
-
case '=': {
|
|
902
|
-
e.preventDefault();
|
|
903
|
-
const newZoom = Math.min(
|
|
904
|
-
this.maxZoom,
|
|
905
|
-
Math.max( this.minZoom, currentState.zoom + 0.5 )
|
|
906
|
-
);
|
|
907
|
-
this.options.actions.setZoom( newZoom );
|
|
908
|
-
break;
|
|
909
|
-
}
|
|
910
|
-
case '-':
|
|
911
|
-
case '_': {
|
|
912
|
-
e.preventDefault();
|
|
913
|
-
const newZoom = Math.min(
|
|
914
|
-
this.maxZoom,
|
|
915
|
-
Math.max( this.minZoom, currentState.zoom - 0.5 )
|
|
916
|
-
);
|
|
917
|
-
this.options.actions.setZoom( newZoom );
|
|
918
|
-
break;
|
|
919
|
-
}
|
|
920
|
-
case 'r':
|
|
921
|
-
case 'R': {
|
|
922
|
-
if ( e.metaKey || e.ctrlKey || e.altKey ) {
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
925
|
-
e.preventDefault();
|
|
926
|
-
this.options.actions.snapRotate90( e.shiftKey ? -1 : 1 );
|
|
927
|
-
break;
|
|
928
|
-
}
|
|
929
|
-
case 'h':
|
|
930
|
-
case 'H': {
|
|
931
|
-
if ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {
|
|
932
|
-
break;
|
|
933
|
-
}
|
|
934
|
-
e.preventDefault();
|
|
935
|
-
this.options.actions.toggleFlip?.( 'horizontal' );
|
|
936
|
-
break;
|
|
937
|
-
}
|
|
938
|
-
case 'v':
|
|
939
|
-
case 'V': {
|
|
940
|
-
if ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {
|
|
941
|
-
break;
|
|
942
|
-
}
|
|
943
|
-
e.preventDefault();
|
|
944
|
-
this.options.actions.toggleFlip?.( 'vertical' );
|
|
945
|
-
break;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
/**
|
|
951
|
-
* Clean up all timers, animation frames, and active touch listeners.
|
|
952
|
-
*
|
|
953
|
-
* Must be called when the controller is no longer needed (e.g., on
|
|
954
|
-
* component unmount or element removal).
|
|
955
|
-
*/
|
|
956
|
-
destroy(): void {
|
|
957
|
-
cancelAnimationFrame( this.rafId );
|
|
958
|
-
clearTimeout( this.zoomTimer );
|
|
959
|
-
clearTimeout( this.wheelGestureTimer );
|
|
960
|
-
this.touchCleanup?.();
|
|
961
|
-
this.touchCleanup = null;
|
|
962
|
-
this.pointerCleanup?.();
|
|
963
|
-
this.pointerCleanup = null;
|
|
964
|
-
this.drag = null;
|
|
965
|
-
this.touch = null;
|
|
966
|
-
this.lastTap = null;
|
|
967
|
-
// Reset the gesture bookkeeping too. The timers above are cancelled
|
|
968
|
-
// rather than run, so these flags would otherwise stay set: a stale
|
|
969
|
-
// `wheelGestureActive` suppresses the next wheel gesture's start,
|
|
970
|
-
// and `setStatus` dedupes against `isDragging` / `isZooming`, so a
|
|
971
|
-
// stale value swallows the next real change.
|
|
972
|
-
this.wheelGestureActive = false;
|
|
973
|
-
this.isDragging = false;
|
|
974
|
-
this.isZooming = false;
|
|
975
|
-
}
|
|
976
|
-
}
|