@wordpress/media-editor 0.9.0 → 0.10.1
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/build/components/media-editor/index.cjs +212 -170
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs +63 -0
- package/build/components/media-editor/use-crop-options.cjs.map +7 -0
- package/build/components/media-editor/use-save-media-editor.cjs +185 -0
- package/build/components/media-editor/use-save-media-editor.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +33 -12
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +70 -84
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-fine-rotation/index.cjs +81 -0
- package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +63 -16
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-transform-controls/index.cjs +84 -0
- package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
- package/build/components/media-form/index.cjs +19 -1
- package/build/components/media-form/index.cjs.map +3 -3
- package/build/components/media-form/sidebar-datetime-view.cjs +53 -0
- package/build/components/media-form/sidebar-datetime-view.cjs.map +7 -0
- package/build/components/rotation-ruler/index.cjs +8 -2
- package/build/components/rotation-ruler/index.cjs.map +2 -2
- package/build/hooks/use-crop-gesture-handlers.cjs +41 -4
- package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
- package/build/image-editor/core/camera.cjs +29 -11
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs +6 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +71 -34
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/crop-rect.cjs +48 -0
- package/build/image-editor/core/crop-rect.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +12 -0
- package/build/image-editor/core/index.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs +92 -0
- package/build/image-editor/core/math/sanitize.cjs.map +7 -0
- package/build/image-editor/core/setter-helpers.cjs +64 -0
- package/build/image-editor/core/setter-helpers.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +16 -14
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +20 -10
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/stencil-math.cjs +31 -20
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs +12 -6
- package/build/image-editor/core/transform-style.cjs.map +2 -2
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/index.cjs +12 -2
- package/build/image-editor/index.cjs.map +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +120 -47
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +172 -0
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +19 -9
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +71 -0
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +6 -3
- package/build/image-editor/react/hooks/index.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +113 -0
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +7 -0
- package/build/state/composite-reducer.cjs +103 -0
- package/build/state/composite-reducer.cjs.map +7 -0
- package/build/state/index.cjs +48 -0
- package/build/state/index.cjs.map +7 -0
- package/build/state/media-editor-state-provider.cjs +58 -0
- package/build/state/media-editor-state-provider.cjs.map +7 -0
- package/build/state/types.cjs +33 -0
- package/build/state/types.cjs.map +7 -0
- package/build/state/use-media-editor-state.cjs +287 -0
- package/build/state/use-media-editor-state.cjs.map +7 -0
- package/build/store/actions.cjs +4 -2
- package/build/store/actions.cjs.map +2 -2
- package/build/store/reducer.cjs +5 -3
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +5 -0
- package/build/store/selectors.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +224 -177
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs +37 -0
- package/build-module/components/media-editor/use-crop-options.mjs.map +7 -0
- package/build-module/components/media-editor/use-save-media-editor.mjs +151 -0
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +34 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +73 -89
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +64 -17
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
- package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
- package/build-module/components/media-form/index.mjs +9 -1
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/media-form/sidebar-datetime-view.mjs +32 -0
- package/build-module/components/media-form/sidebar-datetime-view.mjs.map +7 -0
- package/build-module/components/rotation-ruler/index.mjs +8 -2
- package/build-module/components/rotation-ruler/index.mjs.map +2 -2
- package/build-module/hooks/use-crop-gesture-handlers.mjs +41 -4
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
- package/build-module/image-editor/core/camera.mjs +34 -11
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +4 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +75 -34
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/crop-rect.mjs +23 -0
- package/build-module/image-editor/core/crop-rect.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +12 -0
- package/build-module/image-editor/core/index.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/math/sanitize.mjs +63 -0
- package/build-module/image-editor/core/math/sanitize.mjs.map +7 -0
- package/build-module/image-editor/core/setter-helpers.mjs +39 -0
- package/build-module/image-editor/core/setter-helpers.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +16 -14
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +25 -11
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/stencil-math.mjs +30 -19
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs +12 -6
- package/build-module/image-editor/core/transform-style.mjs.map +2 -2
- package/build-module/image-editor/index.mjs +11 -2
- package/build-module/image-editor/index.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper-provider.mjs +3 -3
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +121 -48
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +147 -0
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +19 -9
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +46 -0
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +4 -2
- package/build-module/image-editor/react/hooks/index.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +100 -0
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +7 -0
- package/build-module/state/composite-reducer.mjs +82 -0
- package/build-module/state/composite-reducer.mjs.map +7 -0
- package/build-module/state/index.mjs +26 -0
- package/build-module/state/index.mjs.map +7 -0
- package/build-module/state/media-editor-state-provider.mjs +34 -0
- package/build-module/state/media-editor-state-provider.mjs.map +7 -0
- package/build-module/state/types.mjs +8 -0
- package/build-module/state/types.mjs.map +7 -0
- package/build-module/state/use-media-editor-state.mjs +278 -0
- package/build-module/state/use-media-editor-state.mjs.map +7 -0
- package/build-module/store/actions.mjs +4 -2
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/reducer.mjs +5 -3
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +4 -0
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-style/style-rtl.css +97 -44
- package/build-style/style.css +97 -44
- package/build-types/components/media-editor/index.d.ts +14 -5
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +35 -0
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -0
- package/build-types/components/media-editor/use-save-media-editor.d.ts +29 -0
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +5 -10
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +6 -25
- 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 +14 -0
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +13 -14
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +18 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +10 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/crop-rect.d.ts +19 -0
- package/build-types/image-editor/core/crop-rect.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +3 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +5 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +70 -0
- package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -0
- package/build-types/image-editor/core/setter-helpers.d.ts +24 -0
- package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts +12 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +23 -18
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
- package/build-types/image-editor/core/types.d.ts +23 -4
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/index.d.ts +4 -4
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +11 -7
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +6 -4
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +36 -0
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +2 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +47 -0
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +4 -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 +58 -0
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +39 -0
- package/build-types/state/composite-reducer.d.ts.map +1 -0
- package/build-types/state/index.d.ts +7 -0
- package/build-types/state/index.d.ts.map +1 -0
- package/build-types/state/media-editor-state-provider.d.ts +34 -0
- package/build-types/state/media-editor-state-provider.d.ts.map +1 -0
- package/build-types/state/types.d.ts +96 -0
- package/build-types/state/types.d.ts.map +1 -0
- package/build-types/state/use-media-editor-state.d.ts +101 -0
- package/build-types/state/use-media-editor-state.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +3 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +3 -0
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +1 -0
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +19 -16
- package/src/components/media-editor/index.tsx +262 -229
- package/src/components/media-editor/style.scss +0 -9
- package/src/components/media-editor/test/use-crop-options.tsx +110 -0
- package/src/components/media-editor/use-crop-options.ts +79 -0
- package/src/components/media-editor/use-save-media-editor.ts +214 -0
- package/src/components/media-editor-canvas/index.tsx +57 -25
- package/src/components/media-editor-crop-panel/index.tsx +53 -87
- package/src/components/media-editor-crop-panel/test/index.tsx +46 -53
- package/src/components/media-editor-fine-rotation/index.tsx +74 -0
- package/src/components/media-editor-modal/index.tsx +70 -16
- package/src/components/media-editor-modal/style.scss +80 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +14 -0
- package/src/components/media-editor-modal/test/index.tsx +146 -0
- package/src/components/media-editor-transform-controls/index.tsx +70 -0
- package/src/components/media-editor-transform-controls/style.scss +8 -0
- package/src/components/media-form/index.tsx +15 -1
- package/src/components/media-form/sidebar-datetime-view.tsx +47 -0
- package/src/components/media-form/test/sidebar-datetime-view.test.tsx +96 -0
- package/src/components/rotation-ruler/README.md +11 -25
- package/src/components/rotation-ruler/index.tsx +17 -2
- package/src/components/rotation-ruler/style.scss +49 -13
- package/src/hooks/use-crop-gesture-handlers.ts +64 -17
- package/src/image-editor/README.md +28 -129
- package/src/image-editor/core/camera.ts +51 -26
- package/src/image-editor/core/constants.ts +19 -0
- package/src/image-editor/core/containment.ts +102 -49
- package/src/image-editor/core/crop-rect.ts +45 -0
- package/src/image-editor/core/index.ts +16 -4
- package/src/image-editor/core/interaction-controller.ts +5 -1
- package/src/image-editor/core/math/sanitize.ts +158 -0
- package/src/image-editor/core/math/test/sanitize.ts +244 -0
- package/src/image-editor/core/setter-helpers.ts +66 -0
- package/src/image-editor/core/source-region.ts +21 -14
- package/src/image-editor/core/state.ts +67 -15
- package/src/image-editor/core/stencil-math.ts +55 -35
- package/src/image-editor/core/test/camera.ts +367 -1
- package/src/image-editor/core/test/state.ts +101 -8
- package/src/image-editor/core/test/stencil-math.ts +193 -0
- package/src/image-editor/core/transform-style.ts +21 -6
- package/src/image-editor/core/types.ts +24 -4
- package/src/image-editor/docs/architecture.md +48 -89
- package/src/image-editor/docs/recipes.md +123 -659
- package/src/image-editor/index.ts +12 -3
- package/src/image-editor/react/components/cropper-provider.tsx +16 -12
- package/src/image-editor/react/components/cropper.scss +23 -4
- package/src/image-editor/react/components/cropper.tsx +194 -89
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +269 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +19 -8
- package/src/image-editor/react/components/test/cropper.tsx +55 -13
- package/src/image-editor/react/hooks/build-cropper-setters.ts +105 -0
- package/src/image-editor/react/hooks/index.ts +4 -2
- package/src/image-editor/react/hooks/test/{use-cropper-state.ts → use-cropper-reducer.ts} +142 -286
- package/src/image-editor/react/hooks/use-cropper-reducer.ts +204 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +7 -17
- package/src/state/composite-reducer.ts +137 -0
- package/src/state/index.ts +20 -0
- package/src/state/media-editor-state-provider.tsx +70 -0
- package/src/state/test/use-media-editor-state.ts +330 -0
- package/src/state/types.ts +101 -0
- package/src/state/use-media-editor-state.ts +472 -0
- package/src/store/actions.ts +3 -0
- package/src/store/reducer.ts +6 -1
- package/src/store/selectors.ts +4 -0
- package/src/store/test/reducer.ts +9 -0
- package/src/style.scss +1 -1
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-toolbar/index.cjs +0 -214
- package/build/components/media-editor-toolbar/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-state.cjs +0 -277
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +0 -7
- package/build-module/components/media-editor-toolbar/index.mjs +0 -190
- package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +0 -262
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +0 -7
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -97
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
- package/src/components/media-editor-toolbar/index.tsx +0 -209
- package/src/components/media-editor-toolbar/style.scss +0 -49
- package/src/image-editor/docs/roadmap.md +0 -66
- package/src/image-editor/react/hooks/use-cropper-state.ts +0 -457
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/containment.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\n\n/** Floating-point epsilon for \"close enough to equal\" comparisons. */\nconst EPSILON = 1e-9;\n\n/**\n * Compute the visual (rotated) bounding-box dimensions in pixel-proportional\n * units where the unrotated image is `a \u00D7 1` (renderedW = a, renderedH = 1).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @return Visual dimensions and trig helpers.\n */\nfunction getVisualDimensions(\n\trotation: number,\n\timageAspectRatio: number\n): { visualW: number; visualH: number; absC: number; absS: number } {\n\tconst rad = degreesToRadians( rotation );\n\tconst absC = Math.abs( Math.cos( rad ) );\n\tconst absS = Math.abs( Math.sin( rad ) );\n\tconst bbox = getRotatedBBox( imageAspectRatio, 1, rotation );\n\treturn {\n\t\tvisualW: bbox.width,\n\t\tvisualH: bbox.height,\n\t\tabsC,\n\t\tabsS,\n\t};\n}\n\n/**\n * Calculates the minimum zoom factor needed for the rotated image to fully cover\n * the crop rectangle, using normalized coordinates and imageAspectRatio.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n * The crop rect is in visual-normalized space and must be scaled by the\n * rotation-dependent visual dimensions before projecting into the image-local\n * frame.\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The minimum zoom factor (always >= 1).\n */\nfunction getMinZoomForCover(\n\trotation: number,\n\timageAspectRatio: number,\n\tcropRect: NormalizedRect\n): number {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// The crop rect lives in the SNAP-rotation visual bbox \u2014 that's how the\n\t// stencil and preview position it (see createCamera / getImageFit). Use\n\t// the snap-rotation dimensions to convert crop fractions to pixels.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\t// Projection into the image-local frame uses the TRUE rotation angle \u2014\n\t// that's the actual orientation of the image under the stencil.\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\n\t// Crop half-extents in pixel-proportional space.\n\tconst cropHalfW = ( cropRect.width * snapVisualW ) / 2;\n\tconst cropHalfH = ( cropRect.height * snapVisualH ) / 2;\n\n\t// AABB of the crop rect projected into the image-local (unrotated) frame.\n\tconst spanAlpha = cropHalfW * absC + cropHalfH * absS;\n\tconst spanBeta = cropHalfW * absS + cropHalfH * absC;\n\n\t// Image half-extents at zoom z: (aspectRatio*z/2, z/2).\n\t// Coverage requires: aspectRatio*z/2 >= spanAlpha AND z/2 >= spanBeta.\n\tconst zoomFromAlpha = ( 2 * spanAlpha ) / aspectRatio;\n\tconst zoomFromBeta = 2 * spanBeta;\n\n\treturn Math.max( 1, zoomFromAlpha, zoomFromBeta );\n}\n\n/**\n * Compute the crop handle bounds in normalized visual space \u2014 the\n * axis-aligned bounding box (AABB) of the actual image footprint at the\n * current pan/zoom/rotation.\n *\n * Returns the full image AABB without intersecting with the container\n * viewport. The viewport pan mechanism in the Cropper component allows\n * the canvas to scroll so handles can reach the image edge even when it\n * lies outside the visible canvas area.\n *\n * Unlike a static centerline-based calculation, this accounts for the\n * current pan position \u2014 if the user pans right, the left bound tightens\n * because the image's left edge has moved right.\n *\n * @param state The current cropper state (crop, zoom, rotation, flip).\n * @param elementSize The fitted (unrotated) image element dimensions in pixels.\n * @param visualSize The visual (rotated) image bounding box in pixels.\n * @return The min/max x and y that a crop rect edge can reach in normalized space.\n */\nexport function getImageCropBounds(\n\tstate: CropperState,\n\telementSize: Size,\n\tvisualSize: Size\n): { minX: number; minY: number; maxX: number; maxY: number } {\n\tif (\n\t\telementSize.width === 0 ||\n\t\telementSize.height === 0 ||\n\t\tvisualSize.width === 0 ||\n\t\tvisualSize.height === 0\n\t) {\n\t\treturn { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n\t}\n\n\t// Build the same CSS matrix as use-transform-style: flip * rotate * zoom.\n\t// Flip is outside rotation so it acts in viewport axes (see createCamera).\n\tconst tx = state.pan.x * visualSize.width;\n\tconst ty = state.pan.y * visualSize.height;\n\tconst rad = degreesToRadians( state.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = state.flip.horizontal ? -1 : 1;\n\tconst sy = state.flip.vertical ? -1 : 1;\n\tconst z = state.zoom;\n\tconst ma = sx * cos * z;\n\tconst mb = sy * sin * z;\n\tconst mc = -sx * sin * z;\n\tconst md = sy * cos * z;\n\n\t// Image element corners relative to element center.\n\tconst hw = elementSize.width / 2;\n\tconst hh = elementSize.height / 2;\n\tconst corners = [\n\t\t[ -hw, -hh ],\n\t\t[ hw, -hh ],\n\t\t[ hw, hh ],\n\t\t[ -hw, hh ],\n\t];\n\n\tlet imgMinX = Infinity;\n\tlet imgMaxX = -Infinity;\n\tlet imgMinY = Infinity;\n\tlet imgMaxY = -Infinity;\n\n\tfor ( const [ cx, cy ] of corners ) {\n\t\t// Screen offset from element center after CSS matrix.\n\t\tconst screenX = ma * cx + mc * cy + tx;\n\t\tconst screenY = mb * cx + md * cy + ty;\n\t\t// Convert to normalized visual space.\n\t\t// The element center is at the visual image center, which is at\n\t\t// normalized (0.5, 0.5). So screen offset / visualSize + 0.5.\n\t\tconst nx = screenX / visualSize.width + 0.5;\n\t\tconst ny = screenY / visualSize.height + 0.5;\n\t\timgMinX = Math.min( imgMinX, nx );\n\t\timgMaxX = Math.max( imgMaxX, nx );\n\t\timgMinY = Math.min( imgMinY, ny );\n\t\timgMaxY = Math.max( imgMaxY, ny );\n\t}\n\n\treturn {\n\t\tminX: imgMinX,\n\t\tminY: imgMinY,\n\t\tmaxX: imgMaxX,\n\t\tmaxY: imgMaxY,\n\t};\n}\n\n/**\n * Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.\n * If the crop rect is too large for the current zoom and rotation, it is scaled\n * down proportionally and re-centered.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n *\n * @param cropRect The crop rectangle in normalized coordinates.\n * @param zoom The current zoom factor.\n * @param rotation The rotation angle in degrees.\n * @param imageAspectRatio The image width / height ratio.\n * @return The restricted crop rectangle.\n */\nexport function restrictCropRect(\n\tcropRect: NormalizedRect,\n\tzoom: number,\n\trotation: number,\n\timageAspectRatio: number\n): NormalizedRect {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// Crop rect lives in the SNAP-rotation visual bbox (matching the stencil\n\t// layout); projection into the image-local frame uses the TRUE rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW, visualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\tconst W = cropRect.width;\n\tconst H = cropRect.height;\n\n\t// Crop full-extents in pixel-proportional space, projected to image-local frame.\n\tconst cropWPx = W * visualW;\n\tconst cropHPx = H * visualH;\n\tconst spanAlpha = cropWPx * absC + cropHPx * absS;\n\tconst spanBeta = cropWPx * absS + cropHPx * absC;\n\n\t// Image full-extents at zoom z: (aspectRatio*z, z).\n\tconst limitAlpha = aspectRatio * zoom;\n\tconst limitBeta = zoom;\n\n\tlet t = 1;\n\tif ( spanAlpha > 0 ) {\n\t\tt = Math.min( t, limitAlpha / spanAlpha );\n\t}\n\tif ( spanBeta > 0 ) {\n\t\tt = Math.min( t, limitBeta / spanBeta );\n\t}\n\tif ( t >= 1 - EPSILON ) {\n\t\t// Crop fits at the current zoom \u2014 no size change needed.\n\t\t// Position is handled by restrictPanZoom, not here.\n\t\treturn cropRect;\n\t}\n\tconst newW = W * t;\n\tconst newH = H * t;\n\tconst centerX = cropRect.x + W / 2;\n\tconst centerY = cropRect.y + H / 2;\n\tlet newX = centerX - newW / 2;\n\tlet newY = centerY - newH / 2;\n\tnewX = Math.max( 0, Math.min( newX, 1 - newW ) );\n\tnewY = Math.max( 0, Math.min( newY, 1 - newH ) );\n\treturn { x: newX, y: newY, width: newW, height: newH };\n}\n\n/**\n * Canonical container used internally by restrictPanZoom.\n * Containment is scale-invariant, so the actual size doesn't matter \u2014\n * only the relative geometry between stencil and image matters.\n */\nconst CANONICAL_CONTAINER: Size = { width: 1000, height: 1000 };\n\n// Pre-allocated scratch buffers for restrictPanZoom's hot path (runs on\n// every pointermove) to avoid Float32Array allocation per call.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers\n * the crop rectangle.\n *\n * Uses the camera matrix to project: builds a camera from the candidate state,\n * maps the stencil corners (axis-aligned in the visual bounding box) to world\n * space via the inverse camera, and checks that all world points lie within\n * [0,1]\u00D7[0,1]. If any point is outside, computes the minimal pan correction.\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the image in pixels.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The restricted crop pan and zoom values.\n */\nexport function restrictPanZoom(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect\n): { pan: { x: number; y: number }; zoom: number } {\n\t// Algorithm overview:\n\t// 1. Ensure zoom is high enough for the rotated image to cover the crop.\n\t// 2. Build a camera (world\u2192screen matrix) with the candidate state.\n\t// 3. Build a base camera (no pan, zoom=1) to find where the stencil\n\t// sits in screen space \u2014 the stencil is anchored to the container,\n\t// not the image, so it doesn't move with pan or scale with zoom.\n\t// 4. Project the 4 stencil corners through the INVERSE of the main\n\t// camera to get world-space positions. A world point outside [0,1]\n\t// means that corner of the stencil isn't covered by the image.\n\t// 5. Compute the minimal translation in world space to push all corners\n\t// back inside [0,1].\n\t// 6. Convert the world-space correction to a pan-field correction by\n\t// mapping it through the camera's linear part back to screen space,\n\t// then dividing by the visual bounds.\n\tconst aspectRatio =\n\t\timageSize.width > 0 && imageSize.height > 0\n\t\t\t? imageSize.width / imageSize.height\n\t\t\t: 1;\n\tconst minZoom = getMinZoomForCover( state.rotation, aspectRatio, cropRect );\n\tconst zoom = Math.max( state.zoom, minZoom );\n\n\t// Step 2: build camera with candidate pan and corrected zoom.\n\tconst candidateState = { ...state, zoom };\n\tconst camera = createCamera(\n\t\tcandidateState,\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\n\t// Build a base camera (zero pan, zoom=1) to get stencil positions.\n\t// The stencil is anchored to the container and laid out using the\n\t// nearest 90\u00B0 rotation (matching `getImageFit`), so it's stable\n\t// through fine rotation. CSS zoom only affects the <img> element,\n\t// not the stencil.\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst baseCamera = createCamera(\n\t\t{\n\t\t\t...candidateState,\n\t\t\tpan: { x: 0, y: 0 },\n\t\t\tzoom: 1,\n\t\t\trotation: snapRotation,\n\t\t},\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\t// Stencil corners in screen space (axis-aligned rect within visual bounds).\n\tconst stencilCorners: [ number, number ][] = [\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t];\n\n\t// Map stencil corners to world space via inverse camera.\n\t// If a world point is outside [0,1], the image doesn't cover that spot.\n\t// Reuse module-level scratch buffers to avoid allocation per frame.\n\tmat2d.invert( _scratchMat, camera );\n\n\tlet minWx = Infinity;\n\tlet maxWx = -Infinity;\n\tlet minWy = Infinity;\n\tlet maxWy = -Infinity;\n\n\tfor ( const corner of stencilCorners ) {\n\t\tvec2.transformMat2d( _scratchVec, corner, _scratchMat );\n\t\tconst w = _scratchVec;\n\t\tif ( w[ 0 ] < minWx ) {\n\t\t\tminWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 0 ] > maxWx ) {\n\t\t\tmaxWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 1 ] < minWy ) {\n\t\t\tminWy = w[ 1 ];\n\t\t}\n\t\tif ( w[ 1 ] > maxWy ) {\n\t\t\tmaxWy = w[ 1 ];\n\t\t}\n\t}\n\n\t// If all world points are in [0,1], no correction needed.\n\tif (\n\t\tminWx >= -EPSILON &&\n\t\tmaxWx <= 1 + EPSILON &&\n\t\tminWy >= -EPSILON &&\n\t\tmaxWy <= 1 + EPSILON\n\t) {\n\t\treturn { pan: state.pan, zoom };\n\t}\n\n\t// Compute world-space correction needed.\n\t// If minWx < 0, we need to shift world points right by |minWx|.\n\t// If maxWx > 1, we need to shift world points left by (maxWx - 1).\n\t// If both, we're over-constrained (crop too big) \u2014 getMinZoomForCover\n\t// should have prevented this.\n\tlet dwx = 0;\n\tlet dwy = 0;\n\n\tif ( minWx < 0 && maxWx <= 1 + EPSILON ) {\n\t\tdwx = -minWx;\n\t} else if ( maxWx > 1 && minWx >= -EPSILON ) {\n\t\tdwx = 1 - maxWx;\n\t} else if ( minWx < 0 && maxWx > 1 ) {\n\t\t// Over-constrained: center it.\n\t\tdwx = ( 1 - maxWx - minWx ) / 2;\n\t}\n\n\tif ( minWy < 0 && maxWy <= 1 + EPSILON ) {\n\t\tdwy = -minWy;\n\t} else if ( maxWy > 1 && minWy >= -EPSILON ) {\n\t\tdwy = 1 - maxWy;\n\t} else if ( minWy < 0 && maxWy > 1 ) {\n\t\tdwy = ( 1 - maxWy - minWy ) / 2;\n\t}\n\n\t// Convert world-space correction to screen-space correction.\n\t// The camera's 2\u00D72 linear part (indices [0,1,2,3]) maps world deltas\n\t// to screen deltas: screenDelta = linear * worldDelta.\n\tconst dsx = camera[ 0 ] * dwx + camera[ 2 ] * dwy;\n\tconst dsy = camera[ 1 ] * dwx + camera[ 3 ] * dwy;\n\n\t// Convert screen-space correction to pan-field correction.\n\t// Pan in screen pixels = pan.x * visualW, pan.y * visualH.\n\t// The correction is subtractive: a positive world shift (dw > 0) means\n\t// the image needs to move opposite to pan direction, so pan decreases.\n\tconst newPanX =\n\t\tstate.pan.x -\n\t\t( visibleBounds.width > 0 ? dsx / visibleBounds.width : 0 );\n\tconst newPanY =\n\t\tstate.pan.y -\n\t\t( visibleBounds.height > 0 ? dsy / visibleBounds.height : 0 );\n\n\treturn {\n\t\tpan: { x: newPanX, y: newPanY },\n\t\tzoom,\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,OAAO,YAAY;AAM5B,SAAS,wBAAwB;AACjC,SAAS,cAAc,gBAAgB,wBAAwB;AAG/D,IAAM,UAAU;AAUhB,SAAS,oBACR,UACA,kBACmE;AACnE,QAAM,MAAM,iBAAkB,QAAS;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,eAAgB,kBAAkB,GAAG,QAAS;AAC3D,SAAO;AAAA,IACN,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,IACd;AAAA,IACA;AAAA,EACD;AACD;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from './types';\nimport { ABSOLUTE_MIN_ZOOM, MAX_ZOOM, MIN_ZOOM } from './constants';\nimport { degreesToRadians } from './math/rotation';\nimport {\n\tisValidSize,\n\tsafeBoundedNumber,\n\tsanitizeCropperState,\n\tsanitizeRect,\n} from './math/sanitize';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\n\n/** Floating-point epsilon for \"close enough to equal\" comparisons. */\nconst EPSILON = 1e-9;\n\n/**\n * Compute the visual (rotated) bounding-box dimensions in pixel-proportional\n * units where the unrotated image is `a \u00D7 1` (renderedW = a, renderedH = 1).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @return Visual dimensions and trig helpers.\n */\nfunction getVisualDimensions(\n\trotation: number,\n\timageAspectRatio: number\n): { visualW: number; visualH: number; absC: number; absS: number } {\n\tconst rad = degreesToRadians( rotation );\n\tconst absC = Math.abs( Math.cos( rad ) );\n\tconst absS = Math.abs( Math.sin( rad ) );\n\tconst bbox = getRotatedBBox( imageAspectRatio, 1, rotation );\n\treturn {\n\t\tvisualW: bbox.width,\n\t\tvisualH: bbox.height,\n\t\tabsC,\n\t\tabsS,\n\t};\n}\n\n/**\n * The geometric minimum zoom required for the rotated image to fully cover the\n * crop rectangle. Works in pixel-proportional space where the unrotated image\n * is a\u00D71; the crop rect lives in visual-normalized space and is scaled by the\n * rotation-dependent visual dimensions before projecting into the image-local\n * frame.\n *\n * Returns 0 for a degenerate (zero-area) crop \u2014 callers compose the result\n * with their own floor (typically the current zoom or `MIN_ZOOM`).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The minimum zoom factor needed for coverage.\n */\nfunction getMinZoomForCover(\n\trotation: number,\n\timageAspectRatio: number,\n\tcropRect: NormalizedRect\n): number {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// The crop rect lives in the SNAP-rotation visual bbox \u2014 that's how the\n\t// stencil and preview position it (see createCamera / getImageFit). Use\n\t// the snap-rotation dimensions to convert crop fractions to pixels.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\t// Projection into the image-local frame uses the TRUE rotation angle \u2014\n\t// that's the actual orientation of the image under the stencil.\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\n\t// Crop half-extents in pixel-proportional space.\n\tconst cropHalfW = ( cropRect.width * snapVisualW ) / 2;\n\tconst cropHalfH = ( cropRect.height * snapVisualH ) / 2;\n\n\t// AABB of the crop rect projected into the image-local (unrotated) frame.\n\tconst spanAlpha = cropHalfW * absC + cropHalfH * absS;\n\tconst spanBeta = cropHalfW * absS + cropHalfH * absC;\n\n\t// Image half-extents at zoom z: (aspectRatio*z/2, z/2).\n\t// Coverage requires: aspectRatio*z/2 >= spanAlpha AND z/2 >= spanBeta.\n\tconst zoomFromAlpha = ( 2 * spanAlpha ) / aspectRatio;\n\tconst zoomFromBeta = 2 * spanBeta;\n\n\treturn Math.max( zoomFromAlpha, zoomFromBeta );\n}\n\n/**\n * Resolves the effective minimum zoom for the current state \u2014 the coverage-\n * aware floor when an image is loaded, falling back to `MIN_ZOOM` otherwise.\n * Used by both the cropper's interaction layer and the zoom slider so the\n * floor stays consistent across surfaces.\n *\n * @param state The current cropper state.\n * @return The minimum zoom factor.\n */\nexport function getMinZoom( state: CropperState ): number {\n\tif ( ! state.image ) {\n\t\treturn MIN_ZOOM;\n\t}\n\tconst imageSize = {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t};\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn MIN_ZOOM;\n\t}\n\tconst safeState = sanitizeCropperState( state );\n\tconst aspectRatio = imageSize.width / imageSize.height;\n\treturn Math.max(\n\t\tABSOLUTE_MIN_ZOOM,\n\t\tgetMinZoomForCover(\n\t\t\tsafeState.rotation,\n\t\t\taspectRatio,\n\t\t\tsafeState.cropRect\n\t\t)\n\t);\n}\n\n/**\n * Compute the crop handle bounds in normalized visual space \u2014 the\n * axis-aligned bounding box (AABB) of the actual image footprint at the\n * current pan/zoom/rotation.\n *\n * Returns the full image AABB without intersecting with the container\n * viewport. The viewport pan mechanism in the Cropper component allows\n * the canvas to scroll so handles can reach the image edge even when it\n * lies outside the visible canvas area.\n *\n * Unlike a static centerline-based calculation, this accounts for the\n * current pan position \u2014 if the user pans right, the left bound tightens\n * because the image's left edge has moved right.\n *\n * @param state The current cropper state (crop, zoom, rotation, flip).\n * @param elementSize The fitted (unrotated) image element dimensions in pixels.\n * @param visualSize The visual (rotated) image bounding box in pixels.\n * @return The min/max x and y that a crop rect edge can reach in normalized space.\n */\nexport function getImageCropBounds(\n\tstate: CropperState,\n\telementSize: Size,\n\tvisualSize: Size\n): { minX: number; minY: number; maxX: number; maxY: number } {\n\tif ( ! isValidSize( elementSize ) || ! isValidSize( visualSize ) ) {\n\t\treturn { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n\t}\n\n\tconst safeState = sanitizeCropperState( state );\n\n\t// Build the same CSS matrix as use-transform-style: flip * rotate * zoom.\n\t// Flip is outside rotation so it acts in viewport axes (see createCamera).\n\tconst tx = safeState.pan.x * visualSize.width;\n\tconst ty = safeState.pan.y * visualSize.height;\n\tconst rad = degreesToRadians( safeState.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = safeState.flip.horizontal ? -1 : 1;\n\tconst sy = safeState.flip.vertical ? -1 : 1;\n\tconst z = safeState.zoom;\n\tconst ma = sx * cos * z;\n\tconst mb = sy * sin * z;\n\tconst mc = -sx * sin * z;\n\tconst md = sy * cos * z;\n\n\t// Image element corners relative to element center.\n\tconst hw = elementSize.width / 2;\n\tconst hh = elementSize.height / 2;\n\tconst corners = [\n\t\t[ -hw, -hh ],\n\t\t[ hw, -hh ],\n\t\t[ hw, hh ],\n\t\t[ -hw, hh ],\n\t];\n\n\tlet imgMinX = Infinity;\n\tlet imgMaxX = -Infinity;\n\tlet imgMinY = Infinity;\n\tlet imgMaxY = -Infinity;\n\n\tfor ( const [ cx, cy ] of corners ) {\n\t\t// Screen offset from element center after CSS matrix.\n\t\tconst screenX = ma * cx + mc * cy + tx;\n\t\tconst screenY = mb * cx + md * cy + ty;\n\t\t// Convert to normalized visual space.\n\t\t// The element center is at the visual image center, which is at\n\t\t// normalized (0.5, 0.5). So screen offset / visualSize + 0.5.\n\t\tconst nx = screenX / visualSize.width + 0.5;\n\t\tconst ny = screenY / visualSize.height + 0.5;\n\t\timgMinX = Math.min( imgMinX, nx );\n\t\timgMaxX = Math.max( imgMaxX, nx );\n\t\timgMinY = Math.min( imgMinY, ny );\n\t\timgMaxY = Math.max( imgMaxY, ny );\n\t}\n\n\treturn {\n\t\tminX: imgMinX,\n\t\tminY: imgMinY,\n\t\tmaxX: imgMaxX,\n\t\tmaxY: imgMaxY,\n\t};\n}\n\n/**\n * Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.\n * If the crop rect is too large for the current zoom and rotation, it is scaled\n * down proportionally and re-centered.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n *\n * @param cropRect The crop rectangle in normalized coordinates.\n * @param zoom The current zoom factor.\n * @param rotation The rotation angle in degrees.\n * @param imageAspectRatio The image width / height ratio.\n * @return The restricted crop rectangle.\n */\nexport function restrictCropRect(\n\tcropRect: NormalizedRect,\n\tzoom: number,\n\trotation: number,\n\timageAspectRatio: number\n): NormalizedRect {\n\t// Guard against non-finite inputs. The reducer normalizes these, but\n\t// programmatic callers or deserialized state could still send NaN/\u00B1Infinity\n\t// through here, where it would silently propagate into the crop rect.\n\tconst safeRect = sanitizeRect( cropRect );\n\tconst zoomCandidate = safeBoundedNumber( zoom, 1 );\n\tconst safeZoom = zoomCandidate >= Number.EPSILON ? zoomCandidate : 1;\n\tconst safeRotation = safeBoundedNumber( rotation, 0 );\n\tconst safeAspect = safeBoundedNumber( imageAspectRatio, 1 );\n\tconst aspectRatio = Math.max( safeAspect, Number.EPSILON );\n\t// Crop rect lives in the SNAP-rotation visual bbox (matching the stencil\n\t// layout); projection into the image-local frame uses the TRUE rotation.\n\tconst snapRotation = Math.round( safeRotation / 90 ) * 90;\n\tconst { visualW, visualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\tconst { absC, absS } = getVisualDimensions( safeRotation, aspectRatio );\n\tconst W = safeRect.width;\n\tconst H = safeRect.height;\n\n\t// Crop full-extents in pixel-proportional space, projected to image-local frame.\n\tconst cropWPx = W * visualW;\n\tconst cropHPx = H * visualH;\n\tconst spanAlpha = cropWPx * absC + cropHPx * absS;\n\tconst spanBeta = cropWPx * absS + cropHPx * absC;\n\n\t// Image full-extents at zoom z: (aspectRatio*z, z).\n\tconst limitAlpha = aspectRatio * safeZoom;\n\tconst limitBeta = safeZoom;\n\n\tlet t = 1;\n\tif ( spanAlpha > 0 ) {\n\t\tt = Math.min( t, limitAlpha / spanAlpha );\n\t}\n\tif ( spanBeta > 0 ) {\n\t\tt = Math.min( t, limitBeta / spanBeta );\n\t}\n\tif ( t >= 1 - EPSILON ) {\n\t\t// Crop fits at the current zoom \u2014 no size change needed.\n\t\t// Return the sanitized rect (not the raw arg) so non-finite fields\n\t\t// don't slip through this path. Position is handled by restrictPanZoom.\n\t\treturn safeRect;\n\t}\n\tconst newW = W * t;\n\tconst newH = H * t;\n\tconst centerX = safeRect.x + W / 2;\n\tconst centerY = safeRect.y + H / 2;\n\tlet newX = centerX - newW / 2;\n\tlet newY = centerY - newH / 2;\n\tnewX = Math.max( 0, Math.min( newX, 1 - newW ) );\n\tnewY = Math.max( 0, Math.min( newY, 1 - newH ) );\n\treturn { x: newX, y: newY, width: newW, height: newH };\n}\n\n/**\n * Canonical container used internally by restrictPanZoom.\n * Containment is scale-invariant, so the actual size doesn't matter \u2014\n * only the relative geometry between stencil and image matters.\n */\nconst CANONICAL_CONTAINER: Size = { width: 1000, height: 1000 };\n\n// Pre-allocated scratch buffers for restrictPanZoom's hot path (runs on\n// every pointermove) to avoid Float32Array allocation per call.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers\n * the crop rectangle.\n *\n * Uses the camera matrix to project: builds a camera from the candidate state,\n * maps the stencil corners (axis-aligned in the visual bounding box) to world\n * space via the inverse camera, and checks that all world points lie within\n * [0,1]\u00D7[0,1]. If any point is outside, computes the minimal pan correction.\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the image in pixels.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The restricted crop pan and zoom values.\n */\nexport function restrictPanZoom(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect\n): { pan: { x: number; y: number }; zoom: number } {\n\t// Algorithm overview:\n\t// 1. Ensure zoom is high enough for the rotated image to cover the crop.\n\t// 2. Build a camera (world\u2192screen matrix) with the candidate state.\n\t// 3. Build a base camera (no pan, zoom=1) to find where the stencil\n\t// sits in screen space \u2014 the stencil is anchored to the container,\n\t// not the image, so it doesn't move with pan or scale with zoom.\n\t// 4. Project the 4 stencil corners through the INVERSE of the main\n\t// camera to get world-space positions. A world point outside [0,1]\n\t// means that corner of the stencil isn't covered by the image.\n\t// 5. Compute the minimal translation in world space to push all corners\n\t// back inside [0,1].\n\t// 6. Convert the world-space correction to a pan-field correction by\n\t// mapping it through the camera's linear part back to screen space,\n\t// then dividing by the visual bounds.\n\tconst safeState = sanitizeCropperState( state );\n\tconst safeCropRect = sanitizeRect( cropRect );\n\t// Use `isValidSize` rather than a bare `> 0` check so Infinity dims\n\t// don't drive `Infinity / Infinity = NaN` into `getMinZoomForCover`\n\t// and leak as `zoom: NaN` through the no-correction early return.\n\tconst aspectRatio = isValidSize( imageSize )\n\t\t? imageSize.width / imageSize.height\n\t\t: 1;\n\tconst minZoom = Math.max(\n\t\tABSOLUTE_MIN_ZOOM,\n\t\tgetMinZoomForCover( safeState.rotation, aspectRatio, safeCropRect )\n\t);\n\tconst zoom = Math.min( MAX_ZOOM, Math.max( safeState.zoom, minZoom ) );\n\n\t// Step 2: build camera with candidate pan and corrected zoom.\n\tconst candidateState = { ...safeState, zoom };\n\tconst camera = createCamera(\n\t\tcandidateState,\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\n\t// Build a base camera (zero pan, zoom=1) to get stencil positions.\n\t// The stencil is anchored to the container and laid out using the\n\t// nearest 90\u00B0 rotation (matching `getImageFit`), so it's stable\n\t// through fine rotation. CSS zoom only affects the <img> element,\n\t// not the stencil.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\tconst baseCamera = createCamera(\n\t\t{\n\t\t\t...candidateState,\n\t\t\tpan: { x: 0, y: 0 },\n\t\t\tzoom: 1,\n\t\t\trotation: snapRotation,\n\t\t},\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\t// Stencil corners in screen space (axis-aligned rect within visual bounds).\n\tconst stencilCorners: [ number, number ][] = [\n\t\t[\n\t\t\tvisibleBounds.left + safeCropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top + safeCropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( safeCropRect.x + safeCropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top + safeCropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( safeCropRect.x + safeCropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( safeCropRect.y + safeCropRect.height ) * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left + safeCropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( safeCropRect.y + safeCropRect.height ) * visibleBounds.height,\n\t\t],\n\t];\n\n\t// Map stencil corners to world space via inverse camera.\n\t// If a world point is outside [0,1], the image doesn't cover that spot.\n\t// Reuse module-level scratch buffers to avoid allocation per frame.\n\tmat2d.invert( _scratchMat, camera );\n\n\tlet minWx = Infinity;\n\tlet maxWx = -Infinity;\n\tlet minWy = Infinity;\n\tlet maxWy = -Infinity;\n\n\tfor ( const corner of stencilCorners ) {\n\t\tvec2.transformMat2d( _scratchVec, corner, _scratchMat );\n\t\tconst w = _scratchVec;\n\t\tif ( w[ 0 ] < minWx ) {\n\t\t\tminWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 0 ] > maxWx ) {\n\t\t\tmaxWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 1 ] < minWy ) {\n\t\t\tminWy = w[ 1 ];\n\t\t}\n\t\tif ( w[ 1 ] > maxWy ) {\n\t\t\tmaxWy = w[ 1 ];\n\t\t}\n\t}\n\n\t// If all world points are in [0,1], no correction needed.\n\tif (\n\t\tminWx >= -EPSILON &&\n\t\tmaxWx <= 1 + EPSILON &&\n\t\tminWy >= -EPSILON &&\n\t\tmaxWy <= 1 + EPSILON\n\t) {\n\t\treturn { pan: safeState.pan, zoom };\n\t}\n\n\t// Compute world-space correction needed.\n\t// If minWx < 0, we need to shift world points right by |minWx|.\n\t// If maxWx > 1, we need to shift world points left by (maxWx - 1).\n\t// If both, we're over-constrained (crop too big) \u2014 getMinZoomForCover\n\t// should have prevented this.\n\tlet dwx = 0;\n\tlet dwy = 0;\n\n\tif ( minWx < 0 && maxWx <= 1 + EPSILON ) {\n\t\tdwx = -minWx;\n\t} else if ( maxWx > 1 && minWx >= -EPSILON ) {\n\t\tdwx = 1 - maxWx;\n\t} else if ( minWx < 0 && maxWx > 1 ) {\n\t\t// Over-constrained: center it.\n\t\tdwx = ( 1 - maxWx - minWx ) / 2;\n\t}\n\n\tif ( minWy < 0 && maxWy <= 1 + EPSILON ) {\n\t\tdwy = -minWy;\n\t} else if ( maxWy > 1 && minWy >= -EPSILON ) {\n\t\tdwy = 1 - maxWy;\n\t} else if ( minWy < 0 && maxWy > 1 ) {\n\t\tdwy = ( 1 - maxWy - minWy ) / 2;\n\t}\n\n\t// Convert world-space correction to screen-space correction.\n\t// The camera's 2\u00D72 linear part (indices [0,1,2,3]) maps world deltas\n\t// to screen deltas: screenDelta = linear * worldDelta.\n\tconst dsx = camera[ 0 ] * dwx + camera[ 2 ] * dwy;\n\tconst dsy = camera[ 1 ] * dwx + camera[ 3 ] * dwy;\n\n\t// Convert screen-space correction to pan-field correction.\n\t// Pan in screen pixels = pan.x * visualW, pan.y * visualH.\n\t// The correction is subtractive: a positive world shift (dw > 0) means\n\t// the image needs to move opposite to pan direction, so pan decreases.\n\tconst newPanX =\n\t\tsafeState.pan.x -\n\t\t( visibleBounds.width > 0 ? dsx / visibleBounds.width : 0 );\n\tconst newPanY =\n\t\tsafeState.pan.y -\n\t\t( visibleBounds.height > 0 ? dsy / visibleBounds.height : 0 );\n\n\treturn {\n\t\tpan: { x: newPanX, y: newPanY },\n\t\tzoom,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,OAAO,YAAY;AAM5B,SAAS,mBAAmB,UAAU,gBAAgB;AACtD,SAAS,wBAAwB;AACjC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc,gBAAgB,wBAAwB;AAG/D,IAAM,UAAU;AAUhB,SAAS,oBACR,UACA,kBACmE;AACnE,QAAM,MAAM,iBAAkB,QAAS;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,eAAgB,kBAAkB,GAAG,QAAS;AAC3D,SAAO;AAAA,IACN,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AA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,CAAE,IAAI,MAAM,OAAQ,CAAE,IAAI;AAM9C,QAAM,UACL,UAAU,IAAI,KACZ,cAAc,QAAQ,IAAI,MAAM,cAAc,QAAQ;AACzD,QAAM,UACL,UAAU,IAAI,KACZ,cAAc,SAAS,IAAI,MAAM,cAAc,SAAS;AAE3D,SAAO;AAAA,IACN,KAAK,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,IAC9B;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/core/crop-rect.ts
|
|
2
|
+
function computeInscribedRect(aspectRatio, visualSize) {
|
|
3
|
+
let w = 1;
|
|
4
|
+
let h = 1;
|
|
5
|
+
if (aspectRatio && aspectRatio > 0 && visualSize.width > 0) {
|
|
6
|
+
const normalizedRatio = aspectRatio * visualSize.height / visualSize.width;
|
|
7
|
+
if (normalizedRatio <= 1) {
|
|
8
|
+
w = normalizedRatio;
|
|
9
|
+
} else {
|
|
10
|
+
h = 1 / normalizedRatio;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
x: (1 - w) / 2,
|
|
15
|
+
y: (1 - h) / 2,
|
|
16
|
+
width: w,
|
|
17
|
+
height: h
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
computeInscribedRect
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=crop-rect.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/image-editor/core/crop-rect.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Size } from './types';\n\n/**\n * Largest rect of the given pixel aspect ratio that fits inside the\n * visual bounds, centered in [0,1] \u00D7 [0,1] normalized space. Returns\n * a full-frame rect (1\u00D71) if `aspectRatio` is unset or non-positive.\n *\n * The returned rect is the same in either freeform or fixed-crop\n * mode \u2014 it's the canonical \"centered crop for this ratio at this\n * canvas size\".\n *\n * @param aspectRatio Desired pixel width/height ratio. `undefined`\n * (or 0/negative) means no lock \u2014 returns full frame.\n * @param visualSize Rendered image dimensions in pixels.\n */\nexport function computeInscribedRect(\n\taspectRatio: number | undefined,\n\tvisualSize: Size\n): NormalizedRect {\n\tlet w = 1;\n\tlet h = 1;\n\tif ( aspectRatio && aspectRatio > 0 && visualSize.width > 0 ) {\n\t\t// normalizedRatio = w/h in normalized space that produces the\n\t\t// desired pixel aspect ratio.\n\t\t// pixelW = w * visualW, pixelH = h * visualH\n\t\t// pixelW / pixelH = aspectRatio\n\t\t// => w / h = aspectRatio * visualH / visualW\n\t\tconst normalizedRatio =\n\t\t\t( aspectRatio * visualSize.height ) / visualSize.width;\n\t\tif ( normalizedRatio <= 1 ) {\n\t\t\tw = normalizedRatio;\n\t\t} else {\n\t\t\th = 1 / normalizedRatio;\n\t\t}\n\t}\n\treturn {\n\t\tx: ( 1 - w ) / 2,\n\t\ty: ( 1 - h ) / 2,\n\t\twidth: w,\n\t\theight: h,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAkBO,SAAS,qBACf,aACA,YACiB;AACjB,MAAI,IAAI;AACR,MAAI,IAAI;AACR,MAAK,eAAe,cAAc,KAAK,WAAW,QAAQ,GAAI;AAM7D,UAAM,kBACH,cAAc,WAAW,SAAW,WAAW;AAClD,QAAK,mBAAmB,GAAI;AAC3B,UAAI;AAAA,IACL,OAAO;AACN,UAAI,IAAI;AAAA,IACT;AAAA,EACD;AACA,SAAO;AAAA,IACN,IAAK,IAAI,KAAM;AAAA,IACf,IAAK,IAAI,KAAM;AAAA,IACf,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -4,7 +4,14 @@ import {
|
|
|
4
4
|
DEFAULT_ASPECT_RATIOS,
|
|
5
5
|
ORIGINAL_ASPECT_RATIO
|
|
6
6
|
} from "./constants.mjs";
|
|
7
|
+
import {
|
|
8
|
+
cropperReducer,
|
|
9
|
+
enforceContainment,
|
|
10
|
+
areCropperStatesEqual,
|
|
11
|
+
isStateDirty
|
|
12
|
+
} from "./state.mjs";
|
|
7
13
|
import { getSourceRegion, getSourceRegionPercent } from "./source-region.mjs";
|
|
14
|
+
import { computeInscribedRect } from "./crop-rect.mjs";
|
|
8
15
|
import {
|
|
9
16
|
applyOperationToState,
|
|
10
17
|
stateFromPipeline
|
|
@@ -16,9 +23,14 @@ export {
|
|
|
16
23
|
ORIGINAL_ASPECT_RATIO,
|
|
17
24
|
applyOperationToState,
|
|
18
25
|
applyToCanvas,
|
|
26
|
+
areCropperStatesEqual,
|
|
27
|
+
computeInscribedRect,
|
|
28
|
+
cropperReducer,
|
|
29
|
+
enforceContainment,
|
|
19
30
|
exportCroppedImage,
|
|
20
31
|
getSourceRegion,
|
|
21
32
|
getSourceRegionPercent,
|
|
33
|
+
isStateDirty,
|
|
22
34
|
stateFromPipeline
|
|
23
35
|
};
|
|
24
36
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Types\nexport type {\n\tCropperState,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tFlip,\n\tStencilProps,\n} from './types';\n//
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["// Types\nexport type {\n\tCropperState,\n\tCropperAction,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tFlip,\n\tStencilProps,\n\tHandlePosition,\n} from './types';\n\n// Constants\nexport {\n\tDEFAULT_STATE,\n\tDEFAULT_ASPECT_RATIOS,\n\tORIGINAL_ASPECT_RATIO,\n} from './constants';\nexport type { AspectRatioPreset } from './constants';\n\n// Reducer + state helpers. `CropperAction` and `cropperReducer` are\n// exported so composite stores can delegate cropper actions through the\n// pure reducer (see `useMediaEditorState`). Most consumers should\n// instead drive state through the named setters on `CropperController`.\nexport {\n\tcropperReducer,\n\tenforceContainment,\n\tareCropperStatesEqual,\n\tisStateDirty,\n} from './state';\n\n// Source region (pixel and percentage)\nexport { getSourceRegion, getSourceRegionPercent } from './source-region';\nexport type { SourceRegion, SourceRegionPercent } from './source-region';\n\n// Crop-rect helpers\nexport { computeInscribedRect } from './crop-rect';\n\n// Pipeline\nexport {\n\tapplyOperationToState,\n\tstateFromPipeline,\n} from './transforms/pipeline';\n\n// Export / canvas\nexport { exportCroppedImage, applyToCanvas } from './export/canvas-renderer';\n"],
|
|
5
|
+
"mappings": ";AAcA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAOP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGP,SAAS,iBAAiB,8BAA8B;AAIxD,SAAS,4BAA4B;AAGrC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAGP,SAAS,oBAAoB,qBAAqB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/interaction-controller.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedPoint, Size } from './types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tDEFAULT_WHEEL_ZOOM_SPEED,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n\tMIN_ZOOM,\n\tMAX_ZOOM,\n} from './constants';\nimport { restrictPanZoom } from './containment';\n\n/** Time window for detecting a double-tap gesture (ms). */\nconst DOUBLE_TAP_TIME = 300;\n/** Max distance between taps to count as a double-tap (px). */\nconst DOUBLE_TAP_DISTANCE = 30;\n/** Duration of the zoom animation state (ms). */\nconst ZOOM_ANIMATION_DURATION = 200;\n\n/**\n * Get the natural image dimensions from cropper state, falling back to 1x1.\n *\n * @param state The current cropper state.\n * @return The image dimensions.\n */\nfunction getImageSizeFromState( state: CropperState ): {\n\twidth: number;\n\theight: number;\n} {\n\treturn state.image\n\t\t? { width: state.image.naturalWidth, height: state.image.naturalHeight }\n\t\t: { width: 1, height: 1 };\n}\n\n/**\n * Get the distance between two touch points.\n *\n * @param t1 The first touch.\n * @param t2 The second touch.\n * @return The pixel distance between the two touches.\n */\nfunction getTouchDistance( t1: Touch, t2: Touch ): number {\n\tconst dx = t1.clientX - t2.clientX;\n\tconst dy = t1.clientY - t2.clientY;\n\treturn Math.sqrt( dx * dx + dy * dy );\n}\n\n/**\n * Status reported by the interaction controller when drag/zoom state changes.\n */\nexport interface InteractionStatus {\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n}\n\n/**\n * State updates the interaction controller can request from its host UI.\n */\nexport interface CropperInteractionActions {\n\t/** Set the image pan offset in normalized coordinates. */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/** Set the zoom level. */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together for focal-point zoom. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Snap rotate by 90 degrees. */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Toggle flip on the given axis. */\n\ttoggleFlip?: ( direction: 'horizontal' | 'vertical' ) => void;\n}\n\n/**\n * Options for creating an InteractionController.\n *\n * Scalar options (minZoom, maxZoom, etc.) are read lazily on each\n * interaction, so changes to the options object take effect immediately\n * without recreating the controller.\n */\nexport interface InteractionControllerOptions {\n\t/** Returns the current cropper state. Called on every interaction. */\n\tgetState: () => CropperState;\n\t/** State updates the interaction controller can request from its host UI. */\n\tactions: CropperInteractionActions;\n\t/** Returns the container dimensions in pixels. */\n\tgetContainerSize: () => Size;\n\t/** Returns the rendered image dimensions in pixels, if available. */\n\tgetImageSize: () => Size | undefined;\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. Read lazily. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. Read lazily. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. Read lazily. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Read lazily. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. Read lazily. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/** Called when isDragging or isZooming changes. */\n\tonStatusChange?: ( status: InteractionStatus ) => void;\n}\n\n/**\n * Framework-agnostic imperative controller for image cropper interactions.\n *\n * Handles mouse, touch, and keyboard event processing for pan, zoom,\n * and crop manipulation. Uses requestAnimationFrame for drag/pinch\n * updates to avoid layout thrashing.\n *\n * The controller does not register DOM event listeners itself \u2014 that is the\n * responsibility of the UI layer (React hook, Vue directive, or vanilla JS).\n * Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,\n * and `handleKeyDown` methods that the UI layer calls with native DOM events.\n *\n * Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)\n * are read lazily from `this.options` on each interaction, so the UI layer\n * can update them without recreating the controller.\n *\n * Call `destroy()` to clean up timers and pending animation frames.\n */\nexport class InteractionController {\n\tprivate readonly options: InteractionControllerOptions;\n\n\t/** Current drag/zoom status. */\n\tprivate isDragging = false;\n\tprivate isZooming = false;\n\n\t/** Active drag state during pointer interactions. */\n\tprivate drag: {\n\t\tstartX: number;\n\t\tstartY: number;\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t} | null = null;\n\n\t/** Active touch state during touch interactions. */\n\tprivate touch: {\n\t\t/** Finger distance at pinch start (0 until pinch detected). */\n\t\tstartDistance: number;\n\t\t/** Zoom level when pinch was detected. */\n\t\tstartZoom: number;\n\t\t/** First touch X/Y (for single-finger pan delta). */\n\t\tlastTouchX: number;\n\t\tlastTouchY: number;\n\t\t/** Pan when gesture started. */\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t\t/** Container rect snapshot for focal-point math. */\n\t\tcontainerRect?: DOMRect;\n\t\t/** Midpoint of two fingers when pinch was detected. */\n\t\tstartMidX: number;\n\t\tstartMidY: number;\n\t\t/** Whether pinch was ever detected during this gesture. */\n\t\tdidPinch: boolean;\n\t\t/** Whether any dispatch has occurred (prevents dispatching before first move). */\n\t\tmoved: boolean;\n\t} | null = null;\n\n\t/** Cleanup function for active touch listeners on document. */\n\tprivate touchCleanup: ( () => void ) | null = null;\n\n\t/**\n\t * Cleanup function for active pointer-drag listeners on the\n\t * captured element. Set while a pointer drag is in progress so\n\t * `destroy()` can tear the drag down cleanly if the consumer\n\t * unmounts mid-drag. Cleared on pointerup/lostpointercapture.\n\t */\n\tprivate pointerCleanup: ( () => void ) | null = null;\n\n\t/** Last tap info for double-tap detection. */\n\tprivate lastTap: {\n\t\ttime: number;\n\t\tx: number;\n\t\ty: number;\n\t} | null = null;\n\n\t/** Timer for the zoom animation state (double-tap). */\n\tprivate zoomTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Timer for wheel gesture debounce. */\n\tprivate wheelGestureTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Whether a wheel gesture is currently active. */\n\tprivate wheelGestureActive = false;\n\n\t/** Current requestAnimationFrame ID. */\n\tprivate rafId = 0;\n\n\tconstructor( options: InteractionControllerOptions ) {\n\t\tthis.options = options;\n\t}\n\n\t/** Read minZoom lazily so option changes take effect immediately. */\n\tprivate get minZoom(): number {\n\t\treturn this.options.minZoom ?? MIN_ZOOM;\n\t}\n\n\t/** Read maxZoom lazily so option changes take effect immediately. */\n\tprivate get maxZoom(): number {\n\t\treturn this.options.maxZoom ?? MAX_ZOOM;\n\t}\n\n\t/** Read zoomSpeed lazily so option changes take effect immediately. */\n\tprivate get zoomSpeed(): number {\n\t\treturn this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;\n\t}\n\n\t/** Read keyboardStep lazily so option changes take effect immediately. */\n\tprivate get keyboardStep(): number {\n\t\treturn this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;\n\t}\n\n\t/**\n\t * Get the keyboard pan step, including modifier-based coarse movement.\n\t *\n\t * @param event The native KeyboardEvent.\n\t * @return The normalized pan step.\n\t */\n\tprivate getKeyboardStep( event: KeyboardEvent ): number {\n\t\treturn event.shiftKey\n\t\t\t? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t: this.keyboardStep;\n\t}\n\n\t/** Read doubleTapZoom lazily so option changes take effect immediately. */\n\tprivate get doubleTapZoom(): number {\n\t\treturn this.options.doubleTapZoom ?? 2;\n\t}\n\n\t/**\n\t * Update the drag/zoom status and notify via callback if changed.\n\t *\n\t * @param update Partial status with isDragging and/or isZooming.\n\t */\n\tprivate setStatus(\n\t\tupdate: Partial< { isDragging: boolean; isZooming: boolean } >\n\t): void {\n\t\tlet changed = false;\n\t\tif (\n\t\t\tupdate.isDragging !== undefined &&\n\t\t\tupdate.isDragging !== this.isDragging\n\t\t) {\n\t\t\tthis.isDragging = update.isDragging;\n\t\t\tchanged = true;\n\t\t}\n\t\tif (\n\t\t\tupdate.isZooming !== undefined &&\n\t\t\tupdate.isZooming !== this.isZooming\n\t\t) {\n\t\t\tthis.isZooming = update.isZooming;\n\t\t\tchanged = true;\n\t\t}\n\t\tif ( changed ) {\n\t\t\tthis.options.onStatusChange?.( {\n\t\t\t\tisDragging: this.isDragging,\n\t\t\t\tisZooming: this.isZooming,\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a pointer-down event on the container element.\n\t *\n\t * Initiates a drag (pan) interaction. Captures the pointer on the\n\t * provided element and registers pointermove/pointerup/lostpointercapture\n\t * listeners for the duration of the drag.\n\t *\n\t * @param e The native PointerEvent.\n\t * @param el The DOM element to capture the pointer on.\n\t */\n\thandlePointerDown( e: PointerEvent, el: HTMLElement ): void {\n\t\t// Only handle primary button (left click / first touch).\n\t\tif ( e.button !== 0 ) {\n\t\t\treturn;\n\t\t}\n\t\te.preventDefault();\n\n\t\t// Blur any focused handle so its focus ring doesn't linger,\n\t\t// but leave the canvas itself alone so keyboard control works after drag.\n\t\tconst ownerDoc = el.ownerDocument;\n\t\tif (\n\t\t\townerDoc?.activeElement instanceof HTMLElement &&\n\t\t\townerDoc.activeElement !== el\n\t\t) {\n\t\t\townerDoc.activeElement.blur();\n\t\t}\n\n\t\tel.focus();\n\n\t\t// Capture pointer so drag works across iframe boundaries.\n\t\tel.setPointerCapture( e.pointerId );\n\n\t\tthis.setStatus( { isDragging: true } );\n\t\tthis.options.onGestureStart?.();\n\n\t\tconst currentState = this.options.getState();\n\t\tthis.drag = {\n\t\t\tstartX: e.clientX,\n\t\t\tstartY: e.clientY,\n\t\t\tstartPanX: currentState.pan.x,\n\t\t\tstartPanY: currentState.pan.y,\n\t\t};\n\n\t\tconst onPointerMove = ( moveEvent: Event ) => {\n\t\t\tconst drag = this.drag;\n\t\t\tif ( ! drag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst pe = moveEvent as PointerEvent;\n\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\t\tconst s = this.options.getState();\n\t\t\t\tconst imgSize = this.options.getImageSize();\n\t\t\t\tconst containerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = imgSize ?? containerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( pe.clientX - drag.startX ) / panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( pe.clientY - drag.startY ) / panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: drag.startPanX + deltaX,\n\t\t\t\t\t\t\ty: drag.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t} );\n\t\t};\n\n\t\tconst removeListeners = () => {\n\t\t\tel.removeEventListener( 'pointermove', onPointerMove );\n\t\t\tel.removeEventListener( 'pointerup', onPointerUp );\n\t\t\tel.removeEventListener( 'lostpointercapture', onPointerUp );\n\t\t};\n\n\t\tconst onPointerUp = () => {\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t\tthis.drag = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tremoveListeners();\n\t\t\tthis.pointerCleanup = null;\n\t\t};\n\n\t\tel.addEventListener( 'pointermove', onPointerMove );\n\t\tel.addEventListener( 'pointerup', onPointerUp );\n\t\tel.addEventListener( 'lostpointercapture', onPointerUp );\n\t\t// Expose cleanup to destroy() in case the consumer unmounts\n\t\t// mid-drag. The pending rAF is cancelled in destroy().\n\t\tthis.pointerCleanup = removeListeners;\n\t}\n\n\t/**\n\t * Handle a wheel event on the container element.\n\t *\n\t * Implements focal-point zoom: the point under the cursor stays\n\t * stationary on screen while the zoom level changes.\n\t *\n\t * Must be registered with `{ passive: false }` to allow preventDefault.\n\t *\n\t * @param e The native WheelEvent.\n\t */\n\thandleWheel( e: WheelEvent ): void {\n\t\te.preventDefault();\n\n\t\tif ( this.drag ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Debounced gesture boundaries for wheel zoom.\n\t\t// Start on first wheel event, end after 300ms of no events.\n\t\tif ( ! this.wheelGestureActive ) {\n\t\t\tthis.wheelGestureActive = true;\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.wheelGestureTimer = setTimeout( () => {\n\t\t\tthis.wheelGestureActive = false;\n\t\t\tthis.options.onGestureEnd?.();\n\t\t}, DOUBLE_TAP_TIME );\n\n\t\tconst s = this.options.getState();\n\t\tconst delta = -e.deltaY * this.zoomSpeed;\n\t\tconst newZoom = Math.min(\n\t\t\tthis.maxZoom,\n\t\t\tMath.max( this.minZoom, s.zoom + delta )\n\t\t);\n\n\t\tif ( newZoom === s.zoom ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Focal-point zoom: keep the point under the cursor stationary.\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\t\tconst visSize = imgSize ?? containerSize;\n\t\tconst target = e.currentTarget;\n\t\tconst rect =\n\t\t\ttarget instanceof Element\n\t\t\t\t? target.getBoundingClientRect()\n\t\t\t\t: undefined;\n\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\tconst fx = e.clientX - rect.left - containerSize.width / 2;\n\t\t\tconst fy = e.clientY - rect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - newZoom / s.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX = s.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\tconst newCropY = s.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },\n\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\ts.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a touch-start event on the container element.\n\t *\n\t * Supports single-finger pan, two-finger pinch zoom, and\n\t * double-tap to toggle between fit and 2x zoom. Registers\n\t * touchmove/touchend/touchcancel on the provided document for the\n\t * duration of the gesture.\n\t *\n\t * @param e The native TouchEvent.\n\t * @param containerRect The bounding rect of the container element.\n\t * @param doc The document to register move/end listeners on.\n\t * Defaults to globalThis.document. Pass the iframe's\n\t * contentDocument when running inside an iframe.\n\t */\n\thandleTouchStart(\n\t\te: TouchEvent,\n\t\tcontainerRect: DOMRect,\n\t\tdoc: Document = document\n\t): void {\n\t\t// Second finger arriving during an existing gesture \u2014 snapshot\n\t\t// pinch start values. handleTouchMove will detect 2 touches and\n\t\t// handle pinch automatically.\n\t\tif ( this.touch && e.touches.length === 2 ) {\n\t\t\tconst s = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch.didPinch = true;\n\t\t\tthis.touch.startDistance = distance;\n\t\t\tthis.touch.startZoom = s.zoom;\n\t\t\tthis.touch.startPanX = s.pan.x;\n\t\t\tthis.touch.startPanY = s.pan.y;\n\t\t\tthis.touch.startMidX = midX;\n\t\t\tthis.touch.startMidY = midY;\n\t\t\tthis.touch.containerRect = containerRect;\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( e.touches.length === 1 ) {\n\t\t\tconst tapX = e.touches[ 0 ].clientX;\n\t\t\tconst tapY = e.touches[ 0 ].clientY;\n\t\t\tif ( this.tryDoubleTap( e, tapX, tapY, containerRect ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentState = this.options.getState();\n\n\t\t\t// Record touch state. Don't decide pan vs pinch yet \u2014\n\t\t\t// that happens in handleTouchMove based on touches.length.\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: 0,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: e.touches[ 0 ].clientX,\n\t\t\t\tlastTouchY: e.touches[ 0 ].clientY,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: 0,\n\t\t\t\tstartMidY: 0,\n\t\t\t\tdidPinch: false,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t} else if ( e.touches.length === 2 ) {\n\t\t\t// Both fingers landed simultaneously (rare but possible).\n\t\t\tconst currentState = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: distance,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: 0,\n\t\t\t\tlastTouchY: 0,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: midX,\n\t\t\t\tstartMidY: midY,\n\t\t\t\tdidPinch: true,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\n\t\tconst onTouchEnd = () => {\n\t\t\tthis.touch = null;\n\t\t\tthis.touchCleanup = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tdoc.removeEventListener( 'touchmove', this.handleTouchMove );\n\t\t\tdoc.removeEventListener( 'touchend', onTouchEnd );\n\t\t\tdoc.removeEventListener( 'touchcancel', onTouchEnd );\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t};\n\n\t\t// Clean up any previous touch listeners before registering new ones.\n\t\tthis.touchCleanup?.();\n\n\t\tdoc.addEventListener( 'touchmove', this.handleTouchMove, {\n\t\t\tpassive: false,\n\t\t} );\n\t\tdoc.addEventListener( 'touchend', onTouchEnd );\n\t\tdoc.addEventListener( 'touchcancel', onTouchEnd );\n\n\t\tthis.touchCleanup = onTouchEnd;\n\t}\n\n\t// Handle a touchmove event during an active touch gesture. Decides pinch\n\t// vs. pan based on current `moveEvent.touches.length`, so the gesture\n\t// can transition between modes without timing sensitivity (e.g. fingers\n\t// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays\n\t// attached when used as an event listener.\n\tprivate handleTouchMove = ( moveEvent: TouchEvent ): void => {\n\t\tconst touch = this.touch;\n\t\tif ( ! touch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcancelAnimationFrame( this.rafId );\n\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\tconst s = this.options.getState();\n\n\t\t\tif ( moveEvent.touches.length === 2 ) {\n\t\t\t\t// Two fingers \u2192 always pinch, regardless of how gesture\n\t\t\t\t// started. Initialize pinch state on first 2-finger move.\n\t\t\t\tif ( ! touch.didPinch ) {\n\t\t\t\t\ttouch.didPinch = true;\n\t\t\t\t\ttouch.startDistance = getTouchDistance(\n\t\t\t\t\t\tmoveEvent.touches[ 0 ],\n\t\t\t\t\t\tmoveEvent.touches[ 1 ]\n\t\t\t\t\t);\n\t\t\t\t\ttouch.startZoom = s.zoom;\n\t\t\t\t\ttouch.startPanX = s.pan.x;\n\t\t\t\t\ttouch.startPanY = s.pan.y;\n\t\t\t\t\ttouch.startMidX =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientX +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientX ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\ttouch.startMidY =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientY +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientY ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst latestContainerSize = this.options.getContainerSize();\n\t\t\t\tconst latestImageSize = this.options.getImageSize();\n\n\t\t\t\t// Pinch zoom with focal point at finger midpoint,\n\t\t\t\t// plus simultaneous pan from midpoint drift.\n\t\t\t\tconst t0 = moveEvent.touches[ 0 ];\n\t\t\t\tconst t1 = moveEvent.touches[ 1 ];\n\t\t\t\tconst currentDistance = getTouchDistance( t0, t1 );\n\t\t\t\tconst ratio = currentDistance / touch.startDistance;\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, touch.startZoom * ratio )\n\t\t\t\t);\n\n\t\t\t\tconst visSize = latestImageSize ?? latestContainerSize;\n\t\t\t\tconst rect = touch.containerRect;\n\t\t\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\t\t\t// Current midpoint.\n\t\t\t\t\tconst mx =\n\t\t\t\t\t\t( t0.clientX + t1.clientX ) / 2 -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst my =\n\t\t\t\t\t\t( t0.clientY + t1.clientY ) / 2 -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\n\t\t\t\t\t// Pan from midpoint drift (fingers moving together).\n\t\t\t\t\tconst startMx =\n\t\t\t\t\t\ttouch.startMidX -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst startMy =\n\t\t\t\t\t\ttouch.startMidY -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\t\t\t\t\tconst panDx =\n\t\t\t\t\t\tvisSize.width > 0\n\t\t\t\t\t\t\t? ( mx - startMx ) / visSize.width\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst panDy =\n\t\t\t\t\t\tvisSize.height > 0\n\t\t\t\t\t\t\t? ( my - startMy ) / visSize.height\n\t\t\t\t\t\t\t: 0;\n\n\t\t\t\t\t// Focal-point zoom correction.\n\t\t\t\t\tconst zoomRatio = s.zoom !== 0 ? 1 - newZoom / s.zoom : 0;\n\t\t\t\t\tconst focalNormX = mx / visSize.width;\n\t\t\t\t\tconst focalNormY = my / visSize.height;\n\t\t\t\t\tconst zoomCropX =\n\t\t\t\t\t\ts.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\t\t\tconst zoomCropY =\n\t\t\t\t\t\ts.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\t\t\t// Combined: pan drift + zoom correction.\n\t\t\t\t\tconst newCropX =\n\t\t\t\t\t\ttouch.startPanX + panDx + ( zoomCropX - s.pan.x );\n\t\t\t\t\tconst newCropY =\n\t\t\t\t\t\ttouch.startPanY + panDy + ( zoomCropY - s.pan.y );\n\n\t\t\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...s,\n\t\t\t\t\t\t\tzoom: newZoom,\n\t\t\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\t\ts.cropRect\n\t\t\t\t\t);\n\t\t\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t\t\t} else if ( newZoom !== s.zoom ) {\n\t\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\t}\n\t\t\t} else if ( moveEvent.touches.length === 1 && ! touch.didPinch ) {\n\t\t\t\t// One finger and no pinch ever detected \u2192 pan.\n\t\t\t\t// If fingers went 2\u21921 (didPinch is true), we do NOT\n\t\t\t\t// switch to pan \u2014 avoids accidental pan after releasing\n\t\t\t\t// one finger from a pinch.\n\t\t\t\tif ( ! touch.moved ) {\n\t\t\t\t\ttouch.moved = true;\n\t\t\t\t\tthis.setStatus( { isDragging: true } );\n\t\t\t\t}\n\t\t\t\tconst panImageSize = this.options.getImageSize();\n\t\t\t\tconst panContainerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = panImageSize ?? panContainerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientX -\n\t\t\t\t\t\t\t\ttouch.lastTouchX ) /\n\t\t\t\t\t\t panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientY -\n\t\t\t\t\t\t\t\ttouch.lastTouchY ) /\n\t\t\t\t\t\t panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: touch.startPanX + deltaX,\n\t\t\t\t\t\t\ty: touch.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t}\n\t\t} );\n\t};\n\n\t// Handle double-tap-to-toggle-zoom. On a second tap within the configured\n\t// time/distance threshold, toggles zoom between `minZoom` and\n\t// `doubleTapZoom` around the tap point and dispatches. Returns `true` if\n\t// the tap was handled as a double-tap (caller should early-return),\n\t// `false` otherwise (caller proceeds with normal single-tap handling).\n\t// Either way, records the tap for next time.\n\tprivate tryDoubleTap(\n\t\te: TouchEvent,\n\t\ttapX: number,\n\t\ttapY: number,\n\t\tcontainerRect: DOMRect\n\t): boolean {\n\t\tconst now = Date.now();\n\t\tconst lastTap = this.lastTap;\n\t\tif ( ! lastTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\t\tconst timeDelta = now - lastTap.time;\n\t\tconst distDelta = Math.sqrt(\n\t\t\t( tapX - lastTap.x ) ** 2 + ( tapY - lastTap.y ) ** 2\n\t\t);\n\t\tconst isDoubleTap =\n\t\t\ttimeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;\n\t\tif ( ! isDoubleTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\n\t\t// It's a double-tap \u2014 suppress browser zoom.\n\t\te.preventDefault();\n\t\tthis.lastTap = null;\n\n\t\tconst currentState = this.options.getState();\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\n\t\t// Toggle: if past halfway to doubleTapZoom, go back to 1x.\n\t\tconst targetZoom =\n\t\t\tcurrentState.zoom > ( this.minZoom + this.doubleTapZoom ) / 2\n\t\t\t\t? this.minZoom\n\t\t\t\t: this.doubleTapZoom;\n\t\tconst visSize = imgSize ?? containerSize;\n\n\t\t// Enable zoom animation before dispatching.\n\t\tthis.setStatus( { isZooming: true } );\n\t\tclearTimeout( this.zoomTimer );\n\t\tthis.zoomTimer = setTimeout( () => {\n\t\t\tthis.setStatus( { isZooming: false } );\n\t\t}, ZOOM_ANIMATION_DURATION );\n\n\t\t// Double-tap bypasses the normal handleTouchStart gesture path so\n\t\t// onGestureStart/End are never called \u2014 fire them here so undo\n\t\t// receives a proper boundary around this discrete zoom action.\n\t\tthis.options.onGestureStart?.();\n\n\t\tif ( visSize.width > 0 && visSize.height > 0 ) {\n\t\t\tconst fx = tapX - containerRect.left - containerSize.width / 2;\n\t\t\tconst fy = tapY - containerRect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - targetZoom / currentState.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX =\n\t\t\t\tcurrentState.pan.x +\n\t\t\t\t( focalNormX - currentState.pan.x ) * zoomRatio;\n\t\t\tconst newCropY =\n\t\t\t\tcurrentState.pan.y +\n\t\t\t\t( focalNormY - currentState.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{\n\t\t\t\t\t...currentState,\n\t\t\t\t\tzoom: targetZoom,\n\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t},\n\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\tcurrentState.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( targetZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( targetZoom );\n\t\t}\n\n\t\tthis.options.onGestureEnd?.();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Handle a keydown event on the container element.\n\t *\n\t * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.\n\t *\n\t * @param e The native KeyboardEvent.\n\t */\n\thandleKeyDown( e: KeyboardEvent ): void {\n\t\tconst currentState = this.options.getState();\n\n\t\tswitch ( e.key ) {\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y + keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y - keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowLeft': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x + keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowRight': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x - keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '+':\n\t\t\tcase '=': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom + 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '-':\n\t\t\tcase '_': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom - 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'r':\n\t\t\tcase 'R': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.snapRotate90( e.shiftKey ? -1 : 1 );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'h':\n\t\t\tcase 'H': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'horizontal' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'v':\n\t\t\tcase 'V': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'vertical' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clean up all timers, animation frames, and active touch listeners.\n\t *\n\t * Must be called when the controller is no longer needed (e.g., on\n\t * component unmount or element removal).\n\t */\n\tdestroy(): void {\n\t\tcancelAnimationFrame( this.rafId );\n\t\tclearTimeout( this.zoomTimer );\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.touchCleanup?.();\n\t\tthis.touchCleanup = null;\n\t\tthis.pointerCleanup?.();\n\t\tthis.pointerCleanup = null;\n\t\tthis.drag = null;\n\t\tthis.touch = null;\n\t\tthis.lastTap = null;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";AAIA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,uBAAuB;AAGhC,IAAM,kBAAkB;AAExB,IAAM,sBAAsB;AAE5B,IAAM,0BAA0B;AAQhC,SAAS,sBAAuB,OAG9B;AACD,SAAO,MAAM,QACV,EAAE,OAAO,MAAM,MAAM,cAAc,QAAQ,MAAM,MAAM,cAAc,IACrE,EAAE,OAAO,GAAG,QAAQ,EAAE;AAC1B;AASA,SAAS,iBAAkB,IAAW,IAAoB;AACzD,QAAM,KAAK,GAAG,UAAU,GAAG;AAC3B,QAAM,KAAK,GAAG,UAAU,GAAG;AAC3B,SAAO,KAAK,KAAM,KAAK,KAAK,KAAK,EAAG;AACrC;AAmFO,IAAM,wBAAN,MAA4B;AAAA,EACjB;AAAA;AAAA,EAGT,aAAa;AAAA,EACb,YAAY;AAAA;AAAA,EAGZ,OAKG;AAAA;AAAA,EAGH,QAoBG;AAAA;AAAA,EAGH,eAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQtC,iBAAwC;AAAA;AAAA,EAGxC,UAIG;AAAA;AAAA,EAGH;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA,qBAAqB;AAAA;AAAA,EAGrB,QAAQ;AAAA,EAEhB,YAAa,SAAwC;AACpD,SAAK,UAAU;AAAA,EAChB;AAAA;AAAA,EAGA,IAAY,UAAkB;AAC7B,WAAO,KAAK,QAAQ,WAAW;AAAA,EAChC;AAAA;AAAA,EAGA,IAAY,UAAkB;AAC7B,WAAO,KAAK,QAAQ,WAAW;AAAA,EAChC;AAAA;AAAA,E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W;AACvD;AAAA,QACD;AACA,UAAE,eAAe;AACjB,aAAK,QAAQ,QAAQ,aAAc,UAAW;AAC9C;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAgB;AACf,yBAAsB,KAAK,KAAM;AACjC,iBAAc,KAAK,SAAU;AAC7B,iBAAc,KAAK,iBAAkB;AACrC,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,iBAAiB;AACtB,SAAK,iBAAiB;AACtB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;",
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedPoint, Size } from './types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tDEFAULT_WHEEL_ZOOM_SPEED,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n\tMIN_ZOOM,\n\tMAX_ZOOM,\n} from './constants';\nimport { restrictPanZoom } from './containment';\n\n/** Time window for detecting a double-tap gesture (ms). */\nconst DOUBLE_TAP_TIME = 300;\n/** Max distance between taps to count as a double-tap (px). */\nconst DOUBLE_TAP_DISTANCE = 30;\n/** Duration of the zoom animation state (ms). */\nconst ZOOM_ANIMATION_DURATION = 200;\n\n/**\n * Get the natural image dimensions from cropper state, falling back to 1x1.\n *\n * @param state The current cropper state.\n * @return The image dimensions.\n */\nfunction getImageSizeFromState( state: CropperState ): {\n\twidth: number;\n\theight: number;\n} {\n\treturn state.image\n\t\t? { width: state.image.naturalWidth, height: state.image.naturalHeight }\n\t\t: { width: 1, height: 1 };\n}\n\n/**\n * Get the distance between two touch points.\n *\n * @param t1 The first touch.\n * @param t2 The second touch.\n * @return The pixel distance between the two touches.\n */\nfunction getTouchDistance( t1: Touch, t2: Touch ): number {\n\tconst dx = t1.clientX - t2.clientX;\n\tconst dy = t1.clientY - t2.clientY;\n\treturn Math.sqrt( dx * dx + dy * dy );\n}\n\n/**\n * Status reported by the interaction controller when drag/zoom state changes.\n */\nexport interface InteractionStatus {\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n}\n\n/**\n * State updates the interaction controller can request from its host UI.\n */\nexport interface CropperInteractionActions {\n\t/** Set the image pan offset in normalized coordinates. */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/**\n\t * Set the zoom level. Cursorless surfaces (slider, keyboard `+`/`-`)\n\t * rely on this anchoring at the crop center; pointer-driven zoom\n\t * paths use `setZoomAtPoint` with an explicit focal point instead.\n\t */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together for focal-point zoom. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Snap rotate by 90 degrees. */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Toggle flip on the given axis. */\n\ttoggleFlip?: ( direction: 'horizontal' | 'vertical' ) => void;\n}\n\n/**\n * Options for creating an InteractionController.\n *\n * Scalar options (minZoom, maxZoom, etc.) are read lazily on each\n * interaction, so changes to the options object take effect immediately\n * without recreating the controller.\n */\nexport interface InteractionControllerOptions {\n\t/** Returns the current cropper state. Called on every interaction. */\n\tgetState: () => CropperState;\n\t/** State updates the interaction controller can request from its host UI. */\n\tactions: CropperInteractionActions;\n\t/** Returns the container dimensions in pixels. */\n\tgetContainerSize: () => Size;\n\t/** Returns the rendered image dimensions in pixels, if available. */\n\tgetImageSize: () => Size | undefined;\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. Read lazily. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. Read lazily. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. Read lazily. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Read lazily. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. Read lazily. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/** Called when isDragging or isZooming changes. */\n\tonStatusChange?: ( status: InteractionStatus ) => void;\n}\n\n/**\n * Framework-agnostic imperative controller for image cropper interactions.\n *\n * Handles mouse, touch, and keyboard event processing for pan, zoom,\n * and crop manipulation. Uses requestAnimationFrame for drag/pinch\n * updates to avoid layout thrashing.\n *\n * The controller does not register DOM event listeners itself \u2014 that is the\n * responsibility of the UI layer (React hook, Vue directive, or vanilla JS).\n * Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,\n * and `handleKeyDown` methods that the UI layer calls with native DOM events.\n *\n * Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)\n * are read lazily from `this.options` on each interaction, so the UI layer\n * can update them without recreating the controller.\n *\n * Call `destroy()` to clean up timers and pending animation frames.\n */\nexport class InteractionController {\n\tprivate readonly options: InteractionControllerOptions;\n\n\t/** Current drag/zoom status. */\n\tprivate isDragging = false;\n\tprivate isZooming = false;\n\n\t/** Active drag state during pointer interactions. */\n\tprivate drag: {\n\t\tstartX: number;\n\t\tstartY: number;\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t} | null = null;\n\n\t/** Active touch state during touch interactions. */\n\tprivate touch: {\n\t\t/** Finger distance at pinch start (0 until pinch detected). */\n\t\tstartDistance: number;\n\t\t/** Zoom level when pinch was detected. */\n\t\tstartZoom: number;\n\t\t/** First touch X/Y (for single-finger pan delta). */\n\t\tlastTouchX: number;\n\t\tlastTouchY: number;\n\t\t/** Pan when gesture started. */\n\t\tstartPanX: number;\n\t\tstartPanY: number;\n\t\t/** Container rect snapshot for focal-point math. */\n\t\tcontainerRect?: DOMRect;\n\t\t/** Midpoint of two fingers when pinch was detected. */\n\t\tstartMidX: number;\n\t\tstartMidY: number;\n\t\t/** Whether pinch was ever detected during this gesture. */\n\t\tdidPinch: boolean;\n\t\t/** Whether any dispatch has occurred (prevents dispatching before first move). */\n\t\tmoved: boolean;\n\t} | null = null;\n\n\t/** Cleanup function for active touch listeners on document. */\n\tprivate touchCleanup: ( () => void ) | null = null;\n\n\t/**\n\t * Cleanup function for active pointer-drag listeners on the\n\t * captured element. Set while a pointer drag is in progress so\n\t * `destroy()` can tear the drag down cleanly if the consumer\n\t * unmounts mid-drag. Cleared on pointerup/lostpointercapture.\n\t */\n\tprivate pointerCleanup: ( () => void ) | null = null;\n\n\t/** Last tap info for double-tap detection. */\n\tprivate lastTap: {\n\t\ttime: number;\n\t\tx: number;\n\t\ty: number;\n\t} | null = null;\n\n\t/** Timer for the zoom animation state (double-tap). */\n\tprivate zoomTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Timer for wheel gesture debounce. */\n\tprivate wheelGestureTimer: ReturnType< typeof setTimeout > | undefined;\n\n\t/** Whether a wheel gesture is currently active. */\n\tprivate wheelGestureActive = false;\n\n\t/** Current requestAnimationFrame ID. */\n\tprivate rafId = 0;\n\n\tconstructor( options: InteractionControllerOptions ) {\n\t\tthis.options = options;\n\t}\n\n\t/** Read minZoom lazily so option changes take effect immediately. */\n\tprivate get minZoom(): number {\n\t\treturn this.options.minZoom ?? MIN_ZOOM;\n\t}\n\n\t/** Read maxZoom lazily so option changes take effect immediately. */\n\tprivate get maxZoom(): number {\n\t\treturn this.options.maxZoom ?? MAX_ZOOM;\n\t}\n\n\t/** Read zoomSpeed lazily so option changes take effect immediately. */\n\tprivate get zoomSpeed(): number {\n\t\treturn this.options.zoomSpeed ?? DEFAULT_WHEEL_ZOOM_SPEED;\n\t}\n\n\t/** Read keyboardStep lazily so option changes take effect immediately. */\n\tprivate get keyboardStep(): number {\n\t\treturn this.options.keyboardStep ?? DEFAULT_KEYBOARD_STEP;\n\t}\n\n\t/**\n\t * Get the keyboard pan step, including modifier-based coarse movement.\n\t *\n\t * @param event The native KeyboardEvent.\n\t * @return The normalized pan step.\n\t */\n\tprivate getKeyboardStep( event: KeyboardEvent ): number {\n\t\treturn event.shiftKey\n\t\t\t? this.keyboardStep * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t: this.keyboardStep;\n\t}\n\n\t/** Read doubleTapZoom lazily so option changes take effect immediately. */\n\tprivate get doubleTapZoom(): number {\n\t\treturn this.options.doubleTapZoom ?? 2;\n\t}\n\n\t/**\n\t * Update the drag/zoom status and notify via callback if changed.\n\t *\n\t * @param update Partial status with isDragging and/or isZooming.\n\t */\n\tprivate setStatus(\n\t\tupdate: Partial< { isDragging: boolean; isZooming: boolean } >\n\t): void {\n\t\tlet changed = false;\n\t\tif (\n\t\t\tupdate.isDragging !== undefined &&\n\t\t\tupdate.isDragging !== this.isDragging\n\t\t) {\n\t\t\tthis.isDragging = update.isDragging;\n\t\t\tchanged = true;\n\t\t}\n\t\tif (\n\t\t\tupdate.isZooming !== undefined &&\n\t\t\tupdate.isZooming !== this.isZooming\n\t\t) {\n\t\t\tthis.isZooming = update.isZooming;\n\t\t\tchanged = true;\n\t\t}\n\t\tif ( changed ) {\n\t\t\tthis.options.onStatusChange?.( {\n\t\t\t\tisDragging: this.isDragging,\n\t\t\t\tisZooming: this.isZooming,\n\t\t\t} );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a pointer-down event on the container element.\n\t *\n\t * Initiates a drag (pan) interaction. Captures the pointer on the\n\t * provided element and registers pointermove/pointerup/lostpointercapture\n\t * listeners for the duration of the drag.\n\t *\n\t * @param e The native PointerEvent.\n\t * @param el The DOM element to capture the pointer on.\n\t */\n\thandlePointerDown( e: PointerEvent, el: HTMLElement ): void {\n\t\t// Only handle primary button (left click / first touch).\n\t\tif ( e.button !== 0 ) {\n\t\t\treturn;\n\t\t}\n\t\te.preventDefault();\n\n\t\t// Blur any focused handle so its focus ring doesn't linger,\n\t\t// but leave the canvas itself alone so keyboard control works after drag.\n\t\tconst ownerDoc = el.ownerDocument;\n\t\tif (\n\t\t\townerDoc?.activeElement instanceof HTMLElement &&\n\t\t\townerDoc.activeElement !== el\n\t\t) {\n\t\t\townerDoc.activeElement.blur();\n\t\t}\n\n\t\tel.focus();\n\n\t\t// Capture pointer so drag works across iframe boundaries.\n\t\tel.setPointerCapture( e.pointerId );\n\n\t\tthis.setStatus( { isDragging: true } );\n\t\tthis.options.onGestureStart?.();\n\n\t\tconst currentState = this.options.getState();\n\t\tthis.drag = {\n\t\t\tstartX: e.clientX,\n\t\t\tstartY: e.clientY,\n\t\t\tstartPanX: currentState.pan.x,\n\t\t\tstartPanY: currentState.pan.y,\n\t\t};\n\n\t\tconst onPointerMove = ( moveEvent: Event ) => {\n\t\t\tconst drag = this.drag;\n\t\t\tif ( ! drag ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst pe = moveEvent as PointerEvent;\n\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\t\tconst s = this.options.getState();\n\t\t\t\tconst imgSize = this.options.getImageSize();\n\t\t\t\tconst containerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = imgSize ?? containerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( pe.clientX - drag.startX ) / panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( pe.clientY - drag.startY ) / panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: drag.startPanX + deltaX,\n\t\t\t\t\t\t\ty: drag.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t} );\n\t\t};\n\n\t\tconst removeListeners = () => {\n\t\t\tel.removeEventListener( 'pointermove', onPointerMove );\n\t\t\tel.removeEventListener( 'pointerup', onPointerUp );\n\t\t\tel.removeEventListener( 'lostpointercapture', onPointerUp );\n\t\t};\n\n\t\tconst onPointerUp = () => {\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t\tthis.drag = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tremoveListeners();\n\t\t\tthis.pointerCleanup = null;\n\t\t};\n\n\t\tel.addEventListener( 'pointermove', onPointerMove );\n\t\tel.addEventListener( 'pointerup', onPointerUp );\n\t\tel.addEventListener( 'lostpointercapture', onPointerUp );\n\t\t// Expose cleanup to destroy() in case the consumer unmounts\n\t\t// mid-drag. The pending rAF is cancelled in destroy().\n\t\tthis.pointerCleanup = removeListeners;\n\t}\n\n\t/**\n\t * Handle a wheel event on the container element.\n\t *\n\t * Implements focal-point zoom: the point under the cursor stays\n\t * stationary on screen while the zoom level changes.\n\t *\n\t * Must be registered with `{ passive: false }` to allow preventDefault.\n\t *\n\t * @param e The native WheelEvent.\n\t */\n\thandleWheel( e: WheelEvent ): void {\n\t\te.preventDefault();\n\n\t\tif ( this.drag ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Debounced gesture boundaries for wheel zoom.\n\t\t// Start on first wheel event, end after 300ms of no events.\n\t\tif ( ! this.wheelGestureActive ) {\n\t\t\tthis.wheelGestureActive = true;\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.wheelGestureTimer = setTimeout( () => {\n\t\t\tthis.wheelGestureActive = false;\n\t\t\tthis.options.onGestureEnd?.();\n\t\t}, DOUBLE_TAP_TIME );\n\n\t\tconst s = this.options.getState();\n\t\tconst delta = -e.deltaY * this.zoomSpeed;\n\t\tconst newZoom = Math.min(\n\t\t\tthis.maxZoom,\n\t\t\tMath.max( this.minZoom, s.zoom + delta )\n\t\t);\n\n\t\tif ( newZoom === s.zoom ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Focal-point zoom: keep the point under the cursor stationary.\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\t\tconst visSize = imgSize ?? containerSize;\n\t\tconst target = e.currentTarget;\n\t\tconst rect =\n\t\t\ttarget instanceof Element\n\t\t\t\t? target.getBoundingClientRect()\n\t\t\t\t: undefined;\n\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\tconst fx = e.clientX - rect.left - containerSize.width / 2;\n\t\t\tconst fy = e.clientY - rect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - newZoom / s.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX = s.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\tconst newCropY = s.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },\n\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\ts.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t}\n\t}\n\n\t/**\n\t * Handle a touch-start event on the container element.\n\t *\n\t * Supports single-finger pan, two-finger pinch zoom, and\n\t * double-tap to toggle between fit and 2x zoom. Registers\n\t * touchmove/touchend/touchcancel on the provided document for the\n\t * duration of the gesture.\n\t *\n\t * @param e The native TouchEvent.\n\t * @param containerRect The bounding rect of the container element.\n\t * @param doc The document to register move/end listeners on.\n\t * Defaults to globalThis.document. Pass the iframe's\n\t * contentDocument when running inside an iframe.\n\t */\n\thandleTouchStart(\n\t\te: TouchEvent,\n\t\tcontainerRect: DOMRect,\n\t\tdoc: Document = document\n\t): void {\n\t\t// Second finger arriving during an existing gesture \u2014 snapshot\n\t\t// pinch start values. handleTouchMove will detect 2 touches and\n\t\t// handle pinch automatically.\n\t\tif ( this.touch && e.touches.length === 2 ) {\n\t\t\tconst s = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch.didPinch = true;\n\t\t\tthis.touch.startDistance = distance;\n\t\t\tthis.touch.startZoom = s.zoom;\n\t\t\tthis.touch.startPanX = s.pan.x;\n\t\t\tthis.touch.startPanY = s.pan.y;\n\t\t\tthis.touch.startMidX = midX;\n\t\t\tthis.touch.startMidY = midY;\n\t\t\tthis.touch.containerRect = containerRect;\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( e.touches.length === 1 ) {\n\t\t\tconst tapX = e.touches[ 0 ].clientX;\n\t\t\tconst tapY = e.touches[ 0 ].clientY;\n\t\t\tif ( this.tryDoubleTap( e, tapX, tapY, containerRect ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentState = this.options.getState();\n\n\t\t\t// Record touch state. Don't decide pan vs pinch yet \u2014\n\t\t\t// that happens in handleTouchMove based on touches.length.\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: 0,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: e.touches[ 0 ].clientX,\n\t\t\t\tlastTouchY: e.touches[ 0 ].clientY,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: 0,\n\t\t\t\tstartMidY: 0,\n\t\t\t\tdidPinch: false,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t} else if ( e.touches.length === 2 ) {\n\t\t\t// Both fingers landed simultaneously (rare but possible).\n\t\t\tconst currentState = this.options.getState();\n\t\t\tconst distance = getTouchDistance( e.touches[ 0 ], e.touches[ 1 ] );\n\t\t\tconst midX =\n\t\t\t\t( e.touches[ 0 ].clientX + e.touches[ 1 ].clientX ) / 2;\n\t\t\tconst midY =\n\t\t\t\t( e.touches[ 0 ].clientY + e.touches[ 1 ].clientY ) / 2;\n\t\t\tthis.touch = {\n\t\t\t\tstartDistance: distance,\n\t\t\t\tstartZoom: currentState.zoom,\n\t\t\t\tlastTouchX: 0,\n\t\t\t\tlastTouchY: 0,\n\t\t\t\tstartPanX: currentState.pan.x,\n\t\t\t\tstartPanY: currentState.pan.y,\n\t\t\t\tcontainerRect,\n\t\t\t\tstartMidX: midX,\n\t\t\t\tstartMidY: midY,\n\t\t\t\tdidPinch: true,\n\t\t\t\tmoved: false,\n\t\t\t};\n\t\t\tthis.options.onGestureStart?.();\n\t\t}\n\n\t\tconst onTouchEnd = () => {\n\t\t\tthis.touch = null;\n\t\t\tthis.touchCleanup = null;\n\t\t\tcancelAnimationFrame( this.rafId );\n\t\t\tdoc.removeEventListener( 'touchmove', this.handleTouchMove );\n\t\t\tdoc.removeEventListener( 'touchend', onTouchEnd );\n\t\t\tdoc.removeEventListener( 'touchcancel', onTouchEnd );\n\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\tthis.options.onGestureEnd?.();\n\t\t};\n\n\t\t// Clean up any previous touch listeners before registering new ones.\n\t\tthis.touchCleanup?.();\n\n\t\tdoc.addEventListener( 'touchmove', this.handleTouchMove, {\n\t\t\tpassive: false,\n\t\t} );\n\t\tdoc.addEventListener( 'touchend', onTouchEnd );\n\t\tdoc.addEventListener( 'touchcancel', onTouchEnd );\n\n\t\tthis.touchCleanup = onTouchEnd;\n\t}\n\n\t// Handle a touchmove event during an active touch gesture. Decides pinch\n\t// vs. pan based on current `moveEvent.touches.length`, so the gesture\n\t// can transition between modes without timing sensitivity (e.g. fingers\n\t// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays\n\t// attached when used as an event listener.\n\tprivate handleTouchMove = ( moveEvent: TouchEvent ): void => {\n\t\tconst touch = this.touch;\n\t\tif ( ! touch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcancelAnimationFrame( this.rafId );\n\t\tthis.rafId = requestAnimationFrame( () => {\n\t\t\tconst s = this.options.getState();\n\n\t\t\tif ( moveEvent.touches.length === 2 ) {\n\t\t\t\t// Two fingers \u2192 always pinch, regardless of how gesture\n\t\t\t\t// started. Initialize pinch state on first 2-finger move.\n\t\t\t\tif ( ! touch.didPinch ) {\n\t\t\t\t\ttouch.didPinch = true;\n\t\t\t\t\ttouch.startDistance = getTouchDistance(\n\t\t\t\t\t\tmoveEvent.touches[ 0 ],\n\t\t\t\t\t\tmoveEvent.touches[ 1 ]\n\t\t\t\t\t);\n\t\t\t\t\ttouch.startZoom = s.zoom;\n\t\t\t\t\ttouch.startPanX = s.pan.x;\n\t\t\t\t\ttouch.startPanY = s.pan.y;\n\t\t\t\t\ttouch.startMidX =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientX +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientX ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\ttouch.startMidY =\n\t\t\t\t\t\t( moveEvent.touches[ 0 ].clientY +\n\t\t\t\t\t\t\tmoveEvent.touches[ 1 ].clientY ) /\n\t\t\t\t\t\t2;\n\t\t\t\t\tthis.setStatus( { isDragging: false } );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst latestContainerSize = this.options.getContainerSize();\n\t\t\t\tconst latestImageSize = this.options.getImageSize();\n\n\t\t\t\t// Pinch zoom with focal point at finger midpoint,\n\t\t\t\t// plus simultaneous pan from midpoint drift.\n\t\t\t\tconst t0 = moveEvent.touches[ 0 ];\n\t\t\t\tconst t1 = moveEvent.touches[ 1 ];\n\t\t\t\tconst currentDistance = getTouchDistance( t0, t1 );\n\t\t\t\tconst ratio = currentDistance / touch.startDistance;\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, touch.startZoom * ratio )\n\t\t\t\t);\n\n\t\t\t\tconst visSize = latestImageSize ?? latestContainerSize;\n\t\t\t\tconst rect = touch.containerRect;\n\t\t\t\tif ( visSize.width > 0 && visSize.height > 0 && rect ) {\n\t\t\t\t\t// Current midpoint.\n\t\t\t\t\tconst mx =\n\t\t\t\t\t\t( t0.clientX + t1.clientX ) / 2 -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst my =\n\t\t\t\t\t\t( t0.clientY + t1.clientY ) / 2 -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\n\t\t\t\t\t// Pan from midpoint drift (fingers moving together).\n\t\t\t\t\tconst startMx =\n\t\t\t\t\t\ttouch.startMidX -\n\t\t\t\t\t\trect.left -\n\t\t\t\t\t\tlatestContainerSize.width / 2;\n\t\t\t\t\tconst startMy =\n\t\t\t\t\t\ttouch.startMidY -\n\t\t\t\t\t\trect.top -\n\t\t\t\t\t\tlatestContainerSize.height / 2;\n\t\t\t\t\tconst panDx =\n\t\t\t\t\t\tvisSize.width > 0\n\t\t\t\t\t\t\t? ( mx - startMx ) / visSize.width\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst panDy =\n\t\t\t\t\t\tvisSize.height > 0\n\t\t\t\t\t\t\t? ( my - startMy ) / visSize.height\n\t\t\t\t\t\t\t: 0;\n\n\t\t\t\t\t// Focal-point zoom correction.\n\t\t\t\t\tconst zoomRatio = s.zoom !== 0 ? 1 - newZoom / s.zoom : 0;\n\t\t\t\t\tconst focalNormX = mx / visSize.width;\n\t\t\t\t\tconst focalNormY = my / visSize.height;\n\t\t\t\t\tconst zoomCropX =\n\t\t\t\t\t\ts.pan.x + ( focalNormX - s.pan.x ) * zoomRatio;\n\t\t\t\t\tconst zoomCropY =\n\t\t\t\t\t\ts.pan.y + ( focalNormY - s.pan.y ) * zoomRatio;\n\n\t\t\t\t\t// Combined: pan drift + zoom correction.\n\t\t\t\t\tconst newCropX =\n\t\t\t\t\t\ttouch.startPanX + panDx + ( zoomCropX - s.pan.x );\n\t\t\t\t\tconst newCropY =\n\t\t\t\t\t\ttouch.startPanY + panDy + ( zoomCropY - s.pan.y );\n\n\t\t\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...s,\n\t\t\t\t\t\t\tzoom: newZoom,\n\t\t\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\t\ts.cropRect\n\t\t\t\t\t);\n\t\t\t\t\tthis.options.actions.setZoomAtPoint( newZoom, clampedCrop );\n\t\t\t\t} else if ( newZoom !== s.zoom ) {\n\t\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\t}\n\t\t\t} else if ( moveEvent.touches.length === 1 && ! touch.didPinch ) {\n\t\t\t\t// One finger and no pinch ever detected \u2192 pan.\n\t\t\t\t// If fingers went 2\u21921 (didPinch is true), we do NOT\n\t\t\t\t// switch to pan \u2014 avoids accidental pan after releasing\n\t\t\t\t// one finger from a pinch.\n\t\t\t\tif ( ! touch.moved ) {\n\t\t\t\t\ttouch.moved = true;\n\t\t\t\t\tthis.setStatus( { isDragging: true } );\n\t\t\t\t}\n\t\t\t\tconst panImageSize = this.options.getImageSize();\n\t\t\t\tconst panContainerSize = this.options.getContainerSize();\n\t\t\t\tconst panSize = panImageSize ?? panContainerSize;\n\t\t\t\tconst deltaX =\n\t\t\t\t\tpanSize.width > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientX -\n\t\t\t\t\t\t\t\ttouch.lastTouchX ) /\n\t\t\t\t\t\t panSize.width\n\t\t\t\t\t\t: 0;\n\t\t\t\tconst deltaY =\n\t\t\t\t\tpanSize.height > 0\n\t\t\t\t\t\t? ( moveEvent.touches[ 0 ].clientY -\n\t\t\t\t\t\t\t\ttouch.lastTouchY ) /\n\t\t\t\t\t\t panSize.height\n\t\t\t\t\t\t: 0;\n\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...s,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: touch.startPanX + deltaX,\n\t\t\t\t\t\t\ty: touch.startPanY + deltaY,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( s ),\n\t\t\t\t\ts.cropRect\n\t\t\t\t);\n\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t}\n\t\t} );\n\t};\n\n\t// Handle double-tap-to-toggle-zoom. On a second tap within the configured\n\t// time/distance threshold, toggles zoom between `minZoom` and\n\t// `doubleTapZoom` around the tap point and dispatches. Returns `true` if\n\t// the tap was handled as a double-tap (caller should early-return),\n\t// `false` otherwise (caller proceeds with normal single-tap handling).\n\t// Either way, records the tap for next time.\n\tprivate tryDoubleTap(\n\t\te: TouchEvent,\n\t\ttapX: number,\n\t\ttapY: number,\n\t\tcontainerRect: DOMRect\n\t): boolean {\n\t\tconst now = Date.now();\n\t\tconst lastTap = this.lastTap;\n\t\tif ( ! lastTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\t\tconst timeDelta = now - lastTap.time;\n\t\tconst distDelta = Math.sqrt(\n\t\t\t( tapX - lastTap.x ) ** 2 + ( tapY - lastTap.y ) ** 2\n\t\t);\n\t\tconst isDoubleTap =\n\t\t\ttimeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;\n\t\tif ( ! isDoubleTap ) {\n\t\t\tthis.lastTap = { time: now, x: tapX, y: tapY };\n\t\t\treturn false;\n\t\t}\n\n\t\t// It's a double-tap \u2014 suppress browser zoom.\n\t\te.preventDefault();\n\t\tthis.lastTap = null;\n\n\t\tconst currentState = this.options.getState();\n\t\tconst containerSize = this.options.getContainerSize();\n\t\tconst imgSize = this.options.getImageSize();\n\n\t\t// Toggle: if past halfway to doubleTapZoom, go back to 1x.\n\t\tconst targetZoom =\n\t\t\tcurrentState.zoom > ( this.minZoom + this.doubleTapZoom ) / 2\n\t\t\t\t? this.minZoom\n\t\t\t\t: this.doubleTapZoom;\n\t\tconst visSize = imgSize ?? containerSize;\n\n\t\t// Enable zoom animation before dispatching.\n\t\tthis.setStatus( { isZooming: true } );\n\t\tclearTimeout( this.zoomTimer );\n\t\tthis.zoomTimer = setTimeout( () => {\n\t\t\tthis.setStatus( { isZooming: false } );\n\t\t}, ZOOM_ANIMATION_DURATION );\n\n\t\t// Double-tap bypasses the normal handleTouchStart gesture path so\n\t\t// onGestureStart/End are never called \u2014 fire them here so undo\n\t\t// receives a proper boundary around this discrete zoom action.\n\t\tthis.options.onGestureStart?.();\n\n\t\tif ( visSize.width > 0 && visSize.height > 0 ) {\n\t\t\tconst fx = tapX - containerRect.left - containerSize.width / 2;\n\t\t\tconst fy = tapY - containerRect.top - containerSize.height / 2;\n\n\t\t\tconst zoomRatio = 1 - targetZoom / currentState.zoom;\n\t\t\tconst focalNormX = fx / visSize.width;\n\t\t\tconst focalNormY = fy / visSize.height;\n\t\t\tconst newCropX =\n\t\t\t\tcurrentState.pan.x +\n\t\t\t\t( focalNormX - currentState.pan.x ) * zoomRatio;\n\t\t\tconst newCropY =\n\t\t\t\tcurrentState.pan.y +\n\t\t\t\t( focalNormY - currentState.pan.y ) * zoomRatio;\n\n\t\t\tconst { pan: clampedCrop } = restrictPanZoom(\n\t\t\t\t{\n\t\t\t\t\t...currentState,\n\t\t\t\t\tzoom: targetZoom,\n\t\t\t\t\tpan: { x: newCropX, y: newCropY },\n\t\t\t\t},\n\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\tcurrentState.cropRect\n\t\t\t);\n\t\t\tthis.options.actions.setZoomAtPoint( targetZoom, clampedCrop );\n\t\t} else {\n\t\t\tthis.options.actions.setZoom( targetZoom );\n\t\t}\n\n\t\tthis.options.onGestureEnd?.();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Handle a keydown event on the container element.\n\t *\n\t * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.\n\t *\n\t * @param e The native KeyboardEvent.\n\t */\n\thandleKeyDown( e: KeyboardEvent ): void {\n\t\tconst currentState = this.options.getState();\n\n\t\tswitch ( e.key ) {\n\t\t\tcase 'ArrowUp': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y + keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowDown': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x,\n\t\t\t\t\t\t\ty: currentState.pan.y - keyboardStep,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowLeft': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x + keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'ArrowRight': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst keyboardStep = this.getKeyboardStep( e );\n\t\t\t\tconst { pan: newCrop } = restrictPanZoom(\n\t\t\t\t\t{\n\t\t\t\t\t\t...currentState,\n\t\t\t\t\t\tpan: {\n\t\t\t\t\t\t\tx: currentState.pan.x - keyboardStep,\n\t\t\t\t\t\t\ty: currentState.pan.y,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetImageSizeFromState( currentState ),\n\t\t\t\t\tcurrentState.cropRect\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setPan( newCrop );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '+':\n\t\t\tcase '=': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom + 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase '-':\n\t\t\tcase '_': {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst newZoom = Math.min(\n\t\t\t\t\tthis.maxZoom,\n\t\t\t\t\tMath.max( this.minZoom, currentState.zoom - 0.5 )\n\t\t\t\t);\n\t\t\t\tthis.options.actions.setZoom( newZoom );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'r':\n\t\t\tcase 'R': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.snapRotate90( e.shiftKey ? -1 : 1 );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'h':\n\t\t\tcase 'H': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'horizontal' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'v':\n\t\t\tcase 'V': {\n\t\t\t\tif ( e.metaKey || e.ctrlKey || e.altKey || e.shiftKey ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\te.preventDefault();\n\t\t\t\tthis.options.actions.toggleFlip?.( 'vertical' );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clean up all timers, animation frames, and active touch listeners.\n\t *\n\t * Must be called when the controller is no longer needed (e.g., on\n\t * component unmount or element removal).\n\t */\n\tdestroy(): void {\n\t\tcancelAnimationFrame( this.rafId );\n\t\tclearTimeout( this.zoomTimer );\n\t\tclearTimeout( this.wheelGestureTimer );\n\t\tthis.touchCleanup?.();\n\t\tthis.touchCleanup = null;\n\t\tthis.pointerCleanup?.();\n\t\tthis.pointerCleanup = null;\n\t\tthis.drag = null;\n\t\tthis.touch = null;\n\t\tthis.lastTap = null;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";AAIA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,uBAAuB;AAGhC,IAAM,kBAAkB;AA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,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/core/math/sanitize.ts
|
|
2
|
+
var MAX_SAFE_MAGNITUDE = 1e6;
|
|
3
|
+
function safeBoundedNumber(value, fallback) {
|
|
4
|
+
if (!Number.isFinite(value)) {
|
|
5
|
+
return fallback;
|
|
6
|
+
}
|
|
7
|
+
if (Math.abs(value) > MAX_SAFE_MAGNITUDE) {
|
|
8
|
+
return fallback;
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function isSafeNumber(value) {
|
|
13
|
+
return Number.isFinite(value) && Math.abs(value) <= MAX_SAFE_MAGNITUDE;
|
|
14
|
+
}
|
|
15
|
+
function isValidSize(size) {
|
|
16
|
+
return Number.isFinite(size.width) && Number.isFinite(size.height) && size.width >= Number.EPSILON && size.height >= Number.EPSILON && size.width <= MAX_SAFE_MAGNITUDE && size.height <= MAX_SAFE_MAGNITUDE;
|
|
17
|
+
}
|
|
18
|
+
function sanitizeRect(rect) {
|
|
19
|
+
const x = safeBoundedNumber(rect.x, 0);
|
|
20
|
+
const y = safeBoundedNumber(rect.y, 0);
|
|
21
|
+
const width = safeBoundedNumber(rect.width, 0);
|
|
22
|
+
const height = safeBoundedNumber(rect.height, 0);
|
|
23
|
+
if (x === rect.x && y === rect.y && width === rect.width && height === rect.height) {
|
|
24
|
+
return rect;
|
|
25
|
+
}
|
|
26
|
+
return { x, y, width, height };
|
|
27
|
+
}
|
|
28
|
+
function sanitizeCropperState(state) {
|
|
29
|
+
const panX = safeBoundedNumber(state.pan.x, 0);
|
|
30
|
+
const panY = safeBoundedNumber(state.pan.y, 0);
|
|
31
|
+
const basePanX = safeBoundedNumber(state.basePan.x, 0);
|
|
32
|
+
const basePanY = safeBoundedNumber(state.basePan.y, 0);
|
|
33
|
+
const rotation = safeBoundedNumber(state.rotation, 0);
|
|
34
|
+
const baseRotation = safeBoundedNumber(state.baseRotation, 0);
|
|
35
|
+
const rawZoom = safeBoundedNumber(state.zoom, 1);
|
|
36
|
+
const zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;
|
|
37
|
+
const rawBaseZoom = safeBoundedNumber(state.baseZoom, 1);
|
|
38
|
+
const baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;
|
|
39
|
+
const cropRect = sanitizeRect(state.cropRect);
|
|
40
|
+
const panUnchanged = panX === state.pan.x && panY === state.pan.y;
|
|
41
|
+
const basePanUnchanged = basePanX === state.basePan.x && basePanY === state.basePan.y;
|
|
42
|
+
if (panUnchanged && basePanUnchanged && zoom === state.zoom && baseZoom === state.baseZoom && rotation === state.rotation && baseRotation === state.baseRotation && cropRect === state.cropRect) {
|
|
43
|
+
return state;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
...state,
|
|
47
|
+
pan: panUnchanged ? state.pan : { x: panX, y: panY },
|
|
48
|
+
zoom,
|
|
49
|
+
rotation,
|
|
50
|
+
basePan: basePanUnchanged ? state.basePan : { x: basePanX, y: basePanY },
|
|
51
|
+
baseZoom,
|
|
52
|
+
baseRotation,
|
|
53
|
+
cropRect
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
isSafeNumber,
|
|
58
|
+
isValidSize,
|
|
59
|
+
safeBoundedNumber,
|
|
60
|
+
sanitizeCropperState,
|
|
61
|
+
sanitizeRect
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=sanitize.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/image-editor/core/math/sanitize.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from '../types';\n\n/**\n * Magnitude beyond which any cropper-math input is treated as corrupt.\n * Picks a value well above any realistic image/rotation/zoom/pan but far\n * below `Number.MAX_VALUE`, so multiplications inside trig and matrix code\n * can't overflow to `Infinity`.\n */\nconst MAX_SAFE_MAGNITUDE = 1e6;\n\n/**\n * Returns `value` if it's finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`, otherwise `fallback`. Stricter than `Number.isFinite`\n * because extreme finite magnitudes (e.g. `Number.MAX_VALUE`) overflow\n * downstream trig/matrix math even though the spec reports them as finite.\n *\n * Note: sub-normal denormals (e.g. `Number.MIN_VALUE`) are accepted by this\n * function \u2014 they don't overflow on their own. Protection against divisions\n * by sub-normal values lives in `sanitizeCropperState`'s zoom guard.\n *\n * @param value The candidate value.\n * @param fallback The replacement to return when `value` is unsafe.\n * @return Either `value` or `fallback`.\n */\nexport function safeBoundedNumber( value: number, fallback: number ): number {\n\tif ( ! Number.isFinite( value ) ) {\n\t\treturn fallback;\n\t}\n\tif ( Math.abs( value ) > MAX_SAFE_MAGNITUDE ) {\n\t\treturn fallback;\n\t}\n\treturn value;\n}\n\n/**\n * Returns `true` when `value` is finite and within `[-MAX_SAFE_MAGNITUDE,\n * MAX_SAFE_MAGNITUDE]`. The predicate companion to {@link safeBoundedNumber}\n * for callers that need to short-circuit rather than substitute a fallback.\n *\n * @param value The candidate value.\n * @return Whether `value` is safe to use in math.\n */\nexport function isSafeNumber( value: number ): boolean {\n\treturn Number.isFinite( value ) && Math.abs( value ) <= MAX_SAFE_MAGNITUDE;\n}\n\n/**\n * Returns `true` when both dimensions are finite and within the safe\n * range `[Number.EPSILON, MAX_SAFE_MAGNITUDE]`. The lower bound matters\n * because sub-normal dimensions (e.g. `Number.MIN_VALUE`) pass `> 0` but\n * make `container / dim` overflow to `Infinity` downstream in\n * `getImageFit` / `createCamera`. Use this to short-circuit math that\n * would otherwise produce non-finite output.\n *\n * @param size The size to check.\n * @return Whether `size` is safe to use in math.\n */\nexport function isValidSize( size: Size ): boolean {\n\treturn (\n\t\tNumber.isFinite( size.width ) &&\n\t\tNumber.isFinite( size.height ) &&\n\t\tsize.width >= Number.EPSILON &&\n\t\tsize.height >= Number.EPSILON &&\n\t\tsize.width <= MAX_SAFE_MAGNITUDE &&\n\t\tsize.height <= MAX_SAFE_MAGNITUDE\n\t);\n}\n\n/**\n * Returns a copy of `rect` with every numeric field replaced by a safe\n * value via {@link safeBoundedNumber}. Returns the same reference when no\n * field needed substitution so callers can keep their reference-equality\n * short-circuits intact for clean inputs.\n *\n * @param rect The rect to sanitize.\n * @return A rect with all numeric fields finite.\n */\nexport function sanitizeRect( rect: NormalizedRect ): NormalizedRect {\n\tconst x = safeBoundedNumber( rect.x, 0 );\n\tconst y = safeBoundedNumber( rect.y, 0 );\n\tconst width = safeBoundedNumber( rect.width, 0 );\n\tconst height = safeBoundedNumber( rect.height, 0 );\n\tif (\n\t\tx === rect.x &&\n\t\ty === rect.y &&\n\t\twidth === rect.width &&\n\t\theight === rect.height\n\t) {\n\t\treturn rect;\n\t}\n\treturn { x, y, width, height };\n}\n\n/**\n * Returns a copy of `state` with the cropper-math numeric fields replaced\n * by safe defaults. Covers `pan`, `zoom`, `rotation`, the matching base\n * pose, and `cropRect`. The `state.image` numeric fields (naturalWidth /\n * naturalHeight) are intentionally NOT sanitized \u2014 image dimensions reach\n * the math layer as a separate `imageSize` argument, and cloning the\n * image object here would break the reducer's reference-equality\n * short-circuit.\n *\n * Returns the same `state` reference when no field needed substitution\n * so callers in hot paths (every pointermove via `restrictPanZoom`) can\n * keep their reference-equality optimizations. Sub-object references\n * (`pan`, `basePan`, `cropRect`) are also preserved when their fields\n * are individually clean.\n *\n * @param state The cropper state to sanitize.\n * @return A cropper state with the math-relevant numeric fields finite.\n */\nexport function sanitizeCropperState( state: CropperState ): CropperState {\n\tconst panX = safeBoundedNumber( state.pan.x, 0 );\n\tconst panY = safeBoundedNumber( state.pan.y, 0 );\n\tconst basePanX = safeBoundedNumber( state.basePan.x, 0 );\n\tconst basePanY = safeBoundedNumber( state.basePan.y, 0 );\n\tconst rotation = safeBoundedNumber( state.rotation, 0 );\n\tconst baseRotation = safeBoundedNumber( state.baseRotation, 0 );\n\tconst rawZoom = safeBoundedNumber( state.zoom, 1 );\n\t// Zoom must be strictly positive AND large enough that 1/zoom doesn't\n\t// overflow. Sub-normals (e.g. Number.MIN_VALUE) pass `> 0` but make\n\t// division explode, so guard against them with Number.EPSILON.\n\tconst zoom = rawZoom >= Number.EPSILON ? rawZoom : 1;\n\tconst rawBaseZoom = safeBoundedNumber( state.baseZoom, 1 );\n\tconst baseZoom = rawBaseZoom >= Number.EPSILON ? rawBaseZoom : 1;\n\tconst cropRect = sanitizeRect( state.cropRect );\n\n\tconst panUnchanged = panX === state.pan.x && panY === state.pan.y;\n\tconst basePanUnchanged =\n\t\tbasePanX === state.basePan.x && basePanY === state.basePan.y;\n\n\tif (\n\t\tpanUnchanged &&\n\t\tbasePanUnchanged &&\n\t\tzoom === state.zoom &&\n\t\tbaseZoom === state.baseZoom &&\n\t\trotation === state.rotation &&\n\t\tbaseRotation === state.baseRotation &&\n\t\tcropRect === state.cropRect\n\t) {\n\t\treturn state;\n\t}\n\treturn {\n\t\t...state,\n\t\tpan: panUnchanged ? state.pan : { x: panX, y: panY },\n\t\tzoom,\n\t\trotation,\n\t\tbasePan: basePanUnchanged\n\t\t\t? state.basePan\n\t\t\t: { x: basePanX, y: basePanY },\n\t\tbaseZoom,\n\t\tbaseRotation,\n\t\tcropRect,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAWA,IAAM,qBAAqB;AAgBpB,SAAS,kBAAmB,OAAe,UAA2B;AAC5E,MAAK,CAAE,OAAO,SAAU,KAAM,GAAI;AACjC,WAAO;AAAA,EACR;AACA,MAAK,KAAK,IAAK,KAAM,IAAI,oBAAqB;AAC7C,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAUO,SAAS,aAAc,OAAyB;AACtD,SAAO,OAAO,SAAU,KAAM,KAAK,KAAK,IAAK,KAAM,KAAK;AACzD;AAa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,QACf,aAAa,MAAM,YACnB,aAAa,MAAM,YACnB,iBAAiB,MAAM,gBACvB,aAAa,MAAM,UAClB;AACD,WAAO;AAAA,EACR;AACA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,KAAK,eAAe,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,KAAK;AAAA,IACnD;AAAA,IACA;AAAA,IACA,SAAS,mBACN,MAAM,UACN,EAAE,GAAG,UAAU,GAAG,SAAS;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/core/setter-helpers.ts
|
|
2
|
+
import { MAX_ZOOM } from "./constants.mjs";
|
|
3
|
+
import { getMinZoom, restrictPanZoom } from "./containment.mjs";
|
|
4
|
+
function buildFocalPointZoomAction(state, requestedZoom) {
|
|
5
|
+
const clampedZoom = Math.min(
|
|
6
|
+
MAX_ZOOM,
|
|
7
|
+
Math.max(getMinZoom(state), requestedZoom)
|
|
8
|
+
);
|
|
9
|
+
if (clampedZoom === state.zoom) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const { cropRect } = state;
|
|
13
|
+
const focalNormX = cropRect.x + cropRect.width / 2 - 0.5;
|
|
14
|
+
const focalNormY = cropRect.y + cropRect.height / 2 - 0.5;
|
|
15
|
+
const zoomRatio = 1 - clampedZoom / state.zoom;
|
|
16
|
+
const newPanX = state.pan.x + (focalNormX - state.pan.x) * zoomRatio;
|
|
17
|
+
const newPanY = state.pan.y + (focalNormY - state.pan.y) * zoomRatio;
|
|
18
|
+
const imageSize = state.image ? {
|
|
19
|
+
width: state.image.naturalWidth,
|
|
20
|
+
height: state.image.naturalHeight
|
|
21
|
+
} : { width: 1, height: 1 };
|
|
22
|
+
const { pan: clampedPan } = restrictPanZoom(
|
|
23
|
+
{
|
|
24
|
+
...state,
|
|
25
|
+
zoom: clampedZoom,
|
|
26
|
+
pan: { x: newPanX, y: newPanY }
|
|
27
|
+
},
|
|
28
|
+
imageSize,
|
|
29
|
+
state.cropRect
|
|
30
|
+
);
|
|
31
|
+
return {
|
|
32
|
+
type: "SET_ZOOM_AT_POINT",
|
|
33
|
+
payload: { zoom: clampedZoom, pan: clampedPan }
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
buildFocalPointZoomAction
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=setter-helpers.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/image-editor/core/setter-helpers.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom \u2014 zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperReducer` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0\u20131), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t }\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAS,gBAAgB;AACzB,SAAS,YAAY,uBAAuB;AAoBrC,SAAS,0BACf,OACA,eACuB;AACvB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,IACA,KAAK,IAAK,WAAY,KAAM,GAAG,aAAc;AAAA,EAC9C;AACA,MAAK,gBAAgB,MAAM,MAAO;AACjC,WAAO;AAAA,EACR;AAKA,QAAM,EAAE,SAAS,IAAI;AACrB,QAAM,aAAa,SAAS,IAAI,SAAS,QAAQ,IAAI;AACrD,QAAM,aAAa,SAAS,IAAI,SAAS,SAAS,IAAI;AACtD,QAAM,YAAY,IAAI,cAAc,MAAM;AAC1C,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,YAA+C,MAAM,QACxD;AAAA,IACA,OAAO,MAAM,MAAM;AAAA,IACnB,QAAQ,MAAM,MAAM;AAAA,EACpB,IACA,EAAE,OAAO,GAAG,QAAQ,EAAE;AACzB,QAAM,EAAE,KAAK,WAAW,IAA8B;AAAA,IACrD;AAAA,MACC,GAAG;AAAA,MACH,MAAM;AAAA,MACN,KAAK,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,MAAM;AAAA,EACP;AACA,SAAO;AAAA,IACN,MAAM;AAAA,IACN,SAAS,EAAE,MAAM,aAAa,KAAK,WAAW;AAAA,EAC/C;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|