@wordpress/media-editor 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/build/components/media-editor/index.cjs +54 -44
- package/build/components/media-editor/index.cjs.map +2 -2
- package/build/components/media-editor/use-crop-options.cjs.map +2 -2
- package/build/components/media-editor/use-save-media-editor.cjs.map +2 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
- package/build/components/media-editor-image-controls/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
- package/build/components/media-editor-modal/build-modifiers.cjs.map +2 -2
- package/build/components/media-editor-modal/index.cjs.map +2 -2
- package/build/components/media-editor-provider/index.cjs.map +2 -2
- package/build/components/media-form/index.cjs.map +2 -2
- package/build/components/media-preview/index.cjs.map +2 -2
- package/build/components/rotation-ruler/index.cjs.map +2 -2
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +2 -2
- package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/crop-rect.cjs.map +2 -2
- package/build/image-editor/core/export/canvas-renderer.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs.map +2 -2
- package/build/image-editor/core/setter-helpers.cjs.map +2 -2
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs.map +2 -2
- package/build/image-editor/core/transforms/pipeline.cjs.map +2 -2
- package/build/image-editor/core/viewport-state.cjs.map +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/components/viewport-provider.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +2 -2
- package/build/lock-unlock.cjs.map +2 -2
- package/build/private-apis.cjs.map +2 -2
- package/build/state/composite-reducer.cjs.map +2 -2
- package/build/state/media-editor-state-provider.cjs.map +2 -2
- package/build/state/types.cjs.map +2 -2
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build/store/index.cjs.map +2 -2
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +54 -45
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs.map +2 -2
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +2 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +2 -2
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-provider/index.mjs.map +2 -2
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/media-preview/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +2 -2
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/crop-rect.mjs.map +2 -2
- package/build-module/image-editor/core/export/canvas-renderer.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.map +2 -2
- package/build-module/image-editor/core/setter-helpers.mjs.map +2 -2
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +2 -2
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +2 -2
- package/build-module/image-editor/core/viewport-state.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +2 -2
- package/build-module/lock-unlock.mjs.map +2 -2
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/state/composite-reducer.mjs.map +2 -2
- package/build-module/state/media-editor-state-provider.mjs.map +2 -2
- package/build-module/state/types.mjs.map +2 -2
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-module/store/index.mjs.map +2 -2
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-style/style-rtl.css +2 -2
- package/build-style/style.css +2 -2
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts +0 -3
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -3
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/stories/index.story.d.ts +0 -6
- package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts +0 -3
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -3
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +0 -3
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -3
- package/build-types/image-editor/core/crop-rect.d.ts.map +1 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -3
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -3
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -3
- package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -3
- package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -3
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts +0 -3
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -3
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -3
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -3
- package/build-types/image-editor/core/viewport-state.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -3
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -6
- 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 +0 -3
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -3
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -3
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -3
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -3
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -3
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -3
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -3
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -3
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -3
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -3
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -1
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +0 -6
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +0 -3
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/media-editor-state-provider.d.ts +0 -3
- package/build-types/state/media-editor-state-provider.d.ts.map +1 -1
- package/build-types/state/types.d.ts +0 -3
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +0 -3
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/store/index.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +0 -3
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +0 -3
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/components/media-editor/index.tsx +83 -78
- package/src/components/media-editor/test/use-crop-options.tsx +0 -7
- package/src/components/media-editor/use-crop-options.ts +0 -7
- package/src/components/media-editor/use-save-media-editor.ts +0 -7
- package/src/components/media-editor-canvas/index.tsx +0 -11
- package/src/components/media-editor-crop-panel/index.tsx +0 -7
- package/src/components/media-editor-crop-panel/test/index.tsx +0 -7
- package/src/components/media-editor-fine-rotation/index.tsx +0 -7
- package/src/components/media-editor-image-controls/index.tsx +0 -7
- package/src/components/media-editor-image-controls/test/index.tsx +0 -7
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +0 -3
- package/src/components/media-editor-modal/build-modifiers.ts +0 -3
- package/src/components/media-editor-modal/index.tsx +0 -7
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -8
- package/src/components/media-editor-modal/test/index.tsx +0 -11
- package/src/components/media-editor-provider/index.tsx +0 -3
- package/src/components/media-form/index.tsx +0 -7
- package/src/components/media-preview/index.tsx +0 -7
- package/src/components/rotation-ruler/index.tsx +0 -11
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -11
- package/src/components/rotation-ruler/test/index.tsx +0 -7
- package/src/components/rotation-ruler/use-ruler-drag.ts +0 -3
- package/src/hooks/use-crop-gesture-handlers.ts +0 -7
- package/src/image-editor/core/camera.ts +0 -7
- package/src/image-editor/core/constants.ts +0 -7
- package/src/image-editor/core/containment.ts +0 -7
- package/src/image-editor/core/crop-rect.ts +0 -3
- package/src/image-editor/core/export/canvas-renderer.ts +0 -3
- package/src/image-editor/core/export/test/canvas-renderer.ts +0 -3
- package/src/image-editor/core/interaction-controller.ts +0 -3
- package/src/image-editor/core/math/sanitize.ts +0 -3
- package/src/image-editor/core/math/test/sanitize.ts +0 -3
- package/src/image-editor/core/setter-helpers.ts +0 -3
- package/src/image-editor/core/source-region.ts +0 -7
- package/src/image-editor/core/state.ts +0 -3
- package/src/image-editor/core/stencil-math.ts +0 -3
- package/src/image-editor/core/test/interaction-controller.ts +0 -3
- package/src/image-editor/core/test/preview-export-parity.ts +0 -1
- package/src/image-editor/core/test/stencil-math.ts +0 -3
- package/src/image-editor/core/transform-style.ts +0 -3
- package/src/image-editor/core/transforms/pipeline.ts +0 -3
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -3
- package/src/image-editor/core/viewport-state.ts +0 -3
- package/src/image-editor/react/components/cropper-provider.tsx +0 -7
- package/src/image-editor/react/components/cropper.tsx +0 -12
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -7
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -3
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -3
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -7
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +0 -7
- package/src/image-editor/react/components/test/cropper.tsx +0 -7
- package/src/image-editor/react/components/viewport-provider.tsx +0 -7
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -3
- package/src/image-editor/react/hooks/test/use-aria-announcer.ts +0 -11
- package/src/image-editor/react/hooks/test/use-cropper-reducer.ts +0 -7
- package/src/image-editor/react/hooks/test/use-interaction.ts +0 -7
- package/src/image-editor/react/hooks/test/use-transform-style.ts +0 -7
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -7
- package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -7
- package/src/image-editor/react/hooks/use-interaction.ts +0 -7
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -7
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -7
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -11
- package/src/lock-unlock.ts +0 -3
- package/src/private-apis.ts +0 -3
- package/src/state/composite-reducer.ts +0 -3
- package/src/state/media-editor-state-provider.tsx +0 -7
- package/src/state/test/use-media-editor-state.ts +0 -7
- package/src/state/types.ts +0 -3
- package/src/state/use-media-editor-state.ts +0 -7
- package/src/store/index.ts +0 -7
- package/src/store/reducer.ts +0 -3
- package/src/store/selectors.ts +0 -3
- package/src/store/test/reducer.ts +0 -3
- package/tsconfig.tsbuildinfo +1 -1
- 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/components/media-editor-transform-controls/index.d.ts +0 -21
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -108
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/camera.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tCamera,\n} from './types';\nimport { degreesToRadians } from './math/rotation';\nimport {\n\tisSafeNumber,\n\tisValidSize,\n\tsafeBoundedNumber,\n\tsanitizeCropperState,\n} from './math/sanitize';\n\n// Pre-allocated scratch buffers for `screenToWorld`, which is called per\n// pointermove. Module-level singletons — safe because usage is synchronous.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Compute the axis-aligned bounding box of a rectangle after rotation.\n *\n * @param width The width of the rectangle.\n * @param height The height of the rectangle.\n * @param rotation The rotation angle in degrees.\n * @return The bounding box size after rotation.\n */\nexport function getRotatedBBox(\n\twidth: number,\n\theight: number,\n\trotation: number\n): Size {\n\t// Short-circuit on any unsafe input. `isSafeNumber` is stricter than\n\t// `Number.isFinite`: very large but technically-finite rotations (e.g.\n\t// `Number.MAX_VALUE`) overflow inside `degreesToRadians` and then\n\t// `Math.cos`/`Math.sin` return `NaN`, so the magnitude bound matters.\n\tif (\n\t\t! isSafeNumber( width ) ||\n\t\t! isSafeNumber( height ) ||\n\t\t! isSafeNumber( rotation ) ||\n\t\twidth <= 0 ||\n\t\theight <= 0\n\t) {\n\t\treturn { width: 0, height: 0 };\n\t}\n\tconst rad = degreesToRadians( rotation );\n\tconst cosR = Math.abs( Math.cos( rad ) );\n\tconst sinR = Math.abs( Math.sin( rad ) );\n\treturn {\n\t\twidth: cosR * width + sinR * height,\n\t\theight: sinR * width + cosR * height,\n\t};\n}\n\n/**\n * Compute the fitted (unrotated) image element dimensions and the visual\n * (rotated) bounding box dimensions for a given container, image, and rotation.\n *\n * This is the same \"contain\" fit logic used by createCamera, extracted so\n * cropper.tsx can size the <img> element and position overlays without\n * duplicating the math.\n *\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The natural image dimensions in pixels.\n * @param rotation The rotation angle in degrees.\n * @return The fitted element size and visual bounding box size.\n */\nexport function getImageFit(\n\tcontainerSize: Size,\n\timageSize: Size,\n\trotation: number\n): { elementSize: Size; visualSize: Size } {\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst safeRotation = safeBoundedNumber( rotation, 0 );\n\t// Snap rotation to the nearest 90° multiple for layout sizing.\n\t// This keeps the stencil a stable size through fine ±45° rotation\n\t// (no inflation at 15°/30° etc.) while still swapping aspect at\n\t// 90°/180°/270° so the snap rotate preserves the framed content.\n\tconst snapRotation = Math.round( safeRotation / 90 ) * 90;\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\t// Defensive: getRotatedBBox returns zero dims for hostile inputs, which\n\t// would make fitScale infinite. Mirror the zero-container short-circuit.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\tconst visualSize = getRotatedBBox( renderedW, renderedH, snapRotation );\n\treturn {\n\t\telementSize: { width: renderedW, height: renderedH },\n\t\tvisualSize,\n\t};\n}\n\n/**\n * Resolve the presentational view magnification that makes the crop fill the\n * canvas.\n *\n * The crop overlay is laid out as `cropRect * visualSize` (the contain-fit\n * footprint, with no zoom), so its on-screen size is capped by that footprint.\n * When a crop's aspect differs from the image's, it can be much smaller than\n * the canvas could show (e.g. a square crop in a tall image is bound by the\n * footprint's narrow axis). Scaling `elementSize` and `visualSize` together by\n * the returned factor uniformly magnifies the whole scene — image, crop\n * overlay, and overlays — so the crop reaches `targetFill` of its constraining\n * canvas axis, with the image bleeding past the canvas (clipped by the host).\n *\n * Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,\n * so the framed source region — and therefore the export — is unchanged.\n *\n * @param cropRect The crop rectangle, normalized to the footprint.\n * @param canvasSize The canvas size in pixels.\n * @param visualSize The contain-fit (rotated) image footprint in pixels.\n * @param targetFill Fraction of the constraining canvas axis to fill (0–1].\n * @param maxScale Upper bound on the magnification.\n * @return A magnification factor in [1, maxScale]; 1 when none is needed.\n */\nexport function getViewScale(\n\tcropRect: NormalizedRect,\n\tcanvasSize: Size,\n\tvisualSize: Size,\n\ttargetFill: number,\n\tmaxScale: number\n): number {\n\tconst cropScreenW = cropRect.width * visualSize.width;\n\tconst cropScreenH = cropRect.height * visualSize.height;\n\t// `> 0` comparisons (rather than `<= 0`) reject NaN as well as zero and\n\t// negatives, so a non-finite rect/dimension/scale can't propagate to a\n\t// `scale(NaN)`. `isValidSize` already guards finiteness of the sizes.\n\tif (\n\t\t! isValidSize( canvasSize ) ||\n\t\t! isValidSize( visualSize ) ||\n\t\t! ( cropScreenW > 0 ) ||\n\t\t! ( cropScreenH > 0 ) ||\n\t\t! Number.isFinite( targetFill ) ||\n\t\t! Number.isFinite( maxScale ) ||\n\t\t! ( targetFill > 0 ) ||\n\t\t! ( maxScale >= 1 )\n\t) {\n\t\treturn 1;\n\t}\n\tconst kW = ( targetFill * canvasSize.width ) / cropScreenW;\n\tconst kH = ( targetFill * canvasSize.height ) / cropScreenH;\n\tconst k = Math.min( kW, kH );\n\treturn Math.min( maxScale, Math.max( 1, k ) );\n}\n\n/**\n * Compose a camera matrix from cropper state, container, and image dimensions.\n *\n * The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.\n * Input (0,0) = image top-left, (1,1) = image bottom-right.\n *\n * Composition order (left-to-right = outermost first, applied last to point):\n * M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels\n *\n * Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`\n * are viewport-relative: the image mirrors across the viewport's vertical /\n * horizontal axis regardless of current rotation.\n *\n * @param state The current cropper state (zoom, rotation, flip, crop).\n * @param containerSize The size of the container in pixels.\n * @param imageSize The natural size of the image in pixels.\n * @return The composed camera matrix.\n */\nexport function createCamera(\n\tstate: CropperState,\n\tcontainerSize: Size,\n\timageSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn m;\n\t}\n\n\tconst safeState = sanitizeCropperState( state );\n\n\t// Use the nearest 90° multiple for layout sizing so the stencil\n\t// and visual bounds are stable through fine rotation. The actual\n\t// `state.rotation` is still used for the rotation component of\n\t// the matrix below.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\n\t// Rotated bounding box of the natural image (at snap angle).\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Defensive: getRotatedBBox returns zero dims for unsafe inputs. Mirror\n\t// the zero-size short-circuit so `fitScale` doesn't become Infinity.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn m;\n\t}\n\n\t// \"Contain\" fit: scale rotated bounding box to fit within container.\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\n\t// The rendered (unrotated) image dimensions at this fit scale.\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\n\t// Visual (rotated) image footprint in pixels (at snap angle).\n\tconst { width: visualW, height: visualH } = getRotatedBBox(\n\t\trenderedW,\n\t\trenderedH,\n\t\tsnapRotation\n\t);\n\n\t// Build matrix left-to-right (outermost first).\n\t// Innermost operations (last in code) are applied first to input point.\n\n\t// Outermost: translate to container center.\n\tmat2d.translate( m, m, [\n\t\tcontainerSize.width / 2,\n\t\tcontainerSize.height / 2,\n\t] );\n\n\t// Pan offset in visual-space pixels.\n\tmat2d.translate( m, m, [\n\t\tsafeState.pan.x * visualW,\n\t\tsafeState.pan.y * visualH,\n\t] );\n\n\t// Flip (viewport-relative — composed outside rotation so horizontal\n\t// flip always mirrors across the viewport's vertical axis).\n\tmat2d.scale( m, m, [\n\t\tsafeState.flip.horizontal ? -1 : 1,\n\t\tsafeState.flip.vertical ? -1 : 1,\n\t] );\n\n\t// Rotate.\n\tmat2d.rotate( m, m, degreesToRadians( safeState.rotation ) );\n\n\t// Zoom.\n\tmat2d.scale( m, m, [ safeState.zoom, safeState.zoom ] );\n\n\t// Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).\n\tmat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );\n\n\t// Innermost: scale from normalized [0,1] to rendered pixels.\n\tmat2d.scale( m, m, [ renderedW, renderedH ] );\n\n\treturn m;\n}\n\n/**\n * Transform a normalized world point [0,1] to screen pixels.\n *\n * @param camera The camera matrix from createCamera.\n * @param point The normalized world coordinate to transform.\n * @return The screen pixel coordinate.\n */\nexport function worldToScreen(\n\tcamera: Camera,\n\tpoint: NormalizedPoint\n): { x: number; y: number } {\n\tconst out = vec2.create();\n\tvec2.transformMat2d( out, [ point.x, point.y ], camera );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * Transform a screen pixel point to normalized world coordinates [0,1].\n *\n * @param camera The camera matrix from createCamera.\n * @param point The screen pixel coordinate to transform.\n * @param point.x The x component of the screen pixel coordinate.\n * @param point.y The y component of the screen pixel coordinate.\n * @return The normalized world coordinate.\n */\nexport function screenToWorld(\n\tcamera: Camera,\n\tpoint: { x: number; y: number }\n): NormalizedPoint {\n\tmat2d.invert( _scratchMat, camera );\n\tconst out = _scratchVec;\n\tvec2.transformMat2d( out, [ point.x, point.y ], _scratchMat );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * The bounding box of a transformed region in screen (pixel) space.\n */\nexport interface VisualBounds {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Compute the axis-aligned bounding box of a set of corners after\n * transforming them through a camera matrix.\n *\n * @param camera The camera matrix from createCamera.\n * @param corners The corners to transform (each as [x, y]).\n * @return The screen-space bounding box.\n */\nfunction aabb( camera: Camera, corners: [ number, number ][] ): VisualBounds {\n\tconst screenCorners = corners.map( ( c ) => {\n\t\tconst out = vec2.create();\n\t\tvec2.transformMat2d( out, c, camera );\n\t\treturn out;\n\t} );\n\tlet minX = screenCorners[ 0 ][ 0 ];\n\tlet maxX = screenCorners[ 0 ][ 0 ];\n\tlet minY = screenCorners[ 0 ][ 1 ];\n\tlet maxY = screenCorners[ 0 ][ 1 ];\n\tfor ( let i = 1; i < screenCorners.length; i++ ) {\n\t\tconst s = screenCorners[ i ];\n\t\tif ( s[ 0 ] < minX ) {\n\t\t\tminX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 0 ] > maxX ) {\n\t\t\tmaxX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 1 ] < minY ) {\n\t\t\tminY = s[ 1 ];\n\t\t}\n\t\tif ( s[ 1 ] > maxY ) {\n\t\t\tmaxY = s[ 1 ];\n\t\t}\n\t}\n\treturn { left: minX, top: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/**\n * Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])\n * after applying the camera transform.\n *\n * @param camera The camera matrix from createCamera.\n * @return The screen-space bounding box of the full image.\n */\nexport function getVisibleBounds( camera: Camera ): VisualBounds {\n\treturn aabb( camera, [\n\t\t[ 0, 0 ],\n\t\t[ 1, 0 ],\n\t\t[ 1, 1 ],\n\t\t[ 0, 1 ],\n\t] );\n}\n\n/**\n * Compose a camera matrix for exporting to a canvas.\n *\n * The resulting matrix maps image-pixel coordinates directly to output-canvas\n * coordinates. Apply it with `ctx.setTransform( ...camera )` then\n * `ctx.drawImage( image, 0, 0 )`.\n *\n * The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:\n * translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the source image in pixels.\n * @param outputSize The desired output canvas size in pixels.\n * @return The composed export camera matrix.\n */\nexport function createExportCamera(\n\tstate: CropperState,\n\timageSize: Size,\n\toutputSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\tif ( ! isValidSize( imageSize ) || ! isValidSize( outputSize ) ) {\n\t\treturn m;\n\t}\n\tconst { rotation, flip, cropRect, zoom, pan } =\n\t\tsanitizeCropperState( state );\n\t// Reference frame for cropRect/pan is the snap-rotation bbox — that's\n\t// what the stencil and CSS matrix use in the preview (see createCamera\n\t// and getImageFit). Using the true rotation here would position the\n\t// crop window at a different offset than the stencil framed, and show\n\t// a shifted region after any fine rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { width: rotW, height: rotH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Scale factor to map the natural crop region to the output canvas size.\n\tconst naturalCropW = cropRect.width * rotW;\n\tconst naturalCropH = cropRect.height * rotH;\n\tconst outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;\n\tconst outputScaleY =\n\t\tnaturalCropH > 0 ? outputSize.height / naturalCropH : 1;\n\n\tconst cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;\n\tconst cropOffsetY =\n\t\tcropRect.y * rotH + outputSize.height / 2 / outputScaleY;\n\tconst visualCenterX = rotW / 2 + pan.x * rotW;\n\tconst visualCenterY = rotH / 2 + pan.y * rotH;\n\tmat2d.scale( m, m, [ outputScaleX, outputScaleY ] );\n\tmat2d.translate( m, m, [\n\t\tvisualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,\n\t\tvisualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY,\n\t] );\n\t// Flip is composed outside rotation so it acts in viewport/output space —\n\t// must match createCamera's order for preview and export to agree.\n\tmat2d.scale( m, m, [ flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1 ] );\n\tmat2d.rotate( m, m, degreesToRadians( rotation ) );\n\tmat2d.scale( m, m, [ zoom, zoom ] );\n\tmat2d.translate( m, m, [ -imageSize.width / 2, -imageSize.height / 2 ] );\n\treturn m;\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import { mat2d, vec2 } from 'gl-matrix';\nimport type {\n\tCropperState,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tCamera,\n} from './types';\nimport { degreesToRadians } from './math/rotation';\nimport {\n\tisSafeNumber,\n\tisValidSize,\n\tsafeBoundedNumber,\n\tsanitizeCropperState,\n} from './math/sanitize';\n\n// Pre-allocated scratch buffers for `screenToWorld`, which is called per\n// pointermove. Module-level singletons — safe because usage is synchronous.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Compute the axis-aligned bounding box of a rectangle after rotation.\n *\n * @param width The width of the rectangle.\n * @param height The height of the rectangle.\n * @param rotation The rotation angle in degrees.\n * @return The bounding box size after rotation.\n */\nexport function getRotatedBBox(\n\twidth: number,\n\theight: number,\n\trotation: number\n): Size {\n\t// Short-circuit on any unsafe input. `isSafeNumber` is stricter than\n\t// `Number.isFinite`: very large but technically-finite rotations (e.g.\n\t// `Number.MAX_VALUE`) overflow inside `degreesToRadians` and then\n\t// `Math.cos`/`Math.sin` return `NaN`, so the magnitude bound matters.\n\tif (\n\t\t! isSafeNumber( width ) ||\n\t\t! isSafeNumber( height ) ||\n\t\t! isSafeNumber( rotation ) ||\n\t\twidth <= 0 ||\n\t\theight <= 0\n\t) {\n\t\treturn { width: 0, height: 0 };\n\t}\n\tconst rad = degreesToRadians( rotation );\n\tconst cosR = Math.abs( Math.cos( rad ) );\n\tconst sinR = Math.abs( Math.sin( rad ) );\n\treturn {\n\t\twidth: cosR * width + sinR * height,\n\t\theight: sinR * width + cosR * height,\n\t};\n}\n\n/**\n * Compute the fitted (unrotated) image element dimensions and the visual\n * (rotated) bounding box dimensions for a given container, image, and rotation.\n *\n * This is the same \"contain\" fit logic used by createCamera, extracted so\n * cropper.tsx can size the <img> element and position overlays without\n * duplicating the math.\n *\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The natural image dimensions in pixels.\n * @param rotation The rotation angle in degrees.\n * @return The fitted element size and visual bounding box size.\n */\nexport function getImageFit(\n\tcontainerSize: Size,\n\timageSize: Size,\n\trotation: number\n): { elementSize: Size; visualSize: Size } {\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst safeRotation = safeBoundedNumber( rotation, 0 );\n\t// Snap rotation to the nearest 90° multiple for layout sizing.\n\t// This keeps the stencil a stable size through fine ±45° rotation\n\t// (no inflation at 15°/30° etc.) while still swapping aspect at\n\t// 90°/180°/270° so the snap rotate preserves the framed content.\n\tconst snapRotation = Math.round( safeRotation / 90 ) * 90;\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\t// Defensive: getRotatedBBox returns zero dims for hostile inputs, which\n\t// would make fitScale infinite. Mirror the zero-container short-circuit.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\tconst visualSize = getRotatedBBox( renderedW, renderedH, snapRotation );\n\treturn {\n\t\telementSize: { width: renderedW, height: renderedH },\n\t\tvisualSize,\n\t};\n}\n\n/**\n * Resolve the presentational view magnification that makes the crop fill the\n * canvas.\n *\n * The crop overlay is laid out as `cropRect * visualSize` (the contain-fit\n * footprint, with no zoom), so its on-screen size is capped by that footprint.\n * When a crop's aspect differs from the image's, it can be much smaller than\n * the canvas could show (e.g. a square crop in a tall image is bound by the\n * footprint's narrow axis). Scaling `elementSize` and `visualSize` together by\n * the returned factor uniformly magnifies the whole scene — image, crop\n * overlay, and overlays — so the crop reaches `targetFill` of its constraining\n * canvas axis, with the image bleeding past the canvas (clipped by the host).\n *\n * Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,\n * so the framed source region — and therefore the export — is unchanged.\n *\n * @param cropRect The crop rectangle, normalized to the footprint.\n * @param canvasSize The canvas size in pixels.\n * @param visualSize The contain-fit (rotated) image footprint in pixels.\n * @param targetFill Fraction of the constraining canvas axis to fill (0–1].\n * @param maxScale Upper bound on the magnification.\n * @return A magnification factor in [1, maxScale]; 1 when none is needed.\n */\nexport function getViewScale(\n\tcropRect: NormalizedRect,\n\tcanvasSize: Size,\n\tvisualSize: Size,\n\ttargetFill: number,\n\tmaxScale: number\n): number {\n\tconst cropScreenW = cropRect.width * visualSize.width;\n\tconst cropScreenH = cropRect.height * visualSize.height;\n\t// `> 0` comparisons (rather than `<= 0`) reject NaN as well as zero and\n\t// negatives, so a non-finite rect/dimension/scale can't propagate to a\n\t// `scale(NaN)`. `isValidSize` already guards finiteness of the sizes.\n\tif (\n\t\t! isValidSize( canvasSize ) ||\n\t\t! isValidSize( visualSize ) ||\n\t\t! ( cropScreenW > 0 ) ||\n\t\t! ( cropScreenH > 0 ) ||\n\t\t! Number.isFinite( targetFill ) ||\n\t\t! Number.isFinite( maxScale ) ||\n\t\t! ( targetFill > 0 ) ||\n\t\t! ( maxScale >= 1 )\n\t) {\n\t\treturn 1;\n\t}\n\tconst kW = ( targetFill * canvasSize.width ) / cropScreenW;\n\tconst kH = ( targetFill * canvasSize.height ) / cropScreenH;\n\tconst k = Math.min( kW, kH );\n\treturn Math.min( maxScale, Math.max( 1, k ) );\n}\n\n/**\n * Compose a camera matrix from cropper state, container, and image dimensions.\n *\n * The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.\n * Input (0,0) = image top-left, (1,1) = image bottom-right.\n *\n * Composition order (left-to-right = outermost first, applied last to point):\n * M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels\n *\n * Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`\n * are viewport-relative: the image mirrors across the viewport's vertical /\n * horizontal axis regardless of current rotation.\n *\n * @param state The current cropper state (zoom, rotation, flip, crop).\n * @param containerSize The size of the container in pixels.\n * @param imageSize The natural size of the image in pixels.\n * @return The composed camera matrix.\n */\nexport function createCamera(\n\tstate: CropperState,\n\tcontainerSize: Size,\n\timageSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn m;\n\t}\n\n\tconst safeState = sanitizeCropperState( state );\n\n\t// Use the nearest 90° multiple for layout sizing so the stencil\n\t// and visual bounds are stable through fine rotation. The actual\n\t// `state.rotation` is still used for the rotation component of\n\t// the matrix below.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\n\t// Rotated bounding box of the natural image (at snap angle).\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Defensive: getRotatedBBox returns zero dims for unsafe inputs. Mirror\n\t// the zero-size short-circuit so `fitScale` doesn't become Infinity.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn m;\n\t}\n\n\t// \"Contain\" fit: scale rotated bounding box to fit within container.\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\n\t// The rendered (unrotated) image dimensions at this fit scale.\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\n\t// Visual (rotated) image footprint in pixels (at snap angle).\n\tconst { width: visualW, height: visualH } = getRotatedBBox(\n\t\trenderedW,\n\t\trenderedH,\n\t\tsnapRotation\n\t);\n\n\t// Build matrix left-to-right (outermost first).\n\t// Innermost operations (last in code) are applied first to input point.\n\n\t// Outermost: translate to container center.\n\tmat2d.translate( m, m, [\n\t\tcontainerSize.width / 2,\n\t\tcontainerSize.height / 2,\n\t] );\n\n\t// Pan offset in visual-space pixels.\n\tmat2d.translate( m, m, [\n\t\tsafeState.pan.x * visualW,\n\t\tsafeState.pan.y * visualH,\n\t] );\n\n\t// Flip (viewport-relative — composed outside rotation so horizontal\n\t// flip always mirrors across the viewport's vertical axis).\n\tmat2d.scale( m, m, [\n\t\tsafeState.flip.horizontal ? -1 : 1,\n\t\tsafeState.flip.vertical ? -1 : 1,\n\t] );\n\n\t// Rotate.\n\tmat2d.rotate( m, m, degreesToRadians( safeState.rotation ) );\n\n\t// Zoom.\n\tmat2d.scale( m, m, [ safeState.zoom, safeState.zoom ] );\n\n\t// Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).\n\tmat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );\n\n\t// Innermost: scale from normalized [0,1] to rendered pixels.\n\tmat2d.scale( m, m, [ renderedW, renderedH ] );\n\n\treturn m;\n}\n\n/**\n * Transform a normalized world point [0,1] to screen pixels.\n *\n * @param camera The camera matrix from createCamera.\n * @param point The normalized world coordinate to transform.\n * @return The screen pixel coordinate.\n */\nexport function worldToScreen(\n\tcamera: Camera,\n\tpoint: NormalizedPoint\n): { x: number; y: number } {\n\tconst out = vec2.create();\n\tvec2.transformMat2d( out, [ point.x, point.y ], camera );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * Transform a screen pixel point to normalized world coordinates [0,1].\n *\n * @param camera The camera matrix from createCamera.\n * @param point The screen pixel coordinate to transform.\n * @param point.x The x component of the screen pixel coordinate.\n * @param point.y The y component of the screen pixel coordinate.\n * @return The normalized world coordinate.\n */\nexport function screenToWorld(\n\tcamera: Camera,\n\tpoint: { x: number; y: number }\n): NormalizedPoint {\n\tmat2d.invert( _scratchMat, camera );\n\tconst out = _scratchVec;\n\tvec2.transformMat2d( out, [ point.x, point.y ], _scratchMat );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * The bounding box of a transformed region in screen (pixel) space.\n */\nexport interface VisualBounds {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Compute the axis-aligned bounding box of a set of corners after\n * transforming them through a camera matrix.\n *\n * @param camera The camera matrix from createCamera.\n * @param corners The corners to transform (each as [x, y]).\n * @return The screen-space bounding box.\n */\nfunction aabb( camera: Camera, corners: [ number, number ][] ): VisualBounds {\n\tconst screenCorners = corners.map( ( c ) => {\n\t\tconst out = vec2.create();\n\t\tvec2.transformMat2d( out, c, camera );\n\t\treturn out;\n\t} );\n\tlet minX = screenCorners[ 0 ][ 0 ];\n\tlet maxX = screenCorners[ 0 ][ 0 ];\n\tlet minY = screenCorners[ 0 ][ 1 ];\n\tlet maxY = screenCorners[ 0 ][ 1 ];\n\tfor ( let i = 1; i < screenCorners.length; i++ ) {\n\t\tconst s = screenCorners[ i ];\n\t\tif ( s[ 0 ] < minX ) {\n\t\t\tminX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 0 ] > maxX ) {\n\t\t\tmaxX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 1 ] < minY ) {\n\t\t\tminY = s[ 1 ];\n\t\t}\n\t\tif ( s[ 1 ] > maxY ) {\n\t\t\tmaxY = s[ 1 ];\n\t\t}\n\t}\n\treturn { left: minX, top: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/**\n * Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])\n * after applying the camera transform.\n *\n * @param camera The camera matrix from createCamera.\n * @return The screen-space bounding box of the full image.\n */\nexport function getVisibleBounds( camera: Camera ): VisualBounds {\n\treturn aabb( camera, [\n\t\t[ 0, 0 ],\n\t\t[ 1, 0 ],\n\t\t[ 1, 1 ],\n\t\t[ 0, 1 ],\n\t] );\n}\n\n/**\n * Compose a camera matrix for exporting to a canvas.\n *\n * The resulting matrix maps image-pixel coordinates directly to output-canvas\n * coordinates. Apply it with `ctx.setTransform( ...camera )` then\n * `ctx.drawImage( image, 0, 0 )`.\n *\n * The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:\n * translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the source image in pixels.\n * @param outputSize The desired output canvas size in pixels.\n * @return The composed export camera matrix.\n */\nexport function createExportCamera(\n\tstate: CropperState,\n\timageSize: Size,\n\toutputSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\tif ( ! isValidSize( imageSize ) || ! isValidSize( outputSize ) ) {\n\t\treturn m;\n\t}\n\tconst { rotation, flip, cropRect, zoom, pan } =\n\t\tsanitizeCropperState( state );\n\t// Reference frame for cropRect/pan is the snap-rotation bbox — that's\n\t// what the stencil and CSS matrix use in the preview (see createCamera\n\t// and getImageFit). Using the true rotation here would position the\n\t// crop window at a different offset than the stencil framed, and show\n\t// a shifted region after any fine rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { width: rotW, height: rotH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Scale factor to map the natural crop region to the output canvas size.\n\tconst naturalCropW = cropRect.width * rotW;\n\tconst naturalCropH = cropRect.height * rotH;\n\tconst outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;\n\tconst outputScaleY =\n\t\tnaturalCropH > 0 ? outputSize.height / naturalCropH : 1;\n\n\tconst cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;\n\tconst cropOffsetY =\n\t\tcropRect.y * rotH + outputSize.height / 2 / outputScaleY;\n\tconst visualCenterX = rotW / 2 + pan.x * rotW;\n\tconst visualCenterY = rotH / 2 + pan.y * rotH;\n\tmat2d.scale( m, m, [ outputScaleX, outputScaleY ] );\n\tmat2d.translate( m, m, [\n\t\tvisualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,\n\t\tvisualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY,\n\t] );\n\t// Flip is composed outside rotation so it acts in viewport/output space —\n\t// must match createCamera's order for preview and export to agree.\n\tmat2d.scale( m, m, [ flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1 ] );\n\tmat2d.rotate( m, m, degreesToRadians( rotation ) );\n\tmat2d.scale( m, m, [ zoom, zoom ] );\n\tmat2d.translate( m, m, [ -imageSize.width / 2, -imageSize.height / 2 ] );\n\treturn m;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,OAAO,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IACrC,UAAU;AAAA,IACV,UAAU;AAAA,IACV;AAAA,EACD;AAGA,QAAM,eAAe,SAAS,QAAQ;AACtC,QAAM,eAAe,SAAS,SAAS;AACvC,QAAM,eAAe,eAAe,IAAI,WAAW,QAAQ,eAAe;AAC1E,QAAM,eACL,eAAe,IAAI,WAAW,SAAS,eAAe;AAEvD,QAAM,cAAc,SAAS,IAAI,OAAO,WAAW,QAAQ,IAAI;AAC/D,QAAM,cACL,SAAS,IAAI,OAAO,WAAW,SAAS,IAAI;AAC7C,QAAM,gBAAgB,OAAO,IAAI,IAAI,IAAI;AACzC,QAAM,gBAAgB,OAAO,IAAI,IAAI,IAAI;AACzC,QAAM,MAAO,GAAG,GAAG,CAAE,cAAc,YAAa,CAAE;AAClD,QAAM,UAAW,GAAG,GAAG;AAAA,IACtB,gBAAgB,cAAc,WAAW,QAAQ,IAAI;AAAA,IACrD,gBAAgB,cAAc,WAAW,SAAS,IAAI;AAAA,EACvD,CAAE;AAGF,QAAM,MAAO,GAAG,GAAG,CAAE,KAAK,aAAa,KAAK,GAAG,KAAK,WAAW,KAAK,CAAE,CAAE;AACxE,QAAM,OAAQ,GAAG,GAAG,iBAAkB,QAAS,CAAE;AACjD,QAAM,MAAO,GAAG,GAAG,CAAE,MAAM,IAAK,CAAE;AAClC,QAAM,UAAW,GAAG,GAAG,CAAE,CAAC,UAAU,QAAQ,GAAG,CAAC,UAAU,SAAS,CAAE,CAAE;AACvE,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/constants.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport type { NormalizedRect, Flip, CropperState } from './types';\n\n/**\n * Default/resting zoom. A full, unrotated crop needs at least 1x to cover the\n * crop area, but smaller/fine-rotated crops can be valid below 1x — the true\n * floor for those comes from `getMinZoom`.\n */\nexport const MIN_ZOOM = 1;\n/**\n * Safety floor for coverage-aware zoom. Degenerate crops can have a geometric\n * coverage minimum of 0, but camera and inverse-matrix math need a stable,\n * positive scale.\n */\nexport const ABSOLUTE_MIN_ZOOM = 0.1;\nexport const MAX_ZOOM = 10;\n\n/**\n * Minimum crop rect dimension in source-image pixels, enforced per axis\n * during resize. Prevents accidental sub-pixel crops while staying small\n * enough to allow tight crops (favicons, icons). Adjust here to tune the\n * floor globally.\n */\nexport const MIN_CROP_PIXELS = 16;\n\n/**\n * Minimum on-screen crop rect dimension in CSS pixels. The source-pixel\n * floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large\n * image fit into a small canvas it can render only a few CSS pixels wide —\n * too small to grab the resize handles. This floor keeps the crop operable\n * regardless of display scale; it binds when zoomed out and yields to the\n * source-pixel floor once the image is shown large enough. Sized to one\n * handle touch target (`$handle-touch-target-size` in `cropper.scss`).\n */\nexport const MIN_CROP_SCREEN_PX = 44;\n\n/**\n * Fraction of the constraining canvas axis the settled crop should occupy on\n * screen. When a crop is shown smaller than this (e.g. a square crop in a tall\n * image, capped by the contain-fit footprint's narrow axis), the view magnifies\n * to fill the canvas. `1` = always fill the canvas; lower = rescue only the\n * under-filled cases. See `getViewScale`.\n */\nexport const SETTLE_TARGET_CANVAS_FILL = 0.8;\n\n/**\n * Upper bound on the presentational view magnification (`getViewScale`).\n * Prevents a near-degenerate crop from magnifying the scene without limit.\n */\nexport const MAX_VIEW_SCALE = 8;\n\n/**\n * CSS pixels per source pixel required before resize handles snap the selected\n * source region to whole-pixel edges. Below 1:1, a source pixel is sub-pixel on\n * screen, so snapping would feel notchy without a visible pixel boundary.\n */\nexport const PIXEL_SNAP_DISPLAY_SCALE = 1;\n\n/**\n * Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.\n * This could be made configurable as a prop to the Cropper component.\n */\nexport const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;\n\n/** Fine step for keyboard-driven cropper movement, in normalized coordinates. */\nexport const DEFAULT_KEYBOARD_STEP = 0.01;\n\n/** Coarse keyboard movement multiplier when Shift is held. */\nexport const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;\n\n/**\n * Maximum free-rotation offset in degrees from the nearest 90° step.\n * The rotation slider allows ±45° around the current cardinal angle.\n */\nexport const MAX_ROTATION_OFFSET = 45;\n\nconst DEFAULT_CROP_RECT: NormalizedRect = {\n\tx: 0,\n\ty: 0,\n\twidth: 1,\n\theight: 1,\n};\n\nconst DEFAULT_FLIP: Flip = {\n\thorizontal: false,\n\tvertical: false,\n};\n\nconst DEFAULT_PAN: { x: number; y: number } = {\n\tx: 0,\n\ty: 0,\n};\n\nexport const DEFAULT_STATE: CropperState = {\n\timage: null,\n\tpan: { ...DEFAULT_PAN },\n\tzoom: MIN_ZOOM,\n\trotation: 0,\n\tbasePan: { ...DEFAULT_PAN },\n\tbaseZoom: MIN_ZOOM,\n\tbaseRotation: 0,\n\tflip: { ...DEFAULT_FLIP },\n\tcropRect: { ...DEFAULT_CROP_RECT },\n};\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/** The aspect ratio value (width / height). 0 = free / original. */\n\tvalue: number;\n}\n\n/**\n * Default aspect ratio presets. Consumers can use these as-is, override\n * with their own list, or extend with additional presets.\n *\n * @example\n * // Use defaults:\n * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />\n *\n * // Custom presets:\n * const socialPresets = [\n * { label: 'Instagram Post', value: 1 },\n * { label: 'Instagram Story', value: 9 / 16 },\n * { label: 'YouTube Thumbnail', value: 16 / 9 },\n * ];\n *\n * // Extend defaults:\n * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];\n */\n/**\n * Sentinel value for \"Original\" aspect ratio — resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },\n\t{ label: __( 'Photo (3:2)' ), value: 3 / 2 },\n\t{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },\n];\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,UAAU;AAQZ,IAAM,WAAW;AAMjB,IAAM,oBAAoB;AAC1B,IAAM,WAAW;AAQjB,IAAM,kBAAkB;AAWxB,IAAM,qBAAqB;AAS3B,IAAM,4BAA4B;AAMlC,IAAM,iBAAiB;AAOvB,IAAM,2BAA2B;AAMjC,IAAM,2BAA2B;AAGjC,IAAM,wBAAwB;AAG9B,IAAM,iCAAiC;AAMvC,IAAM,sBAAsB;AAEnC,IAAM,oBAAoC;AAAA,EACzC,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO;AAAA,EACP,QAAQ;AACT;AAEA,IAAM,eAAqB;AAAA,EAC1B,YAAY;AAAA,EACZ,UAAU;AACX;AAEA,IAAM,cAAwC;AAAA,EAC7C,GAAG;AAAA,EACH,GAAG;AACJ;AAEO,IAAM,gBAA8B;AAAA,EAC1C,OAAO;AAAA,EACP,KAAK,EAAE,GAAG,YAAY;AAAA,EACtB,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS,EAAE,GAAG,YAAY;AAAA,EAC1B,UAAU;AAAA,EACV,cAAc;AAAA,EACd,MAAM,EAAE,GAAG,aAAa;AAAA,EACxB,UAAU,EAAE,GAAG,kBAAkB;AAClC;AAkCO,IAAM,wBAAwB;AAE9B,IAAM,wBAA6C;AAAA,EACzD,EAAE,OAAO,GAAI,MAAO,GAAG,OAAO,EAAE;AAAA,EAChC,EAAE,OAAO,GAAI,UAAW,GAAG,OAAO,sBAAsB;AAAA,EACxD,EAAE,OAAO,GAAI,cAAe,GAAG,OAAO,EAAE;AAAA,EACxC,EAAE,OAAO,GAAI,kBAAmB,GAAG,OAAO,KAAK,EAAE;AAAA,EACjD,EAAE,OAAO,GAAI,iBAAkB,GAAG,OAAO,IAAI,GAAG;AAAA,EAChD,EAAE,OAAO,GAAI,eAAgB,GAAG,OAAO,IAAI,EAAE;AAAA,EAC7C,EAAE,OAAO,GAAI,wBAAyB,GAAG,OAAO,IAAI,EAAE;AAAA,EACtD,EAAE,OAAO,GAAI,aAAc,GAAG,OAAO,IAAI,EAAE;AAAA,EAC3C,EAAE,OAAO,GAAI,sBAAuB,GAAG,OAAO,IAAI,EAAE;AACrD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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 { 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 × 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×1; 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 — 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 — 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 —\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 — 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 — 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 — 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×1.\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/±Infinity\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 — 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 —\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]×[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→screen 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 — 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° 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) — 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×2 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": ";
|
|
4
|
+
"sourcesContent": ["import { mat2d, vec2 } from 'gl-matrix';\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 × 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×1; 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 — 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 — 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 —\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 — 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 — 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 — 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×1.\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/±Infinity\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 — 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 —\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]×[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→screen 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 — 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° 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) — 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×2 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": ";AAAA,SAAS,OAAO,YAAY;AAE5B,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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B;AAKA,QAAM,MAAM,OAAQ,CAAE,IAAI,MAAM,OAAQ,CAAE,IAAI;AAC9C,QAAM,MAAM,OAAQ,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
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/crop-rect.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import 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] × [0,1] normalized space. Returns\n * a full-frame rect (1×1) if `aspectRatio` is unset or non-positive.\n *\n * The returned rect is the same in either freeform or fixed-crop\n * mode — 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 — 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": ";AAeO,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/core/export/canvas-renderer.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type { CropperState } from '../types';\nimport { createExportCamera, getRotatedBBox } from '../camera';\n\n/** Default export quality for lossy formats (JPEG, WebP). */\nconst DEFAULT_QUALITY = 0.92;\n\n/**\n * Load an image from a URL with CORS support.\n *\n * @param src - The image URL to load.\n * @return A promise that resolves to the loaded HTMLImageElement.\n */\nexport function loadImage( src: string ): Promise< HTMLImageElement > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tconst image = new Image();\n\t\timage.addEventListener( 'load', () => resolve( image ) );\n\t\timage.addEventListener( 'error', ( error ) => reject( error ) );\n\t\timage.crossOrigin = 'anonymous';\n\t\timage.src = src;\n\t} );\n}\n\n/**\n * Apply rectangular crop, rotation, and flip transforms to produce a canvas.\n *\n * Uses createExportCamera to compose the full transform matrix, then applies\n * it in a single ctx.setTransform call before drawing the image.\n *\n * @param image - The source image element.\n * @param state - The full cropper state containing crop, rotation, and flip settings.\n * @return A canvas element containing the transformed and cropped image.\n */\nexport function renderToCanvas(\n\timage: HTMLImageElement,\n\tstate: CropperState\n): HTMLCanvasElement {\n\tconst { naturalWidth, naturalHeight } = image;\n\tconst { rotation, cropRect } = state;\n\tconst imageSize = { width: naturalWidth, height: naturalHeight };\n\n\t// Output size is the crop region in the snap-rotation bbox — matches\n\t// the preview's reference frame so the exported pixels track exactly\n\t// what the stencil framed, even at fine rotation angles.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst rotBBox = getRotatedBBox( naturalWidth, naturalHeight, snapRotation );\n\tconst outW = Math.round( cropRect.width * rotBBox.width );\n\tconst outH = Math.round( cropRect.height * rotBBox.height );\n\n\tconst canvas = document.createElement( 'canvas' );\n\tcanvas.width = outW;\n\tcanvas.height = outH;\n\tconst ctx = canvas.getContext( '2d' );\n\tif ( ! ctx ) {\n\t\tthrow new Error(\n\t\t\t'Could not obtain a 2D context for the export canvas.'\n\t\t);\n\t}\n\n\tconst camera = createExportCamera( state, imageSize, {\n\t\twidth: outW,\n\t\theight: outH,\n\t} );\n\tctx.setTransform(\n\t\tcamera[ 0 ],\n\t\tcamera[ 1 ],\n\t\tcamera[ 2 ],\n\t\tcamera[ 3 ],\n\t\tcamera[ 4 ],\n\t\tcamera[ 5 ]\n\t);\n\tctx.drawImage( image, 0, 0 );\n\treturn canvas;\n}\n\n/**\n * Convert a canvas to a Blob with configurable MIME type and quality.\n *\n * @param canvas - The canvas to export.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves to the canvas content as a Blob.\n */\nexport function canvasToBlob(\n\tcanvas: HTMLCanvasElement,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< Blob > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tcanvas.toBlob(\n\t\t\t( blob ) => {\n\t\t\t\tif ( blob ) {\n\t\t\t\t\tresolve( blob );\n\t\t\t\t} else {\n\t\t\t\t\treject( new Error( 'Canvas toBlob returned null.' ) );\n\t\t\t\t}\n\t\t\t},\n\t\t\tmimeType,\n\t\t\tquality\n\t\t);\n\t} );\n}\n\n/**\n * Convert a canvas to a data URL string.\n *\n * @param canvas - The canvas to export.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return The canvas content as a data URL string.\n */\nexport function canvasToDataURL(\n\tcanvas: HTMLCanvasElement,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): string {\n\treturn canvas.toDataURL( mimeType, quality );\n}\n\n/**\n * Load an image, render with transforms, and export as a Blob.\n *\n * Throws on failure so callers can distinguish error cases:\n * - Image load failures (network errors, 404s) throw the native\n * load error from the Image element.\n * - Cross-origin failures manifest as tainted-canvas errors from\n * `canvas.toBlob()` — the browser rejects reading pixel data\n * from a canvas that drew an image without valid CORS headers.\n * Ensure the source server sets `Access-Control-Allow-Origin`.\n * - Canvas context creation failures throw a descriptive Error.\n *\n * Only works in browser environments (needs DOM / HTMLCanvasElement).\n *\n * @param src - The image URL to load.\n * @param state - The cropper state with all transform settings.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves to the exported Blob.\n * @throws If the image fails to load, canvas creation fails, or\n * the resulting canvas is tainted by CORS restrictions.\n */\nexport async function exportCroppedImage(\n\tsrc: string,\n\tstate: CropperState,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< Blob > {\n\tconst image = await loadImage( src );\n\tconst canvas = renderToCanvas( image, state );\n\treturn canvasToBlob( canvas, mimeType, quality );\n}\n\n/**\n * Apply the cropper's transform (crop, rotation, flip, zoom) to an existing\n * canvas or image source. This is the bridge for multi-step editing pipelines\n * where an upstream tool (e.g., brightness/color adjustment) has already\n * processed the image and you want to apply the crop on top.\n *\n * Accepts any CanvasImageSource: HTMLImageElement, HTMLCanvasElement,\n * OffscreenCanvas, ImageBitmap, HTMLVideoElement, etc.\n *\n * @param source - The image source to crop/transform.\n * @param sourceSize - The dimensions of the source (natural width/height).\n * @param sourceSize.width - The width of the source in pixels.\n * @param sourceSize.height - The height of the source in pixels.\n * @param state - The cropper state with all transform settings.\n * @param outputSize - Optional output size. Defaults to the crop region's natural pixel size.\n * @param outputSize.width - The width of the output in pixels.\n * @param outputSize.height - The height of the output in pixels.\n * @return A canvas with the transforms applied.\n */\nexport function applyToCanvas(\n\tsource: CanvasImageSource,\n\tsourceSize: { width: number; height: number },\n\tstate: CropperState,\n\toutputSize?: { width: number; height: number }\n): HTMLCanvasElement {\n\t// Use snap-rotation bbox for default sizing so the default output\n\t// matches the preview's reference frame at fine rotation angles\n\t// (see renderToCanvas / createExportCamera).\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst rotBBox = getRotatedBBox(\n\t\tsourceSize.width,\n\t\tsourceSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Default output size: the crop region in natural pixels.\n\tconst outW =\n\t\toutputSize?.width ?? Math.round( state.cropRect.width * rotBBox.width );\n\tconst outH =\n\t\toutputSize?.height ??\n\t\tMath.round( state.cropRect.height * rotBBox.height );\n\n\tconst canvas = document.createElement( 'canvas' );\n\tcanvas.width = outW;\n\tcanvas.height = outH;\n\tconst ctx = canvas.getContext( '2d' );\n\tif ( ! ctx ) {\n\t\tthrow new Error(\n\t\t\t'Could not obtain a 2D context for the export canvas.'\n\t\t);\n\t}\n\n\tconst camera = createExportCamera( state, sourceSize, {\n\t\twidth: outW,\n\t\theight: outH,\n\t} );\n\tctx.setTransform(\n\t\tcamera[ 0 ],\n\t\tcamera[ 1 ],\n\t\tcamera[ 2 ],\n\t\tcamera[ 3 ],\n\t\tcamera[ 4 ],\n\t\tcamera[ 5 ]\n\t);\n\tctx.drawImage( source, 0, 0 );\n\treturn canvas;\n}\n\n/**\n * Download the cropped image as a file.\n *\n * Loads the source image, applies all transforms, and triggers a\n * browser download via exportCroppedImage() + object URL + anchor click.\n *\n * Throws on export failure (see `exportCroppedImage`).\n *\n * @param src - The image URL to load.\n * @param state - The cropper state with all transform settings.\n * @param filename - The download filename. Defaults to 'cropped-image'.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves when the download is triggered.\n */\nexport async function downloadCroppedImage(\n\tsrc: string,\n\tstate: CropperState,\n\tfilename: string = 'cropped-image',\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< void > {\n\tconst blob = await exportCroppedImage( src, state, mimeType, quality );\n\tconst ext = mimeType.split( '/' )[ 1 ] ?? 'png';\n\tconst url = URL.createObjectURL( blob );\n\tconst a = document.createElement( 'a' );\n\ta.href = url;\n\ta.download = `${ filename }.${ ext }`;\n\ta.click();\n\tURL.revokeObjectURL( url );\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,oBAAoB,sBAAsB;AAGnD,IAAM,kBAAkB;AAQjB,SAAS,UAAW,KAA2C;AACrE,SAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAC1C,UAAM,QAAQ,IAAI,MAAM;AACxB,UAAM,iBAAkB,QAAQ,MAAM,QAAS,KAAM,CAAE;AACvD,UAAM,iBAAkB,SAAS,CAAE,UAAW,OAAQ,KAAM,CAAE;AAC9D,UAAM,cAAc;AACpB,UAAM,MAAM;AAAA,EACb,CAAE;AACH;AAYO,SAAS,eACf,OACA,OACoB;AACpB,QAAM,EAAE,cAAc,cAAc,IAAI;AACxC,QAAM,EAAE,UAAU,SAAS,IAAI;AAC/B,QAAM,YAAY,EAAE,OAAO,c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|
|
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/**\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 — 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\t// Touch gestures are handled by touchstart/touchmove. Starting the\n\t\t// pointer drag path too can briefly toggle drag UI before pinch begins.\n\t\tif ( e.pointerType === 'touch' ) {\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 — 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 —\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\t\tmoveEvent.preventDefault();\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 → 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. Keep this based on the\n\t\t\t\t\t// pinch-start state; using the current reducer state here\n\t\t\t\t\t// compounds prior touchmove frames and makes a fixed pinch\n\t\t\t\t\t// center drift after the image is already zoomed or panned.\n\t\t\t\t\tconst zoomRatio =\n\t\t\t\t\t\ttouch.startZoom !== 0\n\t\t\t\t\t\t\t? 1 - newZoom / touch.startZoom\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst startFocalNormX = startMx / visSize.width;\n\t\t\t\t\tconst startFocalNormY = startMy / visSize.height;\n\n\t\t\t\t\t// Combined: midpoint drift + zoom around the pinch-start\n\t\t\t\t\t// midpoint, so moving both fingers together pans while\n\t\t\t\t\t// symmetric pinches keep the start center stationary.\n\t\t\t\t\tconst newCropX =\n\t\t\t\t\t\ttouch.startPanX +\n\t\t\t\t\t\tpanDx +\n\t\t\t\t\t\t( startFocalNormX - touch.startPanX ) * zoomRatio;\n\t\t\t\t\tconst newCropY =\n\t\t\t\t\t\ttouch.startPanY +\n\t\t\t\t\t\tpanDy +\n\t\t\t\t\t\t( startFocalNormY - touch.startPanY ) * zoomRatio;\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 → pan.\n\t\t\t\t// If fingers went 2→1 (didPinch is true), we do NOT\n\t\t\t\t// switch to pan — 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 — 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 — 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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,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EAChB;AACD;",
|
|
4
|
+
"sourcesContent": ["import 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 — 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\t// Touch gestures are handled by touchstart/touchmove. Starting the\n\t\t// pointer drag path too can briefly toggle drag UI before pinch begins.\n\t\tif ( e.pointerType === 'touch' ) {\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 — 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 —\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\t\tmoveEvent.preventDefault();\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 → 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. Keep this based on the\n\t\t\t\t\t// pinch-start state; using the current reducer state here\n\t\t\t\t\t// compounds prior touchmove frames and makes a fixed pinch\n\t\t\t\t\t// center drift after the image is already zoomed or panned.\n\t\t\t\t\tconst zoomRatio =\n\t\t\t\t\t\ttouch.startZoom !== 0\n\t\t\t\t\t\t\t? 1 - newZoom / touch.startZoom\n\t\t\t\t\t\t\t: 0;\n\t\t\t\t\tconst startFocalNormX = startMx / visSize.width;\n\t\t\t\t\tconst startFocalNormY = startMy / visSize.height;\n\n\t\t\t\t\t// Combined: midpoint drift + zoom around the pinch-start\n\t\t\t\t\t// midpoint, so moving both fingers together pans while\n\t\t\t\t\t// symmetric pinches keep the start center stationary.\n\t\t\t\t\tconst newCropX =\n\t\t\t\t\t\ttouch.startPanX +\n\t\t\t\t\t\tpanDx +\n\t\t\t\t\t\t( startFocalNormX - touch.startPanX ) * zoomRatio;\n\t\t\t\t\tconst newCropY =\n\t\t\t\t\t\ttouch.startPanY +\n\t\t\t\t\t\tpanDy +\n\t\t\t\t\t\t( startFocalNormY - touch.startPanY ) * zoomRatio;\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 → pan.\n\t\t\t\t// If fingers went 2→1 (didPinch is true), we do NOT\n\t\t\t\t// switch to pan — 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 — 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 — 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": ";AACA;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,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