@wordpress/media-editor 0.21.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 +30 -0
- package/build/components/media-editor/index.cjs +586 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +42 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +131 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +117 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +81 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +61 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +181 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +82 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +113 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +59 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +100 -113
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +22 -45
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +11 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +227 -296
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +545 -675
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +37 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +95 -98
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +171 -238
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +74 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -90
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +53 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +80 -91
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +3 -26
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +7 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +223 -288
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +145 -61
- package/build-style/style.css +144 -61
- package/build-types/components/media-editor/index.d.ts +20 -2
- 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/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/state/aspect-ratio-presets.d.ts +24 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- 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 -4
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -63
- 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 +355 -167
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +9 -10
- package/src/components/media-editor/use-save-media-editor.ts +48 -10
- package/src/components/media-editor-canvas/index.tsx +30 -51
- 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 +15 -11
- 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-editor-modal/style.scss +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +65 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +9 -5
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/state/README.md +32 -0
- package/src/state/aspect-ratio-presets.ts +37 -0
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -17
- package/src/state/types.ts +18 -72
- package/src/state/use-media-editor-state.ts +155 -238
- package/src/style.scss +2 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
- package/build/image-editor/core/camera.cjs +0 -225
- package/build/image-editor/core/camera.cjs.map +0 -7
- package/build/image-editor/core/constants.cjs +0 -108
- package/build/image-editor/core/constants.cjs.map +0 -7
- package/build/image-editor/core/containment.cjs +0 -276
- package/build/image-editor/core/containment.cjs.map +0 -7
- package/build/image-editor/core/crop-rect.cjs +0 -48
- package/build/image-editor/core/crop-rect.cjs.map +0 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
- package/build/image-editor/core/index.cjs +0 -62
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/interaction-controller.cjs +0 -654
- package/build/image-editor/core/interaction-controller.cjs.map +0 -7
- package/build/image-editor/core/math/rotation.cjs +0 -41
- package/build/image-editor/core/math/rotation.cjs.map +0 -7
- package/build/image-editor/core/math/sanitize.cjs +0 -92
- package/build/image-editor/core/math/sanitize.cjs.map +0 -7
- package/build/image-editor/core/setter-helpers.cjs +0 -64
- package/build/image-editor/core/setter-helpers.cjs.map +0 -7
- package/build/image-editor/core/source-region.cjs +0 -206
- package/build/image-editor/core/source-region.cjs.map +0 -7
- package/build/image-editor/core/state.cjs +0 -283
- package/build/image-editor/core/state.cjs.map +0 -7
- package/build/image-editor/core/stencil-math.cjs +0 -216
- package/build/image-editor/core/stencil-math.cjs.map +0 -7
- package/build/image-editor/core/transform-style.cjs +0 -52
- package/build/image-editor/core/transform-style.cjs.map +0 -7
- package/build/image-editor/core/transforms/pipeline.cjs +0 -43
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
- package/build/image-editor/core/types.cjs +0 -19
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/core/viewport-state.cjs +0 -50
- package/build/image-editor/core/viewport-state.cjs.map +0 -7
- package/build/image-editor/index.cjs +0 -67
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/cropper-provider.cjs +0 -50
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
- package/build/image-editor/react/components/cropper.cjs +0 -722
- package/build/image-editor/react/components/cropper.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs +0 -36
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
- package/build/image-editor/react/components/viewport-provider.cjs +0 -51
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs +0 -34
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -213
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
- package/build/image-editor/react/visually-hidden-style.cjs +0 -41
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -66
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
- package/build-module/image-editor/core/camera.mjs +0 -198
- package/build-module/image-editor/core/camera.mjs.map +0 -7
- package/build-module/image-editor/core/constants.mjs +0 -69
- package/build-module/image-editor/core/constants.mjs.map +0 -7
- package/build-module/image-editor/core/containment.mjs +0 -253
- package/build-module/image-editor/core/containment.mjs.map +0 -7
- package/build-module/image-editor/core/crop-rect.mjs +0 -23
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
- package/build-module/image-editor/core/index.mjs +0 -36
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -635
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
- package/build-module/image-editor/core/math/rotation.mjs +0 -15
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
- package/build-module/image-editor/core/math/sanitize.mjs +0 -63
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
- package/build-module/image-editor/core/setter-helpers.mjs +0 -39
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
- package/build-module/image-editor/core/source-region.mjs +0 -178
- package/build-module/image-editor/core/source-region.mjs.map +0 -7
- package/build-module/image-editor/core/state.mjs +0 -260
- package/build-module/image-editor/core/state.mjs.map +0 -7
- package/build-module/image-editor/core/stencil-math.mjs +0 -187
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
- package/build-module/image-editor/core/transform-style.mjs +0 -27
- package/build-module/image-editor/core/transform-style.mjs.map +0 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/core/viewport-state.mjs +0 -24
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
- package/build-module/image-editor/index.mjs +0 -39
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper.mjs +0 -704
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs +0 -9
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs +0 -8
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -190
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -80
- 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 -99
- 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 -16
- 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 -63
- 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-reducer.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-reducer.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 -161
- 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 -150
- 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 -47
- 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 -52
- 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 -1116
- 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-reducer.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,635 +0,0 @@
|
|
|
1
|
-
// packages/media-editor/src/image-editor/core/interaction-controller.ts
|
|
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.mjs";
|
|
9
|
-
import { restrictPanZoom } from "./containment.mjs";
|
|
10
|
-
var DOUBLE_TAP_TIME = 300;
|
|
11
|
-
var DOUBLE_TAP_DISTANCE = 30;
|
|
12
|
-
var ZOOM_ANIMATION_DURATION = 200;
|
|
13
|
-
function getImageSizeFromState(state) {
|
|
14
|
-
return state.image ? { width: state.image.naturalWidth, height: state.image.naturalHeight } : { width: 1, height: 1 };
|
|
15
|
-
}
|
|
16
|
-
function getTouchDistance(t1, t2) {
|
|
17
|
-
const dx = t1.clientX - t2.clientX;
|
|
18
|
-
const dy = t1.clientY - t2.clientY;
|
|
19
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
20
|
-
}
|
|
21
|
-
var InteractionController = class {
|
|
22
|
-
options;
|
|
23
|
-
/** Current drag/zoom status. */
|
|
24
|
-
isDragging = false;
|
|
25
|
-
isZooming = false;
|
|
26
|
-
/** Active drag state during pointer interactions. */
|
|
27
|
-
drag = null;
|
|
28
|
-
/** Active touch state during touch interactions. */
|
|
29
|
-
touch = null;
|
|
30
|
-
/** Cleanup function for active touch listeners on document. */
|
|
31
|
-
touchCleanup = null;
|
|
32
|
-
/**
|
|
33
|
-
* Cleanup function for active pointer-drag listeners on the
|
|
34
|
-
* captured element. Set while a pointer drag is in progress so
|
|
35
|
-
* `destroy()` can tear the drag down cleanly if the consumer
|
|
36
|
-
* unmounts mid-drag. Cleared on pointerup/lostpointercapture.
|
|
37
|
-
*/
|
|
38
|
-
pointerCleanup = null;
|
|
39
|
-
/** Last tap info for double-tap detection. */
|
|
40
|
-
lastTap = null;
|
|
41
|
-
/** Timer for the zoom animation state (double-tap). */
|
|
42
|
-
zoomTimer;
|
|
43
|
-
/** Timer for wheel gesture debounce. */
|
|
44
|
-
wheelGestureTimer;
|
|
45
|
-
/** Whether a wheel gesture is currently active. */
|
|
46
|
-
wheelGestureActive = false;
|
|
47
|
-
/** Current requestAnimationFrame ID. */
|
|
48
|
-
rafId = 0;
|
|
49
|
-
constructor(options) {
|
|
50
|
-
this.options = options;
|
|
51
|
-
}
|
|
52
|
-
/** Read minZoom lazily so option changes take effect immediately. */
|
|
53
|
-
get minZoom() {
|
|
54
|
-
return this.options.minZoom ?? MIN_ZOOM;
|
|
55
|
-
}
|
|
56
|
-
/** Read maxZoom lazily so option changes take effect immediately. */
|
|
57
|
-
get maxZoom() {
|
|
58
|
-
return this.options.maxZoom ?? MAX_ZOOM;
|
|
59
|
-
}
|
|
60
|
-
/** Read zoomSpeed lazily so option changes take effect immediately. */
|
|
61
|
-
get zoomSpeed() {
|
|
62
|
-
return this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;
|
|
63
|
-
}
|
|
64
|
-
/** Read keyboardStep lazily so option changes take effect immediately. */
|
|
65
|
-
get keyboardStep() {
|
|
66
|
-
return this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Get the keyboard pan step, including modifier-based coarse movement.
|
|
70
|
-
*
|
|
71
|
-
* @param event The native KeyboardEvent.
|
|
72
|
-
* @return The normalized pan step.
|
|
73
|
-
*/
|
|
74
|
-
getKeyboardStep(event) {
|
|
75
|
-
return event.shiftKey ? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER : this.keyboardStep;
|
|
76
|
-
}
|
|
77
|
-
/** Read doubleTapZoom lazily so option changes take effect immediately. */
|
|
78
|
-
get doubleTapZoom() {
|
|
79
|
-
return this.options.doubleTapZoom ?? 2;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Update the drag/zoom status and notify via callback if changed.
|
|
83
|
-
*
|
|
84
|
-
* @param update Partial status with isDragging and/or isZooming.
|
|
85
|
-
*/
|
|
86
|
-
setStatus(update) {
|
|
87
|
-
let changed = false;
|
|
88
|
-
if (update.isDragging !== void 0 && update.isDragging !== this.isDragging) {
|
|
89
|
-
this.isDragging = update.isDragging;
|
|
90
|
-
changed = true;
|
|
91
|
-
}
|
|
92
|
-
if (update.isZooming !== void 0 && update.isZooming !== this.isZooming) {
|
|
93
|
-
this.isZooming = update.isZooming;
|
|
94
|
-
changed = true;
|
|
95
|
-
}
|
|
96
|
-
if (changed) {
|
|
97
|
-
this.options.onStatusChange?.({
|
|
98
|
-
isDragging: this.isDragging,
|
|
99
|
-
isZooming: this.isZooming
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Handle a pointer-down event on the container element.
|
|
105
|
-
*
|
|
106
|
-
* Initiates a drag (pan) interaction. Captures the pointer on the
|
|
107
|
-
* provided element and registers pointermove/pointerup/lostpointercapture
|
|
108
|
-
* listeners for the duration of the drag.
|
|
109
|
-
*
|
|
110
|
-
* @param e The native PointerEvent.
|
|
111
|
-
* @param el The DOM element to capture the pointer on.
|
|
112
|
-
*/
|
|
113
|
-
handlePointerDown(e, el) {
|
|
114
|
-
if (e.button !== 0) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (e.pointerType === "touch") {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
e.preventDefault();
|
|
121
|
-
const ownerDoc = el.ownerDocument;
|
|
122
|
-
if (ownerDoc?.activeElement instanceof HTMLElement && ownerDoc.activeElement !== el) {
|
|
123
|
-
ownerDoc.activeElement.blur();
|
|
124
|
-
}
|
|
125
|
-
el.focus();
|
|
126
|
-
el.setPointerCapture(e.pointerId);
|
|
127
|
-
if (this.wheelGestureActive) {
|
|
128
|
-
clearTimeout(this.wheelGestureTimer);
|
|
129
|
-
this.wheelGestureActive = false;
|
|
130
|
-
this.options.onGestureEnd?.();
|
|
131
|
-
}
|
|
132
|
-
this.setStatus({ isDragging: true });
|
|
133
|
-
this.options.onGestureStart?.();
|
|
134
|
-
const currentState = this.options.getState();
|
|
135
|
-
this.drag = {
|
|
136
|
-
startX: e.clientX,
|
|
137
|
-
startY: e.clientY,
|
|
138
|
-
startPanX: currentState.pan.x,
|
|
139
|
-
startPanY: currentState.pan.y
|
|
140
|
-
};
|
|
141
|
-
const onPointerMove = (moveEvent) => {
|
|
142
|
-
const drag = this.drag;
|
|
143
|
-
if (!drag) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const pe = moveEvent;
|
|
147
|
-
cancelAnimationFrame(this.rafId);
|
|
148
|
-
this.rafId = requestAnimationFrame(() => {
|
|
149
|
-
const s = this.options.getState();
|
|
150
|
-
const imgSize = this.options.getImageSize();
|
|
151
|
-
const containerSize = this.options.getContainerSize();
|
|
152
|
-
const panSize = imgSize ?? containerSize;
|
|
153
|
-
const deltaX = panSize.width > 0 ? (pe.clientX - drag.startX) / panSize.width : 0;
|
|
154
|
-
const deltaY = panSize.height > 0 ? (pe.clientY - drag.startY) / panSize.height : 0;
|
|
155
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
156
|
-
{
|
|
157
|
-
...s,
|
|
158
|
-
pan: {
|
|
159
|
-
x: drag.startPanX + deltaX,
|
|
160
|
-
y: drag.startPanY + deltaY
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
getImageSizeFromState(s),
|
|
164
|
-
s.cropRect
|
|
165
|
-
);
|
|
166
|
-
this.options.actions.setPan(newCrop);
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
const removeListeners = () => {
|
|
170
|
-
el.removeEventListener("pointermove", onPointerMove);
|
|
171
|
-
el.removeEventListener("pointerup", onPointerUp);
|
|
172
|
-
el.removeEventListener("lostpointercapture", onPointerUp);
|
|
173
|
-
};
|
|
174
|
-
const onPointerUp = () => {
|
|
175
|
-
this.setStatus({ isDragging: false });
|
|
176
|
-
this.options.onGestureEnd?.();
|
|
177
|
-
this.drag = null;
|
|
178
|
-
cancelAnimationFrame(this.rafId);
|
|
179
|
-
removeListeners();
|
|
180
|
-
this.pointerCleanup = null;
|
|
181
|
-
};
|
|
182
|
-
el.addEventListener("pointermove", onPointerMove);
|
|
183
|
-
el.addEventListener("pointerup", onPointerUp);
|
|
184
|
-
el.addEventListener("lostpointercapture", onPointerUp);
|
|
185
|
-
this.pointerCleanup = removeListeners;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Handle a wheel event on the container element.
|
|
189
|
-
*
|
|
190
|
-
* Implements focal-point zoom: the point under the cursor stays
|
|
191
|
-
* stationary on screen while the zoom level changes.
|
|
192
|
-
*
|
|
193
|
-
* Must be registered with `{ passive: false }` to allow preventDefault.
|
|
194
|
-
*
|
|
195
|
-
* @param e The native WheelEvent.
|
|
196
|
-
*/
|
|
197
|
-
handleWheel(e) {
|
|
198
|
-
e.preventDefault();
|
|
199
|
-
if (this.drag) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (!this.wheelGestureActive) {
|
|
203
|
-
this.wheelGestureActive = true;
|
|
204
|
-
this.options.onGestureStart?.();
|
|
205
|
-
}
|
|
206
|
-
clearTimeout(this.wheelGestureTimer);
|
|
207
|
-
this.wheelGestureTimer = setTimeout(() => {
|
|
208
|
-
this.wheelGestureActive = false;
|
|
209
|
-
this.options.onGestureEnd?.();
|
|
210
|
-
}, DOUBLE_TAP_TIME);
|
|
211
|
-
const s = this.options.getState();
|
|
212
|
-
const delta = -e.deltaY * this.zoomSpeed;
|
|
213
|
-
const newZoom = Math.min(
|
|
214
|
-
this.maxZoom,
|
|
215
|
-
Math.max(this.minZoom, s.zoom + delta)
|
|
216
|
-
);
|
|
217
|
-
if (newZoom === s.zoom) {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const containerSize = this.options.getContainerSize();
|
|
221
|
-
const imgSize = this.options.getImageSize();
|
|
222
|
-
const visSize = imgSize ?? containerSize;
|
|
223
|
-
const target = e.currentTarget;
|
|
224
|
-
const rect = target instanceof Element ? target.getBoundingClientRect() : void 0;
|
|
225
|
-
if (visSize.width > 0 && visSize.height > 0 && rect) {
|
|
226
|
-
const fx = e.clientX - rect.left - containerSize.width / 2;
|
|
227
|
-
const fy = e.clientY - rect.top - containerSize.height / 2;
|
|
228
|
-
const zoomRatio = 1 - newZoom / s.zoom;
|
|
229
|
-
const focalNormX = fx / visSize.width;
|
|
230
|
-
const focalNormY = fy / visSize.height;
|
|
231
|
-
const newCropX = s.pan.x + (focalNormX - s.pan.x) * zoomRatio;
|
|
232
|
-
const newCropY = s.pan.y + (focalNormY - s.pan.y) * zoomRatio;
|
|
233
|
-
const { pan: clampedCrop } = restrictPanZoom(
|
|
234
|
-
{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },
|
|
235
|
-
getImageSizeFromState(s),
|
|
236
|
-
s.cropRect
|
|
237
|
-
);
|
|
238
|
-
this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
|
|
239
|
-
} else {
|
|
240
|
-
this.options.actions.setZoom(newZoom);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Handle a touch-start event on the container element.
|
|
245
|
-
*
|
|
246
|
-
* Supports single-finger pan, two-finger pinch zoom, and
|
|
247
|
-
* double-tap to toggle between fit and 2x zoom. Registers
|
|
248
|
-
* touchmove/touchend/touchcancel on the provided document for the
|
|
249
|
-
* duration of the gesture.
|
|
250
|
-
*
|
|
251
|
-
* @param e The native TouchEvent.
|
|
252
|
-
* @param containerRect The bounding rect of the container element.
|
|
253
|
-
* @param doc The document to register move/end listeners on.
|
|
254
|
-
* Defaults to globalThis.document. Pass the iframe's
|
|
255
|
-
* contentDocument when running inside an iframe.
|
|
256
|
-
*/
|
|
257
|
-
handleTouchStart(e, containerRect, doc = document) {
|
|
258
|
-
if (this.touch && e.touches.length === 2) {
|
|
259
|
-
const s = this.options.getState();
|
|
260
|
-
const distance = getTouchDistance(e.touches[0], e.touches[1]);
|
|
261
|
-
const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
|
|
262
|
-
const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
|
|
263
|
-
this.touch.didPinch = true;
|
|
264
|
-
this.touch.startDistance = distance;
|
|
265
|
-
this.touch.startZoom = s.zoom;
|
|
266
|
-
this.touch.startPanX = s.pan.x;
|
|
267
|
-
this.touch.startPanY = s.pan.y;
|
|
268
|
-
this.touch.startMidX = midX;
|
|
269
|
-
this.touch.startMidY = midY;
|
|
270
|
-
this.touch.containerRect = containerRect;
|
|
271
|
-
this.setStatus({ isDragging: false });
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
if (e.touches.length === 1) {
|
|
275
|
-
const tapX = e.touches[0].clientX;
|
|
276
|
-
const tapY = e.touches[0].clientY;
|
|
277
|
-
if (this.tryDoubleTap(e, tapX, tapY, containerRect)) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
const currentState = this.options.getState();
|
|
281
|
-
this.touch = {
|
|
282
|
-
startDistance: 0,
|
|
283
|
-
startZoom: currentState.zoom,
|
|
284
|
-
lastTouchX: e.touches[0].clientX,
|
|
285
|
-
lastTouchY: e.touches[0].clientY,
|
|
286
|
-
startPanX: currentState.pan.x,
|
|
287
|
-
startPanY: currentState.pan.y,
|
|
288
|
-
containerRect,
|
|
289
|
-
startMidX: 0,
|
|
290
|
-
startMidY: 0,
|
|
291
|
-
didPinch: false,
|
|
292
|
-
moved: false
|
|
293
|
-
};
|
|
294
|
-
this.options.onGestureStart?.();
|
|
295
|
-
} else if (e.touches.length === 2) {
|
|
296
|
-
const currentState = this.options.getState();
|
|
297
|
-
const distance = getTouchDistance(e.touches[0], e.touches[1]);
|
|
298
|
-
const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
|
|
299
|
-
const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
|
|
300
|
-
this.touch = {
|
|
301
|
-
startDistance: distance,
|
|
302
|
-
startZoom: currentState.zoom,
|
|
303
|
-
lastTouchX: 0,
|
|
304
|
-
lastTouchY: 0,
|
|
305
|
-
startPanX: currentState.pan.x,
|
|
306
|
-
startPanY: currentState.pan.y,
|
|
307
|
-
containerRect,
|
|
308
|
-
startMidX: midX,
|
|
309
|
-
startMidY: midY,
|
|
310
|
-
didPinch: true,
|
|
311
|
-
moved: false
|
|
312
|
-
};
|
|
313
|
-
this.options.onGestureStart?.();
|
|
314
|
-
}
|
|
315
|
-
const onTouchEnd = () => {
|
|
316
|
-
this.touch = null;
|
|
317
|
-
this.touchCleanup = null;
|
|
318
|
-
cancelAnimationFrame(this.rafId);
|
|
319
|
-
doc.removeEventListener("touchmove", this.handleTouchMove);
|
|
320
|
-
doc.removeEventListener("touchend", onTouchEnd);
|
|
321
|
-
doc.removeEventListener("touchcancel", onTouchEnd);
|
|
322
|
-
this.setStatus({ isDragging: false });
|
|
323
|
-
this.options.onGestureEnd?.();
|
|
324
|
-
};
|
|
325
|
-
this.touchCleanup?.();
|
|
326
|
-
doc.addEventListener("touchmove", this.handleTouchMove, {
|
|
327
|
-
passive: false
|
|
328
|
-
});
|
|
329
|
-
doc.addEventListener("touchend", onTouchEnd);
|
|
330
|
-
doc.addEventListener("touchcancel", onTouchEnd);
|
|
331
|
-
this.touchCleanup = onTouchEnd;
|
|
332
|
-
}
|
|
333
|
-
// Handle a touchmove event during an active touch gesture. Decides pinch
|
|
334
|
-
// vs. pan based on current `moveEvent.touches.length`, so the gesture
|
|
335
|
-
// can transition between modes without timing sensitivity (e.g. fingers
|
|
336
|
-
// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays
|
|
337
|
-
// attached when used as an event listener.
|
|
338
|
-
handleTouchMove = (moveEvent) => {
|
|
339
|
-
const touch = this.touch;
|
|
340
|
-
if (!touch) {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
moveEvent.preventDefault();
|
|
344
|
-
cancelAnimationFrame(this.rafId);
|
|
345
|
-
this.rafId = requestAnimationFrame(() => {
|
|
346
|
-
const s = this.options.getState();
|
|
347
|
-
if (moveEvent.touches.length === 2) {
|
|
348
|
-
if (!touch.didPinch) {
|
|
349
|
-
touch.didPinch = true;
|
|
350
|
-
touch.startDistance = getTouchDistance(
|
|
351
|
-
moveEvent.touches[0],
|
|
352
|
-
moveEvent.touches[1]
|
|
353
|
-
);
|
|
354
|
-
touch.startZoom = s.zoom;
|
|
355
|
-
touch.startPanX = s.pan.x;
|
|
356
|
-
touch.startPanY = s.pan.y;
|
|
357
|
-
touch.startMidX = (moveEvent.touches[0].clientX + moveEvent.touches[1].clientX) / 2;
|
|
358
|
-
touch.startMidY = (moveEvent.touches[0].clientY + moveEvent.touches[1].clientY) / 2;
|
|
359
|
-
this.setStatus({ isDragging: false });
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
const latestContainerSize = this.options.getContainerSize();
|
|
363
|
-
const latestImageSize = this.options.getImageSize();
|
|
364
|
-
const t0 = moveEvent.touches[0];
|
|
365
|
-
const t1 = moveEvent.touches[1];
|
|
366
|
-
const currentDistance = getTouchDistance(t0, t1);
|
|
367
|
-
const ratio = currentDistance / touch.startDistance;
|
|
368
|
-
const newZoom = Math.min(
|
|
369
|
-
this.maxZoom,
|
|
370
|
-
Math.max(this.minZoom, touch.startZoom * ratio)
|
|
371
|
-
);
|
|
372
|
-
const visSize = latestImageSize ?? latestContainerSize;
|
|
373
|
-
const rect = touch.containerRect;
|
|
374
|
-
if (visSize.width > 0 && visSize.height > 0 && rect) {
|
|
375
|
-
const mx = (t0.clientX + t1.clientX) / 2 - rect.left - latestContainerSize.width / 2;
|
|
376
|
-
const my = (t0.clientY + t1.clientY) / 2 - rect.top - latestContainerSize.height / 2;
|
|
377
|
-
const startMx = touch.startMidX - rect.left - latestContainerSize.width / 2;
|
|
378
|
-
const startMy = touch.startMidY - rect.top - latestContainerSize.height / 2;
|
|
379
|
-
const panDx = visSize.width > 0 ? (mx - startMx) / visSize.width : 0;
|
|
380
|
-
const panDy = visSize.height > 0 ? (my - startMy) / visSize.height : 0;
|
|
381
|
-
const zoomRatio = touch.startZoom !== 0 ? 1 - newZoom / touch.startZoom : 0;
|
|
382
|
-
const startFocalNormX = startMx / visSize.width;
|
|
383
|
-
const startFocalNormY = startMy / visSize.height;
|
|
384
|
-
const newCropX = touch.startPanX + panDx + (startFocalNormX - touch.startPanX) * zoomRatio;
|
|
385
|
-
const newCropY = touch.startPanY + panDy + (startFocalNormY - touch.startPanY) * zoomRatio;
|
|
386
|
-
const { pan: clampedCrop } = restrictPanZoom(
|
|
387
|
-
{
|
|
388
|
-
...s,
|
|
389
|
-
zoom: newZoom,
|
|
390
|
-
pan: { x: newCropX, y: newCropY }
|
|
391
|
-
},
|
|
392
|
-
getImageSizeFromState(s),
|
|
393
|
-
s.cropRect
|
|
394
|
-
);
|
|
395
|
-
this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
|
|
396
|
-
} else if (newZoom !== s.zoom) {
|
|
397
|
-
this.options.actions.setZoom(newZoom);
|
|
398
|
-
}
|
|
399
|
-
} else if (moveEvent.touches.length === 1 && !touch.didPinch) {
|
|
400
|
-
if (!touch.moved) {
|
|
401
|
-
touch.moved = true;
|
|
402
|
-
this.setStatus({ isDragging: true });
|
|
403
|
-
}
|
|
404
|
-
const panImageSize = this.options.getImageSize();
|
|
405
|
-
const panContainerSize = this.options.getContainerSize();
|
|
406
|
-
const panSize = panImageSize ?? panContainerSize;
|
|
407
|
-
const deltaX = panSize.width > 0 ? (moveEvent.touches[0].clientX - touch.lastTouchX) / panSize.width : 0;
|
|
408
|
-
const deltaY = panSize.height > 0 ? (moveEvent.touches[0].clientY - touch.lastTouchY) / panSize.height : 0;
|
|
409
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
410
|
-
{
|
|
411
|
-
...s,
|
|
412
|
-
pan: {
|
|
413
|
-
x: touch.startPanX + deltaX,
|
|
414
|
-
y: touch.startPanY + deltaY
|
|
415
|
-
}
|
|
416
|
-
},
|
|
417
|
-
getImageSizeFromState(s),
|
|
418
|
-
s.cropRect
|
|
419
|
-
);
|
|
420
|
-
this.options.actions.setPan(newCrop);
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
};
|
|
424
|
-
// Handle double-tap-to-toggle-zoom. On a second tap within the configured
|
|
425
|
-
// time/distance threshold, toggles zoom between `minZoom` and
|
|
426
|
-
// `doubleTapZoom` around the tap point and dispatches. Returns `true` if
|
|
427
|
-
// the tap was handled as a double-tap (caller should early-return),
|
|
428
|
-
// `false` otherwise (caller proceeds with normal single-tap handling).
|
|
429
|
-
// Either way, records the tap for next time.
|
|
430
|
-
tryDoubleTap(e, tapX, tapY, containerRect) {
|
|
431
|
-
const now = Date.now();
|
|
432
|
-
const lastTap = this.lastTap;
|
|
433
|
-
if (!lastTap) {
|
|
434
|
-
this.lastTap = { time: now, x: tapX, y: tapY };
|
|
435
|
-
return false;
|
|
436
|
-
}
|
|
437
|
-
const timeDelta = now - lastTap.time;
|
|
438
|
-
const distDelta = Math.sqrt(
|
|
439
|
-
(tapX - lastTap.x) ** 2 + (tapY - lastTap.y) ** 2
|
|
440
|
-
);
|
|
441
|
-
const isDoubleTap = timeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;
|
|
442
|
-
if (!isDoubleTap) {
|
|
443
|
-
this.lastTap = { time: now, x: tapX, y: tapY };
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
e.preventDefault();
|
|
447
|
-
this.lastTap = null;
|
|
448
|
-
const currentState = this.options.getState();
|
|
449
|
-
const containerSize = this.options.getContainerSize();
|
|
450
|
-
const imgSize = this.options.getImageSize();
|
|
451
|
-
const targetZoom = currentState.zoom > (this.minZoom + this.doubleTapZoom) / 2 ? this.minZoom : this.doubleTapZoom;
|
|
452
|
-
const visSize = imgSize ?? containerSize;
|
|
453
|
-
this.setStatus({ isZooming: true });
|
|
454
|
-
clearTimeout(this.zoomTimer);
|
|
455
|
-
this.zoomTimer = setTimeout(() => {
|
|
456
|
-
this.setStatus({ isZooming: false });
|
|
457
|
-
}, ZOOM_ANIMATION_DURATION);
|
|
458
|
-
this.options.onGestureStart?.();
|
|
459
|
-
if (visSize.width > 0 && visSize.height > 0) {
|
|
460
|
-
const fx = tapX - containerRect.left - containerSize.width / 2;
|
|
461
|
-
const fy = tapY - containerRect.top - containerSize.height / 2;
|
|
462
|
-
const zoomRatio = 1 - targetZoom / currentState.zoom;
|
|
463
|
-
const focalNormX = fx / visSize.width;
|
|
464
|
-
const focalNormY = fy / visSize.height;
|
|
465
|
-
const newCropX = currentState.pan.x + (focalNormX - currentState.pan.x) * zoomRatio;
|
|
466
|
-
const newCropY = currentState.pan.y + (focalNormY - currentState.pan.y) * zoomRatio;
|
|
467
|
-
const { pan: clampedCrop } = restrictPanZoom(
|
|
468
|
-
{
|
|
469
|
-
...currentState,
|
|
470
|
-
zoom: targetZoom,
|
|
471
|
-
pan: { x: newCropX, y: newCropY }
|
|
472
|
-
},
|
|
473
|
-
getImageSizeFromState(currentState),
|
|
474
|
-
currentState.cropRect
|
|
475
|
-
);
|
|
476
|
-
this.options.actions.setZoomAtPoint(targetZoom, clampedCrop);
|
|
477
|
-
} else {
|
|
478
|
-
this.options.actions.setZoom(targetZoom);
|
|
479
|
-
}
|
|
480
|
-
this.options.onGestureEnd?.();
|
|
481
|
-
return true;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Handle a keydown event on the container element.
|
|
485
|
-
*
|
|
486
|
-
* Supports arrow keys for panning, +/- for zoom, and r/R for rotation.
|
|
487
|
-
*
|
|
488
|
-
* @param e The native KeyboardEvent.
|
|
489
|
-
*/
|
|
490
|
-
handleKeyDown(e) {
|
|
491
|
-
const currentState = this.options.getState();
|
|
492
|
-
switch (e.key) {
|
|
493
|
-
case "ArrowUp": {
|
|
494
|
-
e.preventDefault();
|
|
495
|
-
const keyboardStep = this.getKeyboardStep(e);
|
|
496
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
497
|
-
{
|
|
498
|
-
...currentState,
|
|
499
|
-
pan: {
|
|
500
|
-
x: currentState.pan.x,
|
|
501
|
-
y: currentState.pan.y + keyboardStep
|
|
502
|
-
}
|
|
503
|
-
},
|
|
504
|
-
getImageSizeFromState(currentState),
|
|
505
|
-
currentState.cropRect
|
|
506
|
-
);
|
|
507
|
-
this.options.actions.setPan(newCrop);
|
|
508
|
-
break;
|
|
509
|
-
}
|
|
510
|
-
case "ArrowDown": {
|
|
511
|
-
e.preventDefault();
|
|
512
|
-
const keyboardStep = this.getKeyboardStep(e);
|
|
513
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
514
|
-
{
|
|
515
|
-
...currentState,
|
|
516
|
-
pan: {
|
|
517
|
-
x: currentState.pan.x,
|
|
518
|
-
y: currentState.pan.y - keyboardStep
|
|
519
|
-
}
|
|
520
|
-
},
|
|
521
|
-
getImageSizeFromState(currentState),
|
|
522
|
-
currentState.cropRect
|
|
523
|
-
);
|
|
524
|
-
this.options.actions.setPan(newCrop);
|
|
525
|
-
break;
|
|
526
|
-
}
|
|
527
|
-
case "ArrowLeft": {
|
|
528
|
-
e.preventDefault();
|
|
529
|
-
const keyboardStep = this.getKeyboardStep(e);
|
|
530
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
531
|
-
{
|
|
532
|
-
...currentState,
|
|
533
|
-
pan: {
|
|
534
|
-
x: currentState.pan.x + keyboardStep,
|
|
535
|
-
y: currentState.pan.y
|
|
536
|
-
}
|
|
537
|
-
},
|
|
538
|
-
getImageSizeFromState(currentState),
|
|
539
|
-
currentState.cropRect
|
|
540
|
-
);
|
|
541
|
-
this.options.actions.setPan(newCrop);
|
|
542
|
-
break;
|
|
543
|
-
}
|
|
544
|
-
case "ArrowRight": {
|
|
545
|
-
e.preventDefault();
|
|
546
|
-
const keyboardStep = this.getKeyboardStep(e);
|
|
547
|
-
const { pan: newCrop } = restrictPanZoom(
|
|
548
|
-
{
|
|
549
|
-
...currentState,
|
|
550
|
-
pan: {
|
|
551
|
-
x: currentState.pan.x - keyboardStep,
|
|
552
|
-
y: currentState.pan.y
|
|
553
|
-
}
|
|
554
|
-
},
|
|
555
|
-
getImageSizeFromState(currentState),
|
|
556
|
-
currentState.cropRect
|
|
557
|
-
);
|
|
558
|
-
this.options.actions.setPan(newCrop);
|
|
559
|
-
break;
|
|
560
|
-
}
|
|
561
|
-
case "+":
|
|
562
|
-
case "=": {
|
|
563
|
-
e.preventDefault();
|
|
564
|
-
const newZoom = Math.min(
|
|
565
|
-
this.maxZoom,
|
|
566
|
-
Math.max(this.minZoom, currentState.zoom + 0.5)
|
|
567
|
-
);
|
|
568
|
-
this.options.actions.setZoom(newZoom);
|
|
569
|
-
break;
|
|
570
|
-
}
|
|
571
|
-
case "-":
|
|
572
|
-
case "_": {
|
|
573
|
-
e.preventDefault();
|
|
574
|
-
const newZoom = Math.min(
|
|
575
|
-
this.maxZoom,
|
|
576
|
-
Math.max(this.minZoom, currentState.zoom - 0.5)
|
|
577
|
-
);
|
|
578
|
-
this.options.actions.setZoom(newZoom);
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
case "r":
|
|
582
|
-
case "R": {
|
|
583
|
-
if (e.metaKey || e.ctrlKey || e.altKey) {
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
586
|
-
e.preventDefault();
|
|
587
|
-
this.options.actions.snapRotate90(e.shiftKey ? -1 : 1);
|
|
588
|
-
break;
|
|
589
|
-
}
|
|
590
|
-
case "h":
|
|
591
|
-
case "H": {
|
|
592
|
-
if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) {
|
|
593
|
-
break;
|
|
594
|
-
}
|
|
595
|
-
e.preventDefault();
|
|
596
|
-
this.options.actions.toggleFlip?.("horizontal");
|
|
597
|
-
break;
|
|
598
|
-
}
|
|
599
|
-
case "v":
|
|
600
|
-
case "V": {
|
|
601
|
-
if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) {
|
|
602
|
-
break;
|
|
603
|
-
}
|
|
604
|
-
e.preventDefault();
|
|
605
|
-
this.options.actions.toggleFlip?.("vertical");
|
|
606
|
-
break;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Clean up all timers, animation frames, and active touch listeners.
|
|
612
|
-
*
|
|
613
|
-
* Must be called when the controller is no longer needed (e.g., on
|
|
614
|
-
* component unmount or element removal).
|
|
615
|
-
*/
|
|
616
|
-
destroy() {
|
|
617
|
-
cancelAnimationFrame(this.rafId);
|
|
618
|
-
clearTimeout(this.zoomTimer);
|
|
619
|
-
clearTimeout(this.wheelGestureTimer);
|
|
620
|
-
this.touchCleanup?.();
|
|
621
|
-
this.touchCleanup = null;
|
|
622
|
-
this.pointerCleanup?.();
|
|
623
|
-
this.pointerCleanup = null;
|
|
624
|
-
this.drag = null;
|
|
625
|
-
this.touch = null;
|
|
626
|
-
this.lastTap = null;
|
|
627
|
-
this.wheelGestureActive = false;
|
|
628
|
-
this.isDragging = false;
|
|
629
|
-
this.isZooming = false;
|
|
630
|
-
}
|
|
631
|
-
};
|
|
632
|
-
export {
|
|
633
|
-
InteractionController
|
|
634
|
-
};
|
|
635
|
-
//# sourceMappingURL=interaction-controller.mjs.map
|