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