@wordpress/media-editor 0.15.0 → 0.17.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 +18 -0
- package/build/components/media-editor/index.cjs +115 -119
- package/build/components/media-editor/index.cjs.map +3 -3
- 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 +0 -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 +31 -15
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- 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 +117 -120
- 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 +0 -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 +31 -15
- 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 +6 -6
- package/build-style/style.css +6 -6
- package/build-types/components/media-editor/index.d.ts +46 -11
- 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 +1 -4
- 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/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/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/global.d.ts +5 -0
- package/package.json +24 -22
- package/src/components/media-editor/index.tsx +233 -194
- package/src/components/media-editor/style.scss +6 -3
- 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 +5 -20
- 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 +43 -19
- package/src/components/media-editor-modal/style.scss +8 -4
- 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 +15 -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.build.json +26 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +22 -15
- 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/components/rotation-ruler/stories/index.story.d.ts +0 -14
- package/build-types/components/rotation-ruler/stories/index.story.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
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +0 -16
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/stencil-math.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';\nimport type { HandlePosition, NormalizedRect, Size } from './types';\n\nexport type { HandlePosition };\n\n/** Axis whose resize distance controls the locked-ratio size projection. */\nexport type ResizeDriverAxis = 'width' | 'height';\n\n/**\n * Resolve the minimum crop dimension, in source-image pixels, for the current\n * display scale.\n *\n * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that\n * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that\n * keeps the crop large enough to grab. The on-screen floor converted to source\n * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the\n * larger of the two. When the image is shown small (small `displayScale`) the\n * on-screen floor dominates; once it is shown large enough the source-pixel\n * floor takes over.\n *\n * @param displayScale CSS pixels rendered per source pixel\n * (fit scale × zoom × view scale).\n * @return Minimum crop dimension in source-image pixels.\n */\nexport function getMinCropPixels( displayScale: number ): number {\n\tif ( displayScale <= 0 ) {\n\t\treturn MIN_CROP_PIXELS;\n\t}\n\treturn Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );\n}\n\n/**\n * Default minimum crop rect dimension in normalized space, used when no\n * explicit per-axis minimum is supplied (e.g. before the source image\n * has loaded). Real usage derives a pixel-based min from the source\n * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.\n */\nexport const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };\n\n/**\n * Bounds within which the crop rect must stay.\n */\nexport interface CropBounds {\n\tminX: number;\n\tminY: number;\n\tmaxX: number;\n\tmaxY: number;\n}\n\n/**\n * Drag state for tracking a resize interaction.\n */\nexport interface ResizeDragState {\n\t/** Which handle is being dragged. */\n\thandle: HandlePosition;\n\t/** The mouse position (pixels) when the drag started. */\n\tstartX: number;\n\tstartY: number;\n\t/** The crop rect (normalized) when the drag started. */\n\tstartRect: NormalizedRect;\n}\n\n/**\n * Compute the new crop rect for a free (no aspect ratio) resize.\n *\n * Each edge moves independently based on the handle being dragged.\n * Edges are clamped to the provided bounds and maintain a minimum size.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeFreeResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst dx =\n\t\timageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;\n\tconst dy =\n\t\timageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\tlet edgeTop = s.y;\n\tlet edgeBottom = s.y + s.height;\n\tlet edgeLeft = s.x;\n\tlet edgeRight = s.x + s.width;\n\n\tif ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {\n\t\tedgeTop = Math.max(\n\t\t\tbounds.minY,\n\t\t\tMath.min( s.y + dy, edgeBottom - minCropSize.height )\n\t\t);\n\t}\n\tif ( handle === 's' || handle === 'sw' || handle === 'se' ) {\n\t\tedgeBottom = Math.max(\n\t\t\tedgeTop + minCropSize.height,\n\t\t\tMath.min( s.y + s.height + dy, bounds.maxY )\n\t\t);\n\t}\n\tif ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {\n\t\tedgeLeft = Math.max(\n\t\t\tbounds.minX,\n\t\t\tMath.min( s.x + dx, edgeRight - minCropSize.width )\n\t\t);\n\t}\n\tif ( handle === 'e' || handle === 'ne' || handle === 'se' ) {\n\t\tedgeRight = Math.max(\n\t\t\tedgeLeft + minCropSize.width,\n\t\t\tMath.min( s.x + s.width + dx, bounds.maxX )\n\t\t);\n\t}\n\n\treturn {\n\t\tx: edgeLeft,\n\t\ty: edgeTop,\n\t\twidth: edgeRight - edgeLeft,\n\t\theight: edgeBottom - edgeTop,\n\t};\n}\n\n/**\n * Compute the new crop rect for a locked-aspect-ratio corner resize.\n *\n * The opposite corner is the anchor. The dragged corner moves freely\n * but the result is clamped to maintain the aspect ratio and stay\n * within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param normalizedRatio The locked aspect ratio (width / height in normalized space).\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @param driverAxis Optional explicit driver axis. Used for keyboard\n * resize, where one arrow axis should determine the step.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tnormalizedRatio: number,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE,\n\tdriverAxis?: ResizeDriverAxis\n): NormalizedRect {\n\t// The math below divides by `normalizedRatio` and `imageSize`, so\n\t// bail out with the start rect when any of them is zero. This can\n\t// happen if a resize is triggered (e.g. via keyboard arrows on a\n\t// focused handle) before the image has loaded.\n\tif (\n\t\tnormalizedRatio <= 0 ||\n\t\timageSize.width <= 0 ||\n\t\timageSize.height <= 0\n\t) {\n\t\treturn { ...drag.startRect };\n\t}\n\n\tconst dx = ( clientX - drag.startX ) / imageSize.width;\n\tconst dy = ( clientY - drag.startY ) / imageSize.height;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\t// Determine the anchor corner (opposite to the dragged corner).\n\tconst anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;\n\tconst anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;\n\n\t// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).\n\tconst dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;\n\tconst dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;\n\n\t// Desired new position of the dragged corner.\n\tconst draggedX =\n\t\t( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;\n\tconst draggedY =\n\t\t( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;\n\n\t// Raw distances from anchor to dragged corner.\n\tlet distW = ( draggedX - anchorX ) * dirX;\n\tlet distH = ( draggedY - anchorY ) * dirY;\n\n\t// Enforce minimum size on both axes, projecting through the ratio so\n\t// neither axis falls below its per-axis floor.\n\tconst minDistW = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tconst minDistH = minDistW / normalizedRatio;\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Determine which axis \"drives\". Pointer drags use the dragged-corner\n\t// geometry so the projected crop changes continuously as the pointer moves.\n\t// Keyboard resize passes an explicit axis because a single-axis arrow step\n\t// should drive that axis instead of being cancelled by the unchanged axis.\n\tconst pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;\n\tconst isWidthDriver =\n\t\tdriverAxis === 'width' ||\n\t\t( ! driverAxis &&\n\t\t\t( distW * imageSize.width ) / ( distH * imageSize.height ) >\n\t\t\t\tpixelRatio );\n\n\tif ( isWidthDriver ) {\n\t\t// Width is the driver — compute height from ratio.\n\t\tdistH = distW / normalizedRatio;\n\t} else {\n\t\t// Height is the driver — compute width from ratio.\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Clamp to image coverage bounds. If the rect would exceed,\n\t// shrink it (maintaining ratio) to fit.\n\tconst maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;\n\tconst maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;\n\n\tif ( distW > maxW ) {\n\t\tdistW = maxW;\n\t\tdistH = distW / normalizedRatio;\n\t}\n\tif ( distH > maxH ) {\n\t\tdistH = maxH;\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Enforce minimum after clamping.\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Compute the final rect position from the anchor.\n\tconst newX = dirX > 0 ? anchorX : anchorX - distW;\n\tconst newY = dirY > 0 ? anchorY : anchorY - distH;\n\n\treturn { x: newX, y: newY, width: distW, height: distH };\n}\n\n/**\n * Compute the new crop rect for a resize that temporarily locks the\n * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).\n *\n * Corner handles delegate to {@link computeLockedResizeRect}. Edge\n * handles size the dragged axis freely, then expand the perpendicular\n * axis symmetrically around the rect's center to preserve the ratio,\n * clamping symmetrically so the rect stays within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeShiftLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst s = drag.startRect;\n\tconst pixelW = s.width * imageSize.width;\n\tconst pixelH = s.height * imageSize.height;\n\tif ( pixelH <= 0 || pixelW <= 0 ) {\n\t\treturn computeFreeResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tminCropSize\n\t\t);\n\t}\n\tconst normalizedRatio = s.width / s.height;\n\n\tconst handle = drag.handle;\n\tif (\n\t\thandle === 'nw' ||\n\t\thandle === 'ne' ||\n\t\thandle === 'sw' ||\n\t\thandle === 'se'\n\t) {\n\t\treturn computeLockedResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tnormalizedRatio,\n\t\t\tminCropSize\n\t\t);\n\t}\n\n\t// Edge handle: size the dragged axis with free-resize logic, then\n\t// expand the perpendicular axis symmetrically around the rect's center.\n\tconst free = computeFreeResizeRect(\n\t\tdrag,\n\t\tclientX,\n\t\tclientY,\n\t\timageSize,\n\t\tbounds,\n\t\tminCropSize\n\t);\n\n\tif ( handle === 'n' || handle === 's' ) {\n\t\t// Height is the driver; derive width from ratio.\n\t\tlet newHeight = free.height;\n\t\tlet newWidth = newHeight * normalizedRatio;\n\t\tconst centerX = s.x + s.width / 2;\n\t\t// Symmetric clamp: limit by the smaller of the two side gaps so\n\t\t// the rect stays centered around centerX.\n\t\tconst maxWidth =\n\t\t\tMath.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;\n\t\tif ( newWidth > maxWidth ) {\n\t\t\tnewWidth = maxWidth;\n\t\t\tnewHeight = newWidth / normalizedRatio;\n\t\t}\n\t\t// Enforce the minimum on the driving axis, then derive the\n\t\t// other axis from the ratio so it stays consistent. The\n\t\t// effective minimum height has to satisfy the per-axis floor\n\t\t// on both axes simultaneously.\n\t\tconst minHeight = Math.max(\n\t\t\tminCropSize.height,\n\t\t\tminCropSize.width / normalizedRatio\n\t\t);\n\t\tif ( newHeight < minHeight ) {\n\t\t\tnewHeight = minHeight;\n\t\t\tnewWidth = newHeight * normalizedRatio;\n\t\t}\n\t\t// Re-anchor the dragged axis to the opposite edge so the\n\t\t// height adjustment after clamping keeps that edge fixed.\n\t\tconst newY = handle === 'n' ? s.y + s.height - newHeight : s.y;\n\t\treturn {\n\t\t\tx: centerX - newWidth / 2,\n\t\t\ty: newY,\n\t\t\twidth: newWidth,\n\t\t\theight: newHeight,\n\t\t};\n\t}\n\n\t// 'e' or 'w': width is the driver; derive height from ratio.\n\tlet newWidth = free.width;\n\tlet newHeight = newWidth / normalizedRatio;\n\tconst centerY = s.y + s.height / 2;\n\tconst maxHeight =\n\t\tMath.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;\n\tif ( newHeight > maxHeight ) {\n\t\tnewHeight = maxHeight;\n\t\tnewWidth = newHeight * normalizedRatio;\n\t}\n\tconst minWidth = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tif ( newWidth < minWidth ) {\n\t\tnewWidth = minWidth;\n\t\tnewHeight = newWidth / normalizedRatio;\n\t}\n\tconst newX = handle === 'w' ? s.x + s.width - newWidth : s.x;\n\treturn {\n\t\tx: newX,\n\t\ty: centerY - newHeight / 2,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';\nimport type { HandlePosition, NormalizedRect, Size } from './types';\n\nexport type { HandlePosition };\n\n/** Axis whose resize distance controls the locked-ratio size projection. */\nexport type ResizeDriverAxis = 'width' | 'height';\n\n/**\n * Resolve the minimum crop dimension, in source-image pixels, for the current\n * display scale.\n *\n * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that\n * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that\n * keeps the crop large enough to grab. The on-screen floor converted to source\n * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the\n * larger of the two. When the image is shown small (small `displayScale`) the\n * on-screen floor dominates; once it is shown large enough the source-pixel\n * floor takes over.\n *\n * @param displayScale CSS pixels rendered per source pixel\n * (fit scale × zoom × view scale).\n * @return Minimum crop dimension in source-image pixels.\n */\nexport function getMinCropPixels( displayScale: number ): number {\n\tif ( displayScale <= 0 ) {\n\t\treturn MIN_CROP_PIXELS;\n\t}\n\treturn Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );\n}\n\n/**\n * Default minimum crop rect dimension in normalized space, used when no\n * explicit per-axis minimum is supplied (e.g. before the source image\n * has loaded). Real usage derives a pixel-based min from the source\n * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.\n */\nexport const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };\n\n/**\n * Bounds within which the crop rect must stay.\n */\nexport interface CropBounds {\n\tminX: number;\n\tminY: number;\n\tmaxX: number;\n\tmaxY: number;\n}\n\n/**\n * Drag state for tracking a resize interaction.\n */\nexport interface ResizeDragState {\n\t/** Which handle is being dragged. */\n\thandle: HandlePosition;\n\t/** The mouse position (pixels) when the drag started. */\n\tstartX: number;\n\tstartY: number;\n\t/** The crop rect (normalized) when the drag started. */\n\tstartRect: NormalizedRect;\n}\n\n/**\n * Compute the new crop rect for a free (no aspect ratio) resize.\n *\n * Each edge moves independently based on the handle being dragged.\n * Edges are clamped to the provided bounds and maintain a minimum size.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeFreeResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst dx =\n\t\timageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;\n\tconst dy =\n\t\timageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\tlet edgeTop = s.y;\n\tlet edgeBottom = s.y + s.height;\n\tlet edgeLeft = s.x;\n\tlet edgeRight = s.x + s.width;\n\n\tif ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {\n\t\tedgeTop = Math.max(\n\t\t\tbounds.minY,\n\t\t\tMath.min( s.y + dy, edgeBottom - minCropSize.height )\n\t\t);\n\t}\n\tif ( handle === 's' || handle === 'sw' || handle === 'se' ) {\n\t\tedgeBottom = Math.max(\n\t\t\tedgeTop + minCropSize.height,\n\t\t\tMath.min( s.y + s.height + dy, bounds.maxY )\n\t\t);\n\t}\n\tif ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {\n\t\tedgeLeft = Math.max(\n\t\t\tbounds.minX,\n\t\t\tMath.min( s.x + dx, edgeRight - minCropSize.width )\n\t\t);\n\t}\n\tif ( handle === 'e' || handle === 'ne' || handle === 'se' ) {\n\t\tedgeRight = Math.max(\n\t\t\tedgeLeft + minCropSize.width,\n\t\t\tMath.min( s.x + s.width + dx, bounds.maxX )\n\t\t);\n\t}\n\n\treturn {\n\t\tx: edgeLeft,\n\t\ty: edgeTop,\n\t\twidth: edgeRight - edgeLeft,\n\t\theight: edgeBottom - edgeTop,\n\t};\n}\n\n/**\n * Compute the new crop rect for a locked-aspect-ratio corner resize.\n *\n * The opposite corner is the anchor. The dragged corner moves freely\n * but the result is clamped to maintain the aspect ratio and stay\n * within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param normalizedRatio The locked aspect ratio (width / height in normalized space).\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @param driverAxis Optional explicit driver axis. Used for keyboard\n * resize, where one arrow axis should determine the step.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tnormalizedRatio: number,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE,\n\tdriverAxis?: ResizeDriverAxis\n): NormalizedRect {\n\t// The math below divides by `normalizedRatio` and `imageSize`, so\n\t// bail out with the start rect when any of them is zero. This can\n\t// happen if a resize is triggered (e.g. via keyboard arrows on a\n\t// focused handle) before the image has loaded.\n\tif (\n\t\tnormalizedRatio <= 0 ||\n\t\timageSize.width <= 0 ||\n\t\timageSize.height <= 0\n\t) {\n\t\treturn { ...drag.startRect };\n\t}\n\n\tconst dx = ( clientX - drag.startX ) / imageSize.width;\n\tconst dy = ( clientY - drag.startY ) / imageSize.height;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\t// Determine the anchor corner (opposite to the dragged corner).\n\tconst anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;\n\tconst anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;\n\n\t// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).\n\tconst dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;\n\tconst dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;\n\n\t// Desired new position of the dragged corner.\n\tconst draggedX =\n\t\t( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;\n\tconst draggedY =\n\t\t( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;\n\n\t// Raw distances from anchor to dragged corner.\n\tlet distW = ( draggedX - anchorX ) * dirX;\n\tlet distH = ( draggedY - anchorY ) * dirY;\n\n\t// Enforce minimum size on both axes, projecting through the ratio so\n\t// neither axis falls below its per-axis floor.\n\tconst minDistW = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tconst minDistH = minDistW / normalizedRatio;\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Determine which axis \"drives\". Pointer drags use the dragged-corner\n\t// geometry so the projected crop changes continuously as the pointer moves.\n\t// Keyboard resize passes an explicit axis because a single-axis arrow step\n\t// should drive that axis instead of being cancelled by the unchanged axis.\n\tconst pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;\n\tconst isWidthDriver =\n\t\tdriverAxis === 'width' ||\n\t\t( ! driverAxis &&\n\t\t\t( distW * imageSize.width ) / ( distH * imageSize.height ) >\n\t\t\t\tpixelRatio );\n\n\tif ( isWidthDriver ) {\n\t\t// Width is the driver — compute height from ratio.\n\t\tdistH = distW / normalizedRatio;\n\t} else {\n\t\t// Height is the driver — compute width from ratio.\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Clamp to image coverage bounds. If the rect would exceed,\n\t// shrink it (maintaining ratio) to fit.\n\tconst maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;\n\tconst maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;\n\n\tif ( distW > maxW ) {\n\t\tdistW = maxW;\n\t\tdistH = distW / normalizedRatio;\n\t}\n\tif ( distH > maxH ) {\n\t\tdistH = maxH;\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Enforce minimum after clamping.\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Compute the final rect position from the anchor.\n\tconst newX = dirX > 0 ? anchorX : anchorX - distW;\n\tconst newY = dirY > 0 ? anchorY : anchorY - distH;\n\n\treturn { x: newX, y: newY, width: distW, height: distH };\n}\n\n/**\n * Compute the new crop rect for a resize that temporarily locks the\n * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).\n *\n * Corner handles delegate to {@link computeLockedResizeRect}. Edge\n * handles size the dragged axis freely, then expand the perpendicular\n * axis symmetrically around the rect's center to preserve the ratio,\n * clamping symmetrically so the rect stays within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeShiftLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst s = drag.startRect;\n\tconst pixelW = s.width * imageSize.width;\n\tconst pixelH = s.height * imageSize.height;\n\tif ( pixelH <= 0 || pixelW <= 0 ) {\n\t\treturn computeFreeResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tminCropSize\n\t\t);\n\t}\n\tconst normalizedRatio = s.width / s.height;\n\n\tconst handle = drag.handle;\n\tif (\n\t\thandle === 'nw' ||\n\t\thandle === 'ne' ||\n\t\thandle === 'sw' ||\n\t\thandle === 'se'\n\t) {\n\t\treturn computeLockedResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tnormalizedRatio,\n\t\t\tminCropSize\n\t\t);\n\t}\n\n\t// Edge handle: size the dragged axis with free-resize logic, then\n\t// expand the perpendicular axis symmetrically around the rect's center.\n\tconst free = computeFreeResizeRect(\n\t\tdrag,\n\t\tclientX,\n\t\tclientY,\n\t\timageSize,\n\t\tbounds,\n\t\tminCropSize\n\t);\n\n\tif ( handle === 'n' || handle === 's' ) {\n\t\t// Height is the driver; derive width from ratio.\n\t\tlet newHeight = free.height;\n\t\tlet newWidth = newHeight * normalizedRatio;\n\t\tconst centerX = s.x + s.width / 2;\n\t\t// Symmetric clamp: limit by the smaller of the two side gaps so\n\t\t// the rect stays centered around centerX.\n\t\tconst maxWidth =\n\t\t\tMath.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;\n\t\tif ( newWidth > maxWidth ) {\n\t\t\tnewWidth = maxWidth;\n\t\t\tnewHeight = newWidth / normalizedRatio;\n\t\t}\n\t\t// Enforce the minimum on the driving axis, then derive the\n\t\t// other axis from the ratio so it stays consistent. The\n\t\t// effective minimum height has to satisfy the per-axis floor\n\t\t// on both axes simultaneously.\n\t\tconst minHeight = Math.max(\n\t\t\tminCropSize.height,\n\t\t\tminCropSize.width / normalizedRatio\n\t\t);\n\t\tif ( newHeight < minHeight ) {\n\t\t\tnewHeight = minHeight;\n\t\t\tnewWidth = newHeight * normalizedRatio;\n\t\t}\n\t\t// Re-anchor the dragged axis to the opposite edge so the\n\t\t// height adjustment after clamping keeps that edge fixed.\n\t\tconst newY = handle === 'n' ? s.y + s.height - newHeight : s.y;\n\t\treturn {\n\t\t\tx: centerX - newWidth / 2,\n\t\t\ty: newY,\n\t\t\twidth: newWidth,\n\t\t\theight: newHeight,\n\t\t};\n\t}\n\n\t// 'e' or 'w': width is the driver; derive height from ratio.\n\tlet newWidth = free.width;\n\tlet newHeight = newWidth / normalizedRatio;\n\tconst centerY = s.y + s.height / 2;\n\tconst maxHeight =\n\t\tMath.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;\n\tif ( newHeight > maxHeight ) {\n\t\tnewHeight = maxHeight;\n\t\tnewWidth = newHeight * normalizedRatio;\n\t}\n\tconst minWidth = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tif ( newWidth < minWidth ) {\n\t\tnewWidth = minWidth;\n\t\tnewHeight = newWidth / normalizedRatio;\n\t}\n\tconst newX = handle === 'w' ? s.x + s.width - newWidth : s.x;\n\treturn {\n\t\tx: newX,\n\t\ty: centerY - newHeight / 2,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB,0BAA0B;AAwB7C,SAAS,iBAAkB,cAA+B;AAChE,MAAK,gBAAgB,GAAI;AACxB,WAAO;AAAA,EACR;AACA,SAAO,KAAK,IAAK,iBAAiB,qBAAqB,YAAa;AACrE;AAQO,IAAM,wBAA8B,EAAE,OAAO,MAAM,QAAQ,KAAK;AAuChE,SAAS,sBACf,MACA,SACA,SACA,WACA,QACA,cAAoB,uBACH;AACjB,QAAM,KACL,UAAU,QAAQ,KAAM,UAAU,KAAK,UAAW,UAAU,QAAQ;AACrE,QAAM,KACL,UAAU,SAAS,KAAM,UAAU,KAAK,UAAW,UAAU,SAAS;AAEvE,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,KAAK;AAEpB,MAAI,UAAU,EAAE;AAChB,MAAI,aAAa,EAAE,IAAI,EAAE;AACzB,MAAI,WAAW,EAAE;AACjB,MAAI,YAAY,EAAE,IAAI,EAAE;AAExB,MAAK,WAAW,OAAO,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AA,EACD;AAGA,MAAI,WAAW,KAAK;AACpB,MAAI,YAAY,WAAW;AAC3B,QAAM,UAAU,EAAE,IAAI,EAAE,SAAS;AACjC,QAAM,YACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;AAC5D,MAAK,YAAY,WAAY;AAC5B,gBAAY;AACZ,eAAW,YAAY;AAAA,EACxB;AACA,QAAM,WAAW,KAAK;AAAA,IACrB,YAAY;AAAA,IACZ,YAAY,SAAS;AAAA,EACtB;AACA,MAAK,WAAW,UAAW;AAC1B,eAAW;AACX,gBAAY,WAAW;AAAA,EACxB;AACA,QAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,WAAW,EAAE;AAC3D,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG,UAAU,YAAY;AAAA,IACzB,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AACD;",
|
|
6
6
|
"names": ["newHeight", "newWidth"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/transform-style.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type { CropperState, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { isValidSize, sanitizeCropperState } from './math/sanitize';\n\n/** Identity CSS transform — applied when inputs aren't safe to compose. */\nconst IDENTITY_MATRIX_STYLE = 'matrix(1, 0, 0, 1, 0, 0)';\n\n/**\n * Computes a CSS matrix() transform string from the cropper state.\n *\n * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)\n * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).\n *\n * Flip is composed outside rotation so it is viewport-relative — horizontal\n * flip mirrors across the viewport's vertical axis regardless of rotation.\n * Must match the matrix order in `createCamera` / `getImageCropBounds`.\n *\n * This is a pure function with no framework dependencies. The React hook\n * `useTransformStyle` wraps this in `useMemo` for memoization.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function computeTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\t// Match the identity short-circuit used by `createCamera` and\n\t// `getSourceRegion` so the preview path stays consistent with the math\n\t// path when `imageSize` itself is hostile (state sanitization below\n\t// only guards the state fields, not these size arguments).\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn IDENTITY_MATRIX_STYLE;\n\t}\n\t// Sanitize so hostile state can't produce `matrix(NaN, NaN, ...)` here\n\t// while the parallel `createCamera` path returns a finite matrix. Both\n\t// paths must agree under defense-in-depth conditions.\n\tconst safeState = sanitizeCropperState( state );\n\tconst translateX = safeState.pan.x * imageSize.width;\n\tconst translateY = safeState.pan.y * imageSize.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\n\t// Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)\n\tconst a = sx * cos * z;\n\tconst b = sy * sin * z;\n\tconst c = -sx * sin * z;\n\tconst d = sy * cos * z;\n\n\treturn `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,wBAAwB;AACjC,SAAS,aAAa,4BAA4B;AAGlD,IAAM,wBAAwB;AAmBvB,SAAS,sBACf,OACA,WACS;AAKT,MAAK,CAAE,YAAa,SAAU,GAAI;AACjC,WAAO;AAAA,EACR;AAIA,QAAM,YAAY,qBAAsB,KAAM;AAC9C,QAAM,aAAa,UAAU,IAAI,IAAI,UAAU;AAC/C,QAAM,aAAa,UAAU,IAAI,IAAI,UAAU;AAC/C,QAAM,MAAM,iBAAkB,UAAU,QAAS;AACjD,QAAM,MAAM,KAAK,IAAK,GAAI;AAC1B,QAAM,MAAM,KAAK,IAAK,GAAI;AAC1B,QAAM,KAAK,UAAU,KAAK,aAAa,KAAK;AAC5C,QAAM,KAAK,UAAU,KAAK,WAAW,KAAK;AAC1C,QAAM,IAAI,UAAU;AAGpB,QAAM,IAAI,KAAK,MAAM;AACrB,QAAM,IAAI,KAAK,MAAM;AACrB,QAAM,IAAI,CAAC,KAAK,MAAM;AACtB,QAAM,IAAI,KAAK,MAAM;AAErB,SAAO,UAAW,CAAE,KAAM,CAAE,KAAM,CAAE,KAAM,CAAE,KAAM,UAAW,KAAM,UAAW;AAC/E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/core/transforms/pipeline.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type { TransformOperation, CropperState } from '../types';\nimport { DEFAULT_STATE } from '../constants';\nimport { cropperReducer } from '../state';\n\n/**\n * Apply a single transform operation to a cropper state, returning\n * a new state with the containment invariant enforced.\n *\n * Delegates to the reducer via APPLY_OPERATION so pipeline replay\n * produces identical bounded state to UI interaction or setter\n * calls. The same logical operation yields the same result\n * regardless of entrypoint.\n *\n * @param state The current cropper state.\n * @param op The operation to apply.\n * @return A new cropper state with the operation applied.\n */\nexport function applyOperationToState(\n\tstate: CropperState,\n\top: TransformOperation\n): CropperState {\n\treturn cropperReducer( state, { type: 'APPLY_OPERATION', payload: op } );\n}\n\n/**\n * Replay all operations from an initial state to produce the final state.\n *\n * @param pipeline The array of transform operations to replay.\n * @param initialState The starting state. Defaults to DEFAULT_STATE.\n * @return The resulting cropper state after all operations are applied.\n */\nexport function stateFromPipeline(\n\tpipeline: TransformOperation[],\n\tinitialState: CropperState = { ...DEFAULT_STATE }\n): CropperState {\n\treturn pipeline.reduce(\n\t\t( state, op ) => applyOperationToState( state, op ),\n\t\tinitialState\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAexB,SAAS,sBACf,OACA,IACe;AACf,SAAO,eAAgB,OAAO,EAAE,MAAM,mBAAmB,SAAS,GAAG,CAAE;AACxE;AASO,SAAS,kBACf,UACA,eAA6B,EAAE,GAAG,cAAc,GACjC;AACf,SAAO,SAAS;AAAA,IACf,CAAE,OAAO,OAAQ,sBAAuB,OAAO,EAAG;AAAA,IAClD;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/viewport-state.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type { ViewportState, ViewportAction } from './types';\n\nexport const DEFAULT_VIEWPORT_STATE: ViewportState = {\n\tzoom: 1,\n\tpan: { x: 0, y: 0 },\n};\n\nexport function viewportReducer(\n\tstate: ViewportState,\n\taction: ViewportAction\n): ViewportState {\n\tswitch ( action.type ) {\n\t\tcase 'SET_VIEWPORT_ZOOM': {\n\t\t\tconst zoom = Math.min( 4, Math.max( 0.1, action.payload ) );\n\t\t\treturn zoom === state.zoom ? state : { ...state, zoom };\n\t\t}\n\t\tcase 'SET_VIEWPORT_PAN': {\n\t\t\tconst { x, y } = action.payload;\n\t\t\treturn x === state.pan.x && y === state.pan.y\n\t\t\t\t? state\n\t\t\t\t: { ...state, pan: action.payload };\n\t\t}\n\t\tcase 'RESET_VIEWPORT':\n\t\t\treturn state.zoom === DEFAULT_VIEWPORT_STATE.zoom &&\n\t\t\t\tstate.pan.x === DEFAULT_VIEWPORT_STATE.pan.x &&\n\t\t\t\tstate.pan.y === DEFAULT_VIEWPORT_STATE.pan.y\n\t\t\t\t? state\n\t\t\t\t: DEFAULT_VIEWPORT_STATE;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";AAEO,IAAM,yBAAwC;AAAA,EACpD,MAAM;AAAA,EACN,KAAK,EAAE,GAAG,GAAG,GAAG,EAAE;AACnB;AAEO,SAAS,gBACf,OACA,QACgB;AAChB,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,qBAAqB;AACzB,YAAM,OAAO,KAAK,IAAK,GAAG,KAAK,IAAK,KAAK,OAAO,OAAQ,CAAE;AAC1D,aAAO,SAAS,MAAM,OAAO,QAAQ,EAAE,GAAG,OAAO,KAAK;AAAA,IACvD;AAAA,IACA,KAAK,oBAAoB;AACxB,YAAM,EAAE,GAAG,EAAE,IAAI,OAAO;AACxB,aAAO,MAAM,MAAM,IAAI,KAAK,MAAM,MAAM,IAAI,IACzC,QACA,EAAE,GAAG,OAAO,KAAK,OAAO,QAAQ;AAAA,IACpC;AAAA,IACA,KAAK;AACJ,aAAO,MAAM,SAAS,uBAAuB,QAC5C,MAAM,IAAI,MAAM,uBAAuB,IAAI,KAC3C,MAAM,IAAI,MAAM,uBAAuB,IAAI,IACzC,QACA;AAAA,EACL;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/components/cropper-provider.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseCropperReducer,\n\ttype CropperController,\n} from '../hooks/use-cropper-reducer';\nimport type { CropperState } from '../../core/types';\n\n/**\n * The context value type for the CropperProvider.\n * Contains the cropper controller from useCropperReducer.\n */\ntype CropperContextValue = CropperController | null;\n\nconst CropperContext = createContext< CropperContextValue >( null );\n\n/**\n * Props for the CropperProvider component.\n */\ninterface CropperProviderProps {\n\t/** Optional partial initial state to merge with defaults. */\n\tinitialState?: Partial< CropperState >;\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Convenience context provider that wraps `useCropperReducer`.\n *\n * Provides the pure cropper controller (state + setters, NO undo\n * history) to all descendant components via React context.\n *\n * History is a higher-layer concern owned by composite stores\n * (see `useMediaEditorState` in media-editor/state for the media\n * editor's composite controller with undo/redo).\n *\n * @param props\n * @param props.initialState\n * @param props.children\n * @return The provider element wrapping children.\n */\nexport function CropperProvider( {\n\tinitialState,\n\tchildren,\n}: CropperProviderProps ) {\n\tconst cropperReturn = useCropperReducer( initialState );\n\n\treturn (\n\t\t<CropperContext.Provider value={ cropperReturn }>\n\t\t\t{ children }\n\t\t</CropperContext.Provider>\n\t);\n}\n\n/**\n * Hook to consume the CropperProvider context.\n *\n * Must be used within a CropperProvider. Throws if used outside\n * of the provider tree.\n *\n * @return The cropper controller.\n */\nexport function useCropper(): CropperController {\n\tconst context = useContext( CropperContext );\n\n\tif ( ! context ) {\n\t\tthrow new Error( 'useCropper must be used within a CropperProvider.' );\n\t}\n\n\treturn context;\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,eAAe,kBAAkB;AAC1C;AAAA,EACC;AAAA,OAEM;AA2CL;AAlCF,IAAM,iBAAiB,cAAsC,IAAK;AA2B3D,SAAS,gBAAiB;AAAA,EAChC;AAAA,EACA;AACD,GAA0B;AACzB,QAAM,gBAAgB,kBAAmB,YAAa;AAEtD,SACC,oBAAC,eAAe,UAAf,EAAwB,OAAQ,eAC9B,UACH;AAEF;AAUO,SAAS,aAAgC;AAC/C,QAAM,UAAU,WAAY,cAAe;AAE3C,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI,MAAO,mDAAoD;AAAA,EACtE;AAEA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/components/cropper.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tuseCallback,\n\tuseMemo,\n\tuseRef,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseId,\n\tforwardRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tHandlePosition,\n\tStencilProps,\n\tSize,\n\tNormalizedRect,\n} from '../../core/types';\nimport type { CropperController } from '../hooks/use-cropper-reducer';\nimport { getImageFit, getRotatedBBox, getViewScale } from '../../core/camera';\nimport { getImageCropBounds, getMinZoom } from '../../core/containment';\nimport {\n\tMAX_VIEW_SCALE,\n\tPIXEL_SNAP_DISPLAY_SCALE,\n\tSETTLE_TARGET_CANVAS_FILL,\n} from '../../core/constants';\nimport { computeInscribedRect } from '../../core/crop-rect';\nimport { getMinCropPixels } from '../../core/stencil-math';\nimport { useInteraction } from '../hooks/use-interaction';\nimport { useTransformStyle } from '../hooks/use-transform-style';\nimport { useAriaAnnouncer } from '../hooks/use-aria-announcer';\nimport { RectangleStencil } from './stencils/rectangle-stencil';\nimport { DimmingOverlay } from './overlays/dimming-overlay';\nimport { GridOverlay } from './overlays/grid-overlay';\nimport { DimensionsOverlay } from './overlays/dimensions-overlay';\nimport {\n\tgetSourceRegion,\n\tsnapCropRectToSourcePixelGrid,\n\tsnapCropRectToSourcePixels,\n} from '../../core/source-region';\nimport { ViewportProvider, useViewport } from './viewport-provider';\nimport { VISUALLY_HIDDEN_STYLE } from '../visually-hidden-style';\n\n/** Threshold for comparing normalized crop rect values. */\nconst CROP_RECT_EPSILON = 1e-6;\n/** Threshold for deciding whether rotation is at a 90-degree stop. */\nconst CARDINAL_ROTATION_EPSILON = 1e-6;\n/** Duration of the settle transform transition after resize end. */\nconst SETTLE_TRANSITION_DURATION_MS = 200;\n// Fallback timer for when the computed transform is unchanged and no\n// `transitionend` fires. Sits past the CSS duration so it only wins the race\n// when the transition genuinely never runs.\nconst SETTLE_TRANSITION_FALLBACK_MS = SETTLE_TRANSITION_DURATION_MS + 100;\nconst SETTLE_TRANSFORM_TRANSITION = `transform ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`;\nconst SETTLE_STENCIL_TRANSITION = [\n\t`left ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,\n\t`top ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,\n\t`width ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,\n\t`height ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,\n].join( ', ' );\n\n/**\n * Props for the Cropper component.\n */\nexport interface CropperProps {\n\t/** Image source URL. */\n\tsrc: string;\n\t/** The cropper controller from `useCropperReducer` or a composite store. */\n\tcontroller: CropperController;\n\t/** Stencil component for the crop area. Defaults to RectangleStencil. */\n\tstencil?: React.ComponentType< StencilProps >;\n\t/** Show the rule-of-thirds grid overlay, or only during interactions. */\n\tshowGrid?: boolean | 'interactive';\n\t/** Whether external placement activity should keep the grid visible. */\n\tisPlacementActive?: boolean;\n\t/** Show the dimming overlay outside the crop area. */\n\tshowDimming?: boolean;\n\t/** Show the live output dimensions tooltip during a resize. */\n\tshowDimensions?: boolean;\n\t/** Minimum zoom level override. Defaults to the coverage-aware minimum. */\n\tminZoom?: number;\n\t/** Maximum zoom level. */\n\tmaxZoom?: number;\n\t/** Fixed aspect ratio (width / height) in pixel space for the crop area. */\n\taspectRatio?: number;\n\t/**\n\t * Enable freeform crop mode with resizable handles.\n\t * When false (default), the crop area is fixed and centered.\n\t * When true, the crop area has resize handles and can be freely repositioned.\n\t */\n\tfreeformCrop?: boolean;\n\t/** Focus the crop area when the cropper mounts. */\n\tfocusOnMount?: boolean;\n\t/** Callback fired when the image is loaded. */\n\tonImageLoaded?: ( size: Size ) => void;\n\t/**\n\t * Callback fired on every state change. Fires at pointermove rate\n\t * during drags, so keep the handler light — no heavy work, no\n\t * expensive parent re-renders. For commit-style events (drag end,\n\t * settled crop), use `onGestureEnd` instead.\n\t *\n\t * Useful for lightweight syncing with external tools, analytics,\n\t * or AI agents. Receives the full state so consumers can derive\n\t * whatever they need.\n\t */\n\tonStateChange?: ( state: CropperState ) => void;\n\t/** Fires when a continuous gesture begins (pan drag, handle resize, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointerup, resize settle). */\n\tonGestureEnd?: () => void;\n\t/** Additional className for the container. */\n\tclassName?: string;\n}\n\n/**\n * The main image cropper component.\n *\n * Renders an image within a container with interactive crop overlays.\n * Creates the camera once per render via getImageFit, then passes\n * derived values to stencil, overlays, and interaction hooks.\n *\n * The component fills its parent container (100% width and height).\n * Wrap it in a sized container to control its dimensions.\n *\n * @param root0 Component props implementing CropperProps.\n * @param root0.src Image source URL.\n * @param root0.controller The cropper controller from `useCropperReducer` or a composite store.\n * @param root0.stencil Custom stencil component.\n * @param root0.showGrid Grid overlay mode: false | true | 'interactive'.\n * @param root0.isPlacementActive Keep grid visible during external placement activity.\n * @param root0.showDimming Show dimming overlay outside crop.\n * @param root0.showDimensions Show live dimensions tooltip during resize.\n * @param root0.minZoom Minimum zoom level override.\n * @param root0.maxZoom Maximum zoom level.\n * @param root0.aspectRatio Fixed aspect ratio (width/height).\n * @param root0.freeformCrop Enable resize handles.\n * @param root0.focusOnMount Focus the crop area on mount.\n * @param root0.onImageLoaded Image load callback.\n * @param root0.onStateChange Every-frame state callback.\n * @param root0.onGestureStart Gesture boundary start.\n * @param root0.onGestureEnd Gesture boundary end.\n * @param root0.className Additional CSS class.\n * @param ref Forwarded ref for the container div.\n */\nfunction CropperInner(\n\t{\n\t\tsrc,\n\t\tcontroller,\n\t\tstencil: StencilComponent = RectangleStencil,\n\t\tshowGrid = false,\n\t\tisPlacementActive = false,\n\t\tshowDimming = true,\n\t\tshowDimensions = true,\n\t\tminZoom,\n\t\tmaxZoom,\n\t\taspectRatio,\n\t\tfreeformCrop = false,\n\t\tfocusOnMount = false,\n\t\tonImageLoaded,\n\t\tonStateChange,\n\t\tonGestureStart,\n\t\tonGestureEnd,\n\t\tclassName,\n\t}: CropperProps,\n\tref: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst {\n\t\tstate,\n\t\tsetImage,\n\t\tsetCropRect,\n\t\tsettleCrop,\n\t\tsetVisualSize,\n\t\tadjustCropRectForViewport,\n\t} = controller;\n\tconst {\n\t\tviewport: viewportState,\n\t\tsetViewportPan,\n\t\tresetViewport,\n\t} = useViewport();\n\t// Canvas measurement via ResizeObserver. The canvas is the inner\n\t// positioning context for image/stencil/handles — inset from the root\n\t// by the handle gutter, so crop math operates on the reduced box.\n\tconst canvasRef = useRef< HTMLDivElement >( null );\n\tconst cropAreaDescriptionId = useId();\n\tconst [ isCropAreaFocused, setIsCropAreaFocused ] =\n\t\tuseState( focusOnMount );\n\tconst [ isFocusVisible, setIsFocusVisible ] = useState( false );\n\tconst [ canvasSize, setCanvasSize ] = useState< Size >( {\n\t\twidth: 0,\n\t\theight: 0,\n\t} );\n\n\tuseLayoutEffect( () => {\n\t\tif ( focusOnMount ) {\n\t\t\tcanvasRef.current?.focus( { preventScroll: true } );\n\t\t}\n\t}, [ focusOnMount ] );\n\n\tconst handleCropAreaFocus = useCallback(\n\t\t( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tif ( target === event.currentTarget ) {\n\t\t\t\tsetIsCropAreaFocused( true );\n\t\t\t}\n\t\t\t// Show the outline only when focus arrived via keyboard\n\t\t\t// navigation. relatedTarget is null for pointer-initiated and\n\t\t\t// cross-window focus, so it reliably excludes those cases\n\t\t\t// without needing a separate ref or flag. Applies to focus\n\t\t\t// arriving on the canvas itself or on a descendant handle.\n\t\t\tif (\n\t\t\t\tevent.relatedTarget !== null &&\n\t\t\t\ttarget.matches( ':focus-visible' )\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( true );\n\t\t\t}\n\t\t},\n\t\t[]\n\t);\n\n\tconst handleCropAreaBlur = useCallback(\n\t\t( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.target === event.currentTarget ) {\n\t\t\t\tsetIsCropAreaFocused( false );\n\t\t\t}\n\t\t\t// Reset keyboard-active styling only when focus leaves the\n\t\t\t// cropper entirely. Moves between the canvas and a handle (or\n\t\t\t// between handles) keep the keyboard-active state intact.\n\t\t\tif (\n\t\t\t\t! event.currentTarget.contains(\n\t\t\t\t\tevent.relatedTarget as Node | null\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( false );\n\t\t\t}\n\t\t},\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\tconst element = canvasRef.current;\n\t\tif ( ! element ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new ResizeObserver( ( entries ) => {\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst { width, height } = entry.contentRect;\n\t\t\t\tsetCanvasSize( ( prev ) => {\n\t\t\t\t\tif ( prev.width === width && prev.height === height ) {\n\t\t\t\t\t\treturn prev;\n\t\t\t\t\t}\n\t\t\t\t\treturn { width, height };\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t\tobserver.observe( element );\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [] );\n\n\t// Notify consumer of state changes.\n\tuseEffect( () => {\n\t\tonStateChange?.( state );\n\t}, [ state, onStateChange ] );\n\n\t// ARIA announcements: announce significant state changes for screen readers\n\t// via the centralized @wordpress/a11y speak() API called inside the hook.\n\tuseAriaAnnouncer( state );\n\n\t// Compute fitted image dimensions and visual bounds from camera math.\n\tconst naturalWidth = state.image?.naturalWidth ?? 0;\n\tconst naturalHeight = state.image?.naturalHeight ?? 0;\n\tconst { elementSize, visualSize } = useMemo(\n\t\t() =>\n\t\t\tgetImageFit(\n\t\t\t\tcanvasSize,\n\t\t\t\t{ width: naturalWidth, height: naturalHeight },\n\t\t\t\tstate.rotation\n\t\t\t),\n\t\t[ canvasSize, naturalWidth, naturalHeight, state.rotation ]\n\t);\n\n\t// Report the rendered image size to the controller. Composite\n\t// controllers need it to compute aspect-ratio reshapes from the\n\t// reducer (the dropdown dispatches without DOM access); pure\n\t// controllers ignore it.\n\tuseEffect( () => {\n\t\tsetVisualSize( visualSize );\n\t}, [ visualSize, setVisualSize ] );\n\n\t// In fixed-crop mode, auto-size the crop rect only when a fixed\n\t// aspect ratio is selected. With \"Free\" selected, turning freeform\n\t// handles off should preserve the user's current unconstrained\n\t// crop. Uses `adjustCropRectForViewport` so window-resize-driven\n\t// reshapes don't create undo entries (composite controller); the\n\t// dedup at lines below avoids redundant dispatches when the\n\t// reducer has already updated the cropRect for an aspect change.\n\tuseEffect( () => {\n\t\tif (\n\t\t\tfreeformCrop ||\n\t\t\tvisualSize.width === 0 ||\n\t\t\tvisualSize.height === 0 ||\n\t\t\t! aspectRatio ||\n\t\t\taspectRatio <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = computeInscribedRect( aspectRatio, visualSize );\n\t\tconst current = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.height - rect.height ) < CROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tadjustCropRectForViewport( rect );\n\t}, [\n\t\tfreeformCrop,\n\t\taspectRatio,\n\t\tvisualSize,\n\t\tadjustCropRectForViewport,\n\t\tstate.cropRect,\n\t] );\n\n\t// In freeform mode, when aspectRatio changes, reshape the crop to\n\t// the largest inscribed rect of the new ratio. Bails out when the\n\t// cropRect already matches the inscribed rect — composite stores\n\t// reshape atomically inside the reducer, so this effect is a\n\t// no-op there.\n\tconst prevAspectRatioRef = useRef( aspectRatio );\n\tuseEffect( () => {\n\t\tif ( prevAspectRatioRef.current === aspectRatio ) {\n\t\t\treturn;\n\t\t}\n\t\tprevAspectRatioRef.current = aspectRatio;\n\n\t\tif (\n\t\t\t! freeformCrop ||\n\t\t\tvisualSize.width === 0 ||\n\t\t\tvisualSize.height === 0 ||\n\t\t\t! aspectRatio ||\n\t\t\taspectRatio <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = computeInscribedRect( aspectRatio, visualSize );\n\t\tconst current = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.height - rect.height ) < CROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tadjustCropRectForViewport( rect );\n\t}, [\n\t\taspectRatio,\n\t\tfreeformCrop,\n\t\tvisualSize,\n\t\tadjustCropRectForViewport,\n\t\tstate.cropRect,\n\t] );\n\n\t// Compute the crop handle bounds from the actual image footprint.\n\t// Depends on the full state object because getImageCropBounds reads\n\t// crop, zoom, rotation, flip, and image. React Compiler requires\n\t// the complete dependency; the computation is lightweight (a few\n\t// trig ops + 4 corner transforms).\n\tconst cropBounds = useMemo( () => {\n\t\tif ( ! state.image || elementSize.width === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn getImageCropBounds( state, elementSize, visualSize );\n\t}, [ state, elementSize, visualSize ] );\n\tconst effectiveMinZoom =\n\t\tminZoom !== undefined ? minZoom : getMinZoom( state );\n\tconst [ isResizing, setIsResizing ] = useState( false );\n\tconst isResizingRef = useRef( false );\n\tconst isSettlingRef = useRef( false );\n\tconst [ isTouchPinching, setIsTouchPinchingState ] = useState( false );\n\tconst isTouchPinchingRef = useRef( false );\n\tconst setTouchPinching = useCallback( ( isPinching: boolean ) => {\n\t\tisTouchPinchingRef.current = isPinching;\n\t\tsetIsTouchPinchingState( isPinching );\n\t}, [] );\n\t// Direction of the handle the user is currently resizing — pointer or\n\t// keyboard. `null` outside of an active resize. Drives the live\n\t// dimensions tooltip overlay.\n\tconst [ activeHandle, setActiveHandle ] = useState< HandlePosition | null >(\n\t\tnull\n\t);\n\n\t// Presentational magnification so the at-rest crop fills the canvas. The\n\t// crop overlay is laid out as `cropRect * visualSize` (the contain-fit\n\t// footprint, no zoom), so a crop whose aspect differs from the image's can\n\t// render far smaller than the canvas allows. Scaling `elementSize` and\n\t// `visualSize` together magnifies the whole scene uniformly — image,\n\t// overlays, and the pixel->normalized interaction math — and the root's\n\t// `overflow: hidden` clips the image bleed. Magnifying around the footprint\n\t// centre keeps the crop centred only because the at-rest crop is always\n\t// centred (SETTLE_CROP, computeInscribedRect, and the initial full-frame\n\t// crop all centre it).\n\tconst viewScaleRest = useMemo(\n\t\t() =>\n\t\t\tgetViewScale(\n\t\t\t\tstate.cropRect,\n\t\t\t\tcanvasSize,\n\t\t\t\tvisualSize,\n\t\t\t\tSETTLE_TARGET_CANVAS_FILL,\n\t\t\t\tMAX_VIEW_SCALE\n\t\t\t),\n\t\t[ state.cropRect, canvasSize, visualSize ]\n\t);\n\t// During a resize the magnification is frozen at its pre-drag value rather\n\t// than recomputed per pointer move: recomputing live would zoom the scene\n\t// under the cursor, and snapping to 1 would reset the zoom the moment a\n\t// handle is grabbed. `handleResizeStart` snapshots the current rest value\n\t// into `frozenViewScale`; on release the settle recomputes from the new crop.\n\tconst [ frozenViewScale, setFrozenViewScale ] = useState( 1 );\n\tconst viewScale = isResizing ? frozenViewScale : viewScaleRest;\n\tconst scaledVisualSize = useMemo(\n\t\t() => ( {\n\t\t\twidth: visualSize.width * viewScale,\n\t\t\theight: visualSize.height * viewScale,\n\t\t} ),\n\t\t[ visualSize.width, visualSize.height, viewScale ]\n\t);\n\t// CSS pixels rendered per source pixel: the contain fit\n\t// (elementSize / natural), times zoom and the view-scale magnification.\n\tconst displayScale =\n\t\tnaturalWidth > 0\n\t\t\t? ( elementSize.width / naturalWidth ) * state.zoom * viewScale\n\t\t\t: 0;\n\tconst keyboardResizeStep = useMemo( () => {\n\t\tif (\n\t\t\tdisplayScale < PIXEL_SNAP_DISPLAY_SCALE ||\n\t\t\t( aspectRatio && aspectRatio > 0 ) ||\n\t\t\tnaturalWidth <= 0 ||\n\t\t\tnaturalHeight <= 0\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\t\tif (\n\t\t\tMath.abs( state.rotation - snapRotation ) >=\n\t\t\tCARDINAL_ROTATION_EPSILON\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst bbox = getRotatedBBox(\n\t\t\tnaturalWidth,\n\t\t\tnaturalHeight,\n\t\t\tsnapRotation\n\t\t);\n\t\tif ( bbox.width <= 0 || bbox.height <= 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\t// Keyboard steps are normalized crop-space deltas, but snapping wants\n\t\t// one source pixel per key press. The normalized delta for one source\n\t\t// pixel is different on each axis when the snap-rotation bbox is not\n\t\t// square, so this must be an object with separate width/height steps\n\t\t// instead of a single scalar.\n\t\treturn {\n\t\t\twidth: state.zoom / bbox.width,\n\t\t\theight: state.zoom / bbox.height,\n\t\t};\n\t}, [\n\t\tdisplayScale,\n\t\taspectRatio,\n\t\tnaturalWidth,\n\t\tnaturalHeight,\n\t\tstate.rotation,\n\t\tstate.zoom,\n\t] );\n\n\t// Per-axis minimum crop size in normalized space, expressing a pixel floor\n\t// on the captured source region. cropRect is normalized in the viewport's\n\t// snap-rotation bbox; the captured source-pixel width is\n\t// `cropRect.width * bbox.width / zoom`, so the normalized floor scales with\n\t// `zoom` to keep the source-pixel floor constant. The floor itself adapts to\n\t// the on-screen display scale (fit × zoom × view scale) via\n\t// `getMinCropPixels`, so on a large image shown small the crop can't shrink\n\t// until the handles collapse — it yields to the 24px source floor only once\n\t// the image is shown large enough.\n\tconst minCropSize: Size | undefined = useMemo( () => {\n\t\tif ( naturalWidth <= 0 || naturalHeight <= 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\t\tconst bbox = getRotatedBBox(\n\t\t\tnaturalWidth,\n\t\t\tnaturalHeight,\n\t\t\tsnapRotation\n\t\t);\n\t\tconst minPixels = getMinCropPixels( displayScale );\n\t\treturn {\n\t\t\twidth: Math.min( 1, ( minPixels * state.zoom ) / bbox.width ),\n\t\t\theight: Math.min( 1, ( minPixels * state.zoom ) / bbox.height ),\n\t\t};\n\t}, [\n\t\tnaturalWidth,\n\t\tnaturalHeight,\n\t\tstate.rotation,\n\t\tstate.zoom,\n\t\tdisplayScale,\n\t] );\n\n\tconst snapCropRect = useCallback(\n\t\t( rect: NormalizedRect, handle: HandlePosition ): NormalizedRect => {\n\t\t\tif (\n\t\t\t\tdisplayScale < PIXEL_SNAP_DISPLAY_SCALE ||\n\t\t\t\tnaturalWidth <= 0 ||\n\t\t\t\tnaturalHeight <= 0\n\t\t\t) {\n\t\t\t\treturn rect;\n\t\t\t}\n\t\t\treturn snapCropRectToSourcePixels(\n\t\t\t\tstate,\n\t\t\t\t{ width: naturalWidth, height: naturalHeight },\n\t\t\t\trect,\n\t\t\t\thandle\n\t\t\t);\n\t\t},\n\t\t[ displayScale, naturalWidth, naturalHeight, state ]\n\t);\n\n\tconst wasPixelSnapEnabledRef = useRef( false );\n\tuseEffect( () => {\n\t\tconst isPixelSnapEnabled =\n\t\t\tfreeformCrop &&\n\t\t\t( ! aspectRatio || aspectRatio <= 0 ) &&\n\t\t\tdisplayScale >= PIXEL_SNAP_DISPLAY_SCALE &&\n\t\t\tnaturalWidth > 0 &&\n\t\t\tnaturalHeight > 0;\n\t\tconst wasPixelSnapEnabled = wasPixelSnapEnabledRef.current;\n\t\twasPixelSnapEnabledRef.current = isPixelSnapEnabled;\n\n\t\tif ( ! isPixelSnapEnabled || wasPixelSnapEnabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst snappedCropRect = snapCropRectToSourcePixelGrid(\n\t\t\tstate,\n\t\t\t{ width: naturalWidth, height: naturalHeight },\n\t\t\tstate.cropRect\n\t\t);\n\t\tconst currentCropRect = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( currentCropRect.x - snappedCropRect.x ) <\n\t\t\t\tCROP_RECT_EPSILON &&\n\t\t\tMath.abs( currentCropRect.y - snappedCropRect.y ) <\n\t\t\t\tCROP_RECT_EPSILON &&\n\t\t\tMath.abs( currentCropRect.width - snappedCropRect.width ) <\n\t\t\t\tCROP_RECT_EPSILON &&\n\t\t\tMath.abs( currentCropRect.height - snappedCropRect.height ) <\n\t\t\t\tCROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetCropRect( snappedCropRect );\n\t}, [\n\t\taspectRatio,\n\t\tdisplayScale,\n\t\tfreeformCrop,\n\t\tnaturalWidth,\n\t\tnaturalHeight,\n\t\tsetCropRect,\n\t\tstate,\n\t] );\n\n\t// Use the interaction hook for mouse, touch, and keyboard events.\n\tconst {\n\t\thandlers,\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isInteractionPlacementActive,\n\t} = useInteraction( state, controller, canvasSize, scaledVisualSize, {\n\t\tminZoom: effectiveMinZoom,\n\t\tmaxZoom,\n\t\tonGestureStart,\n\t\tonGestureEnd,\n\t} );\n\n\t// Compose focus-visibility tracking into the canvas event handlers.\n\t// Kept as a spread rather than explicit props to avoid triggering\n\t// jsx-a11y/no-noninteractive-element-interactions on role=\"group\".\n\t//\n\t// The pointer/key tracking lives in the capture phase so it runs\n\t// before any child handler — handles call stopPropagation in their\n\t// own onPointerDown / onKeyDown, which would otherwise prevent the\n\t// keyboard-active state from updating when the user interacts with\n\t// a handle directly.\n\tconst canvasHandlers = {\n\t\t...handlers,\n\t\tonPointerDownCapture: () => {\n\t\t\tsetIsFocusVisible( false );\n\t\t},\n\t\tonTouchStartCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.touches.length > 1 ) {\n\t\t\t\tsetTouchPinching( true );\n\t\t\t}\n\t\t},\n\t\tonTouchMoveCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.touches.length > 1 ) {\n\t\t\t\tsetTouchPinching( true );\n\t\t\t}\n\t\t},\n\t\tonTouchEndCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.touches.length === 0 ) {\n\t\t\t\tsetTouchPinching( false );\n\t\t\t}\n\t\t},\n\t\tonTouchCancelCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.touches.length === 0 ) {\n\t\t\t\tsetTouchPinching( false );\n\t\t\t}\n\t\t},\n\t\tonKeyDownCapture: ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t\t// Modifier-only keypresses precede another key rather than\n\t\t\t// indicating deliberate keyboard interaction on their own.\n\t\t\tif (\n\t\t\t\t! [ 'Shift', 'Control', 'Alt', 'Meta' ].includes( event.key )\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( true );\n\t\t\t}\n\t\t},\n\t\tonPointerDown: ( event: React.PointerEvent< HTMLDivElement > ) => {\n\t\t\tif (\n\t\t\t\tisResizingRef.current ||\n\t\t\t\tisTouchPinchingRef.current ||\n\t\t\t\t( event.pointerType === 'touch' && event.isPrimary === false )\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\thandlers.onPointerDown?.( event );\n\t\t\t// Re-assert false after handlers run — el.focus() inside the\n\t\t\t// handler fires onFocus, which may otherwise set it back to true.\n\t\t\tsetIsFocusVisible( false );\n\t\t},\n\t};\n\n\t// Register wheel handler natively with { passive: false } so\n\t// preventDefault works. React's onWheel registers as passive. Bound\n\t// to the canvas (not the root) so pointer geometry inside the handler\n\t// resolves against the canvas box.\n\tuseEffect( () => {\n\t\tconst el = canvasRef.current;\n\t\tif ( ! el ) {\n\t\t\treturn;\n\t\t}\n\t\tconst handleWheel = ( event: WheelEvent ) => {\n\t\t\t// Block wheel zoom while resizing or settling — the stage CSS\n\t\t\t// transform changes getBoundingClientRect() during this window,\n\t\t\t// so focal-point math would resolve against the wrong center.\n\t\t\tif ( isResizingRef.current || isSettlingRef.current ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tonWheelNative( event );\n\t\t};\n\t\tel.addEventListener( 'wheel', handleWheel, {\n\t\t\tpassive: false,\n\t\t} );\n\t\treturn () => {\n\t\t\tel.removeEventListener( 'wheel', handleWheel );\n\t\t};\n\t}, [ onWheelNative ] );\n\n\t// Use the unscaled contain-fit footprint here. `imageStyle` prepends\n\t// `scale(viewScale)` to this matrix, so pan translations are magnified with\n\t// the rest of the scene; using `scaledVisualSize` here would apply viewScale\n\t// to pan twice.\n\tconst transformString = useTransformStyle( state, visualSize );\n\n\t/**\n\t * Handle the image load event.\n\t */\n\tconst handleImageLoad = useCallback(\n\t\t( event: React.SyntheticEvent< HTMLImageElement > ) => {\n\t\t\tconst img = event.currentTarget;\n\t\t\tconst size: Size = {\n\t\t\t\twidth: img.naturalWidth,\n\t\t\t\theight: img.naturalHeight,\n\t\t\t};\n\n\t\t\tsetImage( {\n\t\t\t\tsrc,\n\t\t\t\tnaturalWidth: size.width,\n\t\t\t\tnaturalHeight: size.height,\n\t\t\t} );\n\n\t\t\tonImageLoaded?.( size );\n\t\t},\n\t\t[ src, setImage, onImageLoaded ]\n\t);\n\n\tconst handleCropChange = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tif ( isTouchPinchingRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetCropRect( rect );\n\t\t\t// During a resize drag, pan the viewport so the handle stays\n\t\t\t// visible even when the crop extends beyond the canvas edge.\n\t\t\tif (\n\t\t\t\tisResizingRef.current &&\n\t\t\t\tscaledVisualSize.width > 0 &&\n\t\t\t\tscaledVisualSize.height > 0\n\t\t\t) {\n\t\t\t\tconst offsetX =\n\t\t\t\t\t( canvasSize.width - scaledVisualSize.width ) / 2;\n\t\t\t\tconst offsetY =\n\t\t\t\t\t( canvasSize.height - scaledVisualSize.height ) / 2;\n\t\t\t\tconst rightOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\toffsetX +\n\t\t\t\t\t\t( rect.x + rect.width ) * scaledVisualSize.width -\n\t\t\t\t\t\tcanvasSize.width\n\t\t\t\t);\n\t\t\t\tconst leftOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\t-( offsetX + rect.x * scaledVisualSize.width )\n\t\t\t\t);\n\t\t\t\tconst bottomOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\toffsetY +\n\t\t\t\t\t\t( rect.y + rect.height ) * scaledVisualSize.height -\n\t\t\t\t\t\tcanvasSize.height\n\t\t\t\t);\n\t\t\t\tconst topOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\t-( offsetY + rect.y * scaledVisualSize.height )\n\t\t\t\t);\n\t\t\t\tsetViewportPan( {\n\t\t\t\t\tx: -rightOverflow + leftOverflow,\n\t\t\t\t\ty: -bottomOverflow + topOverflow,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ setCropRect, setViewportPan, canvasSize, scaledVisualSize ]\n\t);\n\n\t// Settling animation: brief transition after resize end.\n\tconst [ settling, setSettling ] = useState( false );\n\tconst settleTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\tconst finishSettling = useCallback( () => {\n\t\tclearTimeout( settleTimerRef.current );\n\t\tisSettlingRef.current = false;\n\t\tsetSettling( false );\n\t}, [] );\n\n\t// Clear the pending settle timer on unmount so it can't fire a\n\t// state update on an unmounted component.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( settleTimerRef.current );\n\t\t};\n\t}, [] );\n\n\tconst isInteractiveGrid = showGrid === 'interactive';\n\tconst showInteractiveGrid =\n\t\tisInteractiveGrid &&\n\t\t( isInteractionPlacementActive || isResizing || isPlacementActive );\n\n\t// Output crop size in source pixels — drives the live tooltip\n\t// overlay. Only computed during pointer drags, so the per-frame\n\t// state churn during pan/zoom doesn't pay for it.\n\tconst outputSize = useMemo( () => {\n\t\tif ( ! showDimensions || ! activeHandle || ! state.image ) {\n\t\t\treturn null;\n\t\t}\n\t\tconst region = getSourceRegion( state, {\n\t\t\twidth: state.image.naturalWidth,\n\t\t\theight: state.image.naturalHeight,\n\t\t} );\n\t\treturn { width: region.width, height: region.height };\n\t}, [ showDimensions, activeHandle, state ] );\n\n\t/**\n\t * Handle Escape on a resize handle — return focus to the canvas so\n\t * arrow keys pan the image rather than resize.\n\t */\n\tconst handleEscape = useCallback( () => {\n\t\t// Escape is always a keyboard action, so show the outline immediately\n\t\t// rather than relying on the focus handler's :focus-visible check.\n\t\tsetIsFocusVisible( true );\n\t\tcanvasRef.current?.focus( { preventScroll: true } );\n\t}, [] );\n\n\tconst handleResizeStart = useCallback(\n\t\t( handle?: HandlePosition ) => {\n\t\t\tif ( isTouchPinchingRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Freeze the magnification at its current value so grabbing a\n\t\t\t// handle doesn't reset the zoom; it holds for the whole drag.\n\t\t\tsetFrozenViewScale( viewScaleRest );\n\t\t\tisResizingRef.current = true;\n\t\t\tsetIsResizing( true );\n\t\t\tsetActiveHandle( handle ?? null );\n\t\t\t// Clear any in-flight settle so transitions don't apply during the\n\t\t\t// new drag (rapid successive resizes would otherwise inherit the\n\t\t\t// previous settle animation).\n\t\t\tfinishSettling();\n\t\t\tresetViewport();\n\t\t\tonGestureStart?.();\n\t\t},\n\t\t[ finishSettling, onGestureStart, resetViewport, viewScaleRest ]\n\t);\n\n\t/**\n\t * Handle resize end — settle the crop rect (re-center, fill height)\n\t * and reset the viewport pan back to neutral.\n\t */\n\tconst handleResizeEnd = useCallback( () => {\n\t\tconst isCancellingForPinch = isTouchPinchingRef.current;\n\t\tisResizingRef.current = false;\n\t\tsetIsResizing( false );\n\t\tsetActiveHandle( null );\n\t\tclearTimeout( settleTimerRef.current );\n\n\t\tif ( isCancellingForPinch ) {\n\t\t\t// A pinch took over mid-resize. Tear down resize UI without\n\t\t\t// settling or firing onGestureEnd: the pinch owns the gesture\n\t\t\t// boundary and fires the end on its own touchend. The resize and\n\t\t\t// the pinch therefore collapse into a single undo step, since\n\t\t\t// `beginGesture` is idempotent and the snapshot captured at resize\n\t\t\t// start is flushed by the pinch's `endGesture`.\n\t\t\tfinishSettling();\n\t\t\tresetViewport();\n\t\t\treturn;\n\t\t}\n\n\t\tisSettlingRef.current = true;\n\t\tsetSettling( true );\n\t\t// Reset viewport pan first so it transitions back to zero in sync\n\t\t// with the settle animation on the image.\n\t\tresetViewport();\n\t\tsettleCrop();\n\t\tonGestureEnd?.();\n\t\t// Normal completion is driven by transitionend so settling cannot clear\n\t\t// before the browser has actually finished animating. Keep a fallback for\n\t\t// cases where the computed transform is unchanged and no event fires.\n\t\tsettleTimerRef.current = setTimeout(\n\t\t\tfinishSettling,\n\t\t\tSETTLE_TRANSITION_FALLBACK_MS\n\t\t);\n\t}, [ finishSettling, settleCrop, onGestureEnd, resetViewport ] );\n\n\t/**\n\t * Finish settling when the settle transform transition actually completes.\n\t * The handler lives on the stage, but in the common (un-panned) case the\n\t * transform transition runs on the image layer and its `transitionend`\n\t * bubbles up to here. Other transitionend events (stencil left/top/width/\n\t * height) also bubble up, so only the transform transition should clear the\n\t * settle state.\n\t */\n\tconst handleSettleTransitionEnd = useCallback(\n\t\t( event: React.TransitionEvent< HTMLDivElement > ) => {\n\t\t\tif (\n\t\t\t\t! isSettlingRef.current ||\n\t\t\t\tevent.propertyName !== 'transform'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfinishSettling();\n\t\t},\n\t\t[ finishSettling ]\n\t);\n\n\tlet imageTransition: string | undefined;\n\tif ( settling ) {\n\t\timageTransition = SETTLE_TRANSFORM_TRANSITION;\n\t} else if ( isZooming ) {\n\t\timageTransition = 'transform 150ms linear';\n\t}\n\tconst settleStencilTransition = settling\n\t\t? SETTLE_STENCIL_TRANSITION\n\t\t: undefined;\n\n\t// Compute the image's CSS style. The element keeps its contain-fit box; the\n\t// view-scale magnification is folded into the transform as an outer\n\t// `scale()` so the whole settle motion (zoom, pan, and magnification) is one\n\t// coherent transform that interpolates as a unit — the image slides/scales\n\t// to its position rather than animating its box separately. Magnifying\n\t// around the centred box keeps the (centred) crop centred.\n\tconst imageStyle = useMemo( (): React.CSSProperties => {\n\t\tif ( elementSize.width === 0 || elementSize.height === 0 ) {\n\t\t\treturn {};\n\t\t}\n\t\tconst centerX = ( canvasSize.width - elementSize.width ) / 2;\n\t\tconst centerY = ( canvasSize.height - elementSize.height ) / 2;\n\t\t// Above 1:1 the image is upscaled, so render nearest-neighbour to keep\n\t\t// pixel boundaries crisp (e.g. small images the cropper magnifies);\n\t\t// below 1:1 leave smoothing on for downscaled large images.\n\t\treturn {\n\t\t\twidth: elementSize.width,\n\t\t\theight: elementSize.height,\n\t\t\tmaxWidth: elementSize.width,\n\t\t\tmaxHeight: elementSize.height,\n\t\t\tleft: centerX,\n\t\t\ttop: centerY,\n\t\t\t// Always lead with `scale()` (identity at rest) so the transform's\n\t\t\t// function list stays structurally constant across rest, resize, and\n\t\t\t// settle. A conditional that dropped `scale()` at viewScale === 1\n\t\t\t// would change the list shape exactly when the settle transition\n\t\t\t// crosses 1:1, forcing the browser to fall back to matrix-decomposition\n\t\t\t// interpolation instead of interpolating each function in turn.\n\t\t\ttransform: `scale(${ viewScale }) ${ transformString }`,\n\t\t\ttransition: imageTransition,\n\t\t\timageRendering: displayScale > 1 ? 'pixelated' : undefined,\n\t\t};\n\t}, [\n\t\tcanvasSize,\n\t\telementSize,\n\t\ttransformString,\n\t\timageTransition,\n\t\tdisplayScale,\n\t\tviewScale,\n\t] );\n\n\t// Viewport pan CSS transform for the stage div. Applied during resize\n\t// drags to keep handles visible when the crop extends past the canvas edge.\n\t// Transitions back to zero during the settle animation.\n\t// will-change promotes the stage to its own compositor layer while the\n\t// transform is active, keeping per-frame pan updates off the main thread.\n\tconst settleTransition = settling ? SETTLE_TRANSFORM_TRANSITION : undefined;\n\tconst willChange = isResizing || settling ? 'transform' : undefined;\n\tlet stageStyle: React.CSSProperties | undefined;\n\tif ( viewportState.pan.x !== 0 || viewportState.pan.y !== 0 ) {\n\t\tstageStyle = {\n\t\t\ttransform: `translate(${ viewportState.pan.x }px, ${ viewportState.pan.y }px)`,\n\t\t\ttransition: settleTransition,\n\t\t\twillChange,\n\t\t};\n\t} else if ( settling ) {\n\t\t// Animate the viewport pan back to an explicit identity translate rather\n\t\t// than dropping the transform property, so the reset eases instead of\n\t\t// snapping (transitions to a removed transform are unreliable).\n\t\tstageStyle = {\n\t\t\ttransform: 'translate(0px, 0px)',\n\t\t\ttransition: settleTransition,\n\t\t\twillChange,\n\t\t};\n\t}\n\n\t// Forward the root element to the consumer's ref.\n\tconst setContainerRef = useCallback(\n\t\t( element: HTMLDivElement | null ) => {\n\t\t\tif ( typeof ref === 'function' ) {\n\t\t\t\tref( element );\n\t\t\t} else if ( ref ) {\n\t\t\t\t(\n\t\t\t\t\tref as React.MutableRefObject< HTMLDivElement | null >\n\t\t\t\t ).current = element;\n\t\t\t}\n\t\t},\n\t\t[ ref ]\n\t);\n\n\treturn (\n\t\t<div\n\t\t\tref={ setContainerRef }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wp-media-editor-image-editor',\n\t\t\t\tisDragging && 'wp-media-editor-image-editor--dragging',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t>\n\t\t\t{ /*\n\t\t\t * The canvas is the interactive, inset surface. Handles and\n\t\t\t * the ARIA role/tabIndex live here so pointer geometry\n\t\t\t * (getBoundingClientRect on e.currentTarget) resolves against\n\t\t\t * the same box that crop math uses. The root stays as the\n\t\t\t * clipping shell for the dimming overlay's box-shadow.\n\t\t\t *\n\t\t\t * Not role=\"application\" — that disables the screen reader's\n\t\t\t * normal keyboard interception, too heavy-handed for a single\n\t\t\t * widget. Screen reader users get the ARIA live region below\n\t\t\t * as the announcement channel.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tref={ canvasRef }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wp-media-editor-image-editor__canvas',\n\t\t\t\t\tisInteractiveGrid &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--grid-interactive',\n\t\t\t\t\tshowInteractiveGrid &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--show-grid',\n\t\t\t\t\tsettling &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--settling',\n\t\t\t\t\t// Marks the cropper as in keyboard-interaction mode.\n\t\t\t\t\t// CSS uses :focus on the canvas to show the stencil\n\t\t\t\t\t// outline and :focus on a handle to show its ring,\n\t\t\t\t\t// so the class applies whenever any cropper element\n\t\t\t\t\t// has keyboard focus.\n\t\t\t\t\tisFocusVisible &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--focus-visible'\n\t\t\t\t) }\n\t\t\t\ttabIndex={ 0 }\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={ __( 'Crop area' ) }\n\t\t\t\taria-describedby={\n\t\t\t\t\tisCropAreaFocused ? cropAreaDescriptionId : undefined\n\t\t\t\t}\n\t\t\t\tonFocus={ handleCropAreaFocus }\n\t\t\t\tonBlur={ handleCropAreaBlur }\n\t\t\t\t{ ...canvasHandlers }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tid={ cropAreaDescriptionId }\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ /*\n\t\t\t\t * The stage is an inner full-size div that receives the\n\t\t\t\t * viewport pan CSS transform. Keeping the transform here\n\t\t\t\t * (rather than on the canvas) means the canvas always stays\n\t\t\t\t * at its natural position, so the root div's background is\n\t\t\t\t * never exposed when the stage is panned during a resize drag.\n\t\t\t\t */ }\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"wp-media-editor-image-editor__stage\"\n\t\t\t\t\tdata-testid=\"cropper-stage\"\n\t\t\t\t\tstyle={ stageStyle }\n\t\t\t\t\tonTransitionEnd={ handleSettleTransitionEnd }\n\t\t\t\t>\n\t\t\t\t\t{ /* The image layer */ }\n\t\t\t\t\t<img\n\t\t\t\t\t\tclassName=\"wp-media-editor-image-editor__image\"\n\t\t\t\t\t\tdata-testid=\"cropper-image\"\n\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tonLoad={ handleImageLoad }\n\t\t\t\t\t\tstyle={ imageStyle }\n\t\t\t\t\t\tdraggable={ false }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ /* Dimming overlay outside the crop area */ }\n\t\t\t\t\t{ showDimming && (\n\t\t\t\t\t\t<DimmingOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ scaledVisualSize }\n\t\t\t\t\t\t\ttransition={ settleStencilTransition }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ /* The stencil (crop area with handles) */ }\n\t\t\t\t\t<StencilComponent\n\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\timageSize={ scaledVisualSize }\n\t\t\t\t\t\tonCropChange={ handleCropChange }\n\t\t\t\t\t\tonResizeStart={ handleResizeStart }\n\t\t\t\t\t\tonResizeEnd={ handleResizeEnd }\n\t\t\t\t\t\tonEscape={ handleEscape }\n\t\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\t\tfreeformCrop={ freeformCrop }\n\t\t\t\t\t\tisResizeDisabled={ isTouchPinching }\n\t\t\t\t\t\tstencilTransition={ settleStencilTransition }\n\t\t\t\t\t\tcropBounds={ cropBounds }\n\t\t\t\t\t\tminCropSize={ minCropSize }\n\t\t\t\t\t\tsnapCropRect={ snapCropRect }\n\t\t\t\t\t\tkeyboardResizeStep={ keyboardResizeStep }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ /* Rule-of-thirds grid */ }\n\t\t\t\t\t{ ( showGrid === true || isInteractiveGrid ) && (\n\t\t\t\t\t\t<GridOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ scaledVisualSize }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ /* Live dimensions tooltip pinned to the dragged handle. */ }\n\t\t\t\t\t{ activeHandle && outputSize && (\n\t\t\t\t\t\t<DimensionsOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ scaledVisualSize }\n\t\t\t\t\t\t\tactiveHandle={ activeHandle }\n\t\t\t\t\t\t\toutputWidth={ outputSize.width }\n\t\t\t\t\t\t\toutputHeight={ outputSize.height }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nconst CropperInnerWithRef = forwardRef< HTMLDivElement, CropperProps >(\n\tCropperInner\n);\n\nexport const Cropper = forwardRef< HTMLDivElement, CropperProps >(\n\t( props, ref ) => (\n\t\t<ViewportProvider>\n\t\t\t<CropperInnerWithRef { ...props } ref={ ref } />\n\t\t</ViewportProvider>\n\t)\n);\n"],
|
|
5
|
-
"mappings": ";AAIA,OAAO,UAAU;AAKjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AAanB,SAAS,aAAa,gBAAgB,oBAAoB;AAC1D,SAAS,oBAAo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AQ,KAAY,GAC/C;AAEF;",
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport {\n\tuseState,\n\tuseCallback,\n\tuseMemo,\n\tuseRef,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseId,\n\tforwardRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport type {\n\tCropperState,\n\tHandlePosition,\n\tStencilProps,\n\tSize,\n\tNormalizedRect,\n} from '../../core/types';\nimport type { CropperController } from '../hooks/use-cropper-reducer';\nimport { getImageFit, getRotatedBBox, getViewScale } from '../../core/camera';\nimport { getImageCropBounds, getMinZoom } from '../../core/containment';\nimport {\n\tMAX_VIEW_SCALE,\n\tPIXEL_SNAP_DISPLAY_SCALE,\n\tSETTLE_TARGET_CANVAS_FILL,\n} from '../../core/constants';\nimport { computeInscribedRect } from '../../core/crop-rect';\nimport { getMinCropPixels } from '../../core/stencil-math';\nimport { useInteraction } from '../hooks/use-interaction';\nimport { useTransformStyle } from '../hooks/use-transform-style';\nimport { useAriaAnnouncer } from '../hooks/use-aria-announcer';\nimport { RectangleStencil } from './stencils/rectangle-stencil';\nimport { DimmingOverlay } from './overlays/dimming-overlay';\nimport { GridOverlay } from './overlays/grid-overlay';\nimport { DimensionsOverlay } from './overlays/dimensions-overlay';\nimport {\n\tgetSourceRegion,\n\tsnapCropRectToSourcePixelGrid,\n\tsnapCropRectToSourcePixels,\n} from '../../core/source-region';\nimport { ViewportProvider, useViewport } from './viewport-provider';\nimport { VISUALLY_HIDDEN_STYLE } from '../visually-hidden-style';\n\n/** Threshold for comparing normalized crop rect values. */\nconst CROP_RECT_EPSILON = 1e-6;\n/** Threshold for deciding whether rotation is at a 90-degree stop. */\nconst CARDINAL_ROTATION_EPSILON = 1e-6;\n/** Duration of the settle transform transition after resize end. */\nconst SETTLE_TRANSITION_DURATION_MS = 200;\n// Fallback timer for when the computed transform is unchanged and no\n// `transitionend` fires. Sits past the CSS duration so it only wins the race\n// when the transition genuinely never runs.\nconst SETTLE_TRANSITION_FALLBACK_MS = SETTLE_TRANSITION_DURATION_MS + 100;\nconst SETTLE_TRANSFORM_TRANSITION = `transform ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`;\nconst SETTLE_STENCIL_TRANSITION = [\n\t`left ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,\n\t`top ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,\n\t`width ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,\n\t`height ${ SETTLE_TRANSITION_DURATION_MS }ms ease-out`,\n].join( ', ' );\n\n/**\n * Props for the Cropper component.\n */\nexport interface CropperProps {\n\t/** Image source URL. */\n\tsrc: string;\n\t/** The cropper controller from `useCropperReducer` or a composite store. */\n\tcontroller: CropperController;\n\t/** Stencil component for the crop area. Defaults to RectangleStencil. */\n\tstencil?: React.ComponentType< StencilProps >;\n\t/** Show the rule-of-thirds grid overlay, or only during interactions. */\n\tshowGrid?: boolean | 'interactive';\n\t/** Whether external placement activity should keep the grid visible. */\n\tisPlacementActive?: boolean;\n\t/** Show the dimming overlay outside the crop area. */\n\tshowDimming?: boolean;\n\t/** Show the live output dimensions tooltip during a resize. */\n\tshowDimensions?: boolean;\n\t/** Minimum zoom level override. Defaults to the coverage-aware minimum. */\n\tminZoom?: number;\n\t/** Maximum zoom level. */\n\tmaxZoom?: number;\n\t/** Fixed aspect ratio (width / height) in pixel space for the crop area. */\n\taspectRatio?: number;\n\t/**\n\t * Enable freeform crop mode with resizable handles.\n\t * When false (default), the crop area is fixed and centered.\n\t * When true, the crop area has resize handles and can be freely repositioned.\n\t */\n\tfreeformCrop?: boolean;\n\t/** Focus the crop area when the cropper mounts. */\n\tfocusOnMount?: boolean;\n\t/** Callback fired when the image is loaded. */\n\tonImageLoaded?: ( size: Size ) => void;\n\t/**\n\t * Callback fired on every state change. Fires at pointermove rate\n\t * during drags, so keep the handler light — no heavy work, no\n\t * expensive parent re-renders. For commit-style events (drag end,\n\t * settled crop), use `onGestureEnd` instead.\n\t *\n\t * Useful for lightweight syncing with external tools, analytics,\n\t * or AI agents. Receives the full state so consumers can derive\n\t * whatever they need.\n\t */\n\tonStateChange?: ( state: CropperState ) => void;\n\t/** Fires when a continuous gesture begins (pan drag, handle resize, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointerup, resize settle). */\n\tonGestureEnd?: () => void;\n\t/** Additional className for the container. */\n\tclassName?: string;\n}\n\n/**\n * The main image cropper component.\n *\n * Renders an image within a container with interactive crop overlays.\n * Creates the camera once per render via getImageFit, then passes\n * derived values to stencil, overlays, and interaction hooks.\n *\n * The component fills its parent container (100% width and height).\n * Wrap it in a sized container to control its dimensions.\n *\n * @param root0 Component props implementing CropperProps.\n * @param root0.src Image source URL.\n * @param root0.controller The cropper controller from `useCropperReducer` or a composite store.\n * @param root0.stencil Custom stencil component.\n * @param root0.showGrid Grid overlay mode: false | true | 'interactive'.\n * @param root0.isPlacementActive Keep grid visible during external placement activity.\n * @param root0.showDimming Show dimming overlay outside crop.\n * @param root0.showDimensions Show live dimensions tooltip during resize.\n * @param root0.minZoom Minimum zoom level override.\n * @param root0.maxZoom Maximum zoom level.\n * @param root0.aspectRatio Fixed aspect ratio (width/height).\n * @param root0.freeformCrop Enable resize handles.\n * @param root0.focusOnMount Focus the crop area on mount.\n * @param root0.onImageLoaded Image load callback.\n * @param root0.onStateChange Every-frame state callback.\n * @param root0.onGestureStart Gesture boundary start.\n * @param root0.onGestureEnd Gesture boundary end.\n * @param root0.className Additional CSS class.\n * @param ref Forwarded ref for the container div.\n */\nfunction CropperInner(\n\t{\n\t\tsrc,\n\t\tcontroller,\n\t\tstencil: StencilComponent = RectangleStencil,\n\t\tshowGrid = false,\n\t\tisPlacementActive = false,\n\t\tshowDimming = true,\n\t\tshowDimensions = true,\n\t\tminZoom,\n\t\tmaxZoom,\n\t\taspectRatio,\n\t\tfreeformCrop = false,\n\t\tfocusOnMount = false,\n\t\tonImageLoaded,\n\t\tonStateChange,\n\t\tonGestureStart,\n\t\tonGestureEnd,\n\t\tclassName,\n\t}: CropperProps,\n\tref: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst {\n\t\tstate,\n\t\tsetImage,\n\t\tsetCropRect,\n\t\tsettleCrop,\n\t\tsetVisualSize,\n\t\tadjustCropRectForViewport,\n\t} = controller;\n\tconst {\n\t\tviewport: viewportState,\n\t\tsetViewportPan,\n\t\tresetViewport,\n\t} = useViewport();\n\t// Canvas measurement via ResizeObserver. The canvas is the inner\n\t// positioning context for image/stencil/handles — inset from the root\n\t// by the handle gutter, so crop math operates on the reduced box.\n\tconst canvasRef = useRef< HTMLDivElement >( null );\n\tconst cropAreaDescriptionId = useId();\n\tconst [ isCropAreaFocused, setIsCropAreaFocused ] =\n\t\tuseState( focusOnMount );\n\tconst [ isFocusVisible, setIsFocusVisible ] = useState( false );\n\tconst [ canvasSize, setCanvasSize ] = useState< Size >( {\n\t\twidth: 0,\n\t\theight: 0,\n\t} );\n\n\tuseLayoutEffect( () => {\n\t\tif ( focusOnMount ) {\n\t\t\tcanvasRef.current?.focus( { preventScroll: true } );\n\t\t}\n\t}, [ focusOnMount ] );\n\n\tconst handleCropAreaFocus = useCallback(\n\t\t( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tif ( target === event.currentTarget ) {\n\t\t\t\tsetIsCropAreaFocused( true );\n\t\t\t}\n\t\t\t// Show the outline only when focus arrived via keyboard\n\t\t\t// navigation. relatedTarget is null for pointer-initiated and\n\t\t\t// cross-window focus, so it reliably excludes those cases\n\t\t\t// without needing a separate ref or flag. Applies to focus\n\t\t\t// arriving on the canvas itself or on a descendant handle.\n\t\t\tif (\n\t\t\t\tevent.relatedTarget !== null &&\n\t\t\t\ttarget.matches( ':focus-visible' )\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( true );\n\t\t\t}\n\t\t},\n\t\t[]\n\t);\n\n\tconst handleCropAreaBlur = useCallback(\n\t\t( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.target === event.currentTarget ) {\n\t\t\t\tsetIsCropAreaFocused( false );\n\t\t\t}\n\t\t\t// Reset keyboard-active styling only when focus leaves the\n\t\t\t// cropper entirely. Moves between the canvas and a handle (or\n\t\t\t// between handles) keep the keyboard-active state intact.\n\t\t\tif (\n\t\t\t\t! event.currentTarget.contains(\n\t\t\t\t\tevent.relatedTarget as Node | null\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( false );\n\t\t\t}\n\t\t},\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\tconst element = canvasRef.current;\n\t\tif ( ! element ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new ResizeObserver( ( entries ) => {\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst { width, height } = entry.contentRect;\n\t\t\t\tsetCanvasSize( ( prev ) => {\n\t\t\t\t\tif ( prev.width === width && prev.height === height ) {\n\t\t\t\t\t\treturn prev;\n\t\t\t\t\t}\n\t\t\t\t\treturn { width, height };\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t\tobserver.observe( element );\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [] );\n\n\t// Notify consumer of state changes.\n\tuseEffect( () => {\n\t\tonStateChange?.( state );\n\t}, [ state, onStateChange ] );\n\n\t// ARIA announcements: announce significant state changes for screen readers\n\t// via the centralized @wordpress/a11y speak() API called inside the hook.\n\tuseAriaAnnouncer( state );\n\n\t// Compute fitted image dimensions and visual bounds from camera math.\n\tconst naturalWidth = state.image?.naturalWidth ?? 0;\n\tconst naturalHeight = state.image?.naturalHeight ?? 0;\n\tconst { elementSize, visualSize } = useMemo(\n\t\t() =>\n\t\t\tgetImageFit(\n\t\t\t\tcanvasSize,\n\t\t\t\t{ width: naturalWidth, height: naturalHeight },\n\t\t\t\tstate.rotation\n\t\t\t),\n\t\t[ canvasSize, naturalWidth, naturalHeight, state.rotation ]\n\t);\n\n\t// Report the rendered image size to the controller. Composite\n\t// controllers need it to compute aspect-ratio reshapes from the\n\t// reducer (the dropdown dispatches without DOM access); pure\n\t// controllers ignore it.\n\tuseEffect( () => {\n\t\tsetVisualSize( visualSize );\n\t}, [ visualSize, setVisualSize ] );\n\n\t// In fixed-crop mode, auto-size the crop rect only when a fixed\n\t// aspect ratio is selected. With \"Free\" selected, turning freeform\n\t// handles off should preserve the user's current unconstrained\n\t// crop. Uses `adjustCropRectForViewport` so window-resize-driven\n\t// reshapes don't create undo entries (composite controller); the\n\t// dedup at lines below avoids redundant dispatches when the\n\t// reducer has already updated the cropRect for an aspect change.\n\tuseEffect( () => {\n\t\tif (\n\t\t\tfreeformCrop ||\n\t\t\tvisualSize.width === 0 ||\n\t\t\tvisualSize.height === 0 ||\n\t\t\t! aspectRatio ||\n\t\t\taspectRatio <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = computeInscribedRect( aspectRatio, visualSize );\n\t\tconst current = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.height - rect.height ) < CROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tadjustCropRectForViewport( rect );\n\t}, [\n\t\tfreeformCrop,\n\t\taspectRatio,\n\t\tvisualSize,\n\t\tadjustCropRectForViewport,\n\t\tstate.cropRect,\n\t] );\n\n\t// In freeform mode, when aspectRatio changes, reshape the crop to\n\t// the largest inscribed rect of the new ratio. Bails out when the\n\t// cropRect already matches the inscribed rect — composite stores\n\t// reshape atomically inside the reducer, so this effect is a\n\t// no-op there.\n\tconst prevAspectRatioRef = useRef( aspectRatio );\n\tuseEffect( () => {\n\t\tif ( prevAspectRatioRef.current === aspectRatio ) {\n\t\t\treturn;\n\t\t}\n\t\tprevAspectRatioRef.current = aspectRatio;\n\n\t\tif (\n\t\t\t! freeformCrop ||\n\t\t\tvisualSize.width === 0 ||\n\t\t\tvisualSize.height === 0 ||\n\t\t\t! aspectRatio ||\n\t\t\taspectRatio <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = computeInscribedRect( aspectRatio, visualSize );\n\t\tconst current = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.height - rect.height ) < CROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tadjustCropRectForViewport( rect );\n\t}, [\n\t\taspectRatio,\n\t\tfreeformCrop,\n\t\tvisualSize,\n\t\tadjustCropRectForViewport,\n\t\tstate.cropRect,\n\t] );\n\n\t// Compute the crop handle bounds from the actual image footprint.\n\t// Depends on the full state object because getImageCropBounds reads\n\t// crop, zoom, rotation, flip, and image. React Compiler requires\n\t// the complete dependency; the computation is lightweight (a few\n\t// trig ops + 4 corner transforms).\n\tconst cropBounds = useMemo( () => {\n\t\tif ( ! state.image || elementSize.width === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn getImageCropBounds( state, elementSize, visualSize );\n\t}, [ state, elementSize, visualSize ] );\n\tconst effectiveMinZoom =\n\t\tminZoom !== undefined ? minZoom : getMinZoom( state );\n\tconst [ isResizing, setIsResizing ] = useState( false );\n\tconst isResizingRef = useRef( false );\n\tconst isSettlingRef = useRef( false );\n\tconst [ isTouchPinching, setIsTouchPinchingState ] = useState( false );\n\tconst isTouchPinchingRef = useRef( false );\n\tconst setTouchPinching = useCallback( ( isPinching: boolean ) => {\n\t\tisTouchPinchingRef.current = isPinching;\n\t\tsetIsTouchPinchingState( isPinching );\n\t}, [] );\n\t// Direction of the handle the user is currently resizing — pointer or\n\t// keyboard. `null` outside of an active resize. Drives the live\n\t// dimensions tooltip overlay.\n\tconst [ activeHandle, setActiveHandle ] = useState< HandlePosition | null >(\n\t\tnull\n\t);\n\n\t// Presentational magnification so the at-rest crop fills the canvas. The\n\t// crop overlay is laid out as `cropRect * visualSize` (the contain-fit\n\t// footprint, no zoom), so a crop whose aspect differs from the image's can\n\t// render far smaller than the canvas allows. Scaling `elementSize` and\n\t// `visualSize` together magnifies the whole scene uniformly — image,\n\t// overlays, and the pixel->normalized interaction math — and the root's\n\t// `overflow: hidden` clips the image bleed. Magnifying around the footprint\n\t// centre keeps the crop centred only because the at-rest crop is always\n\t// centred (SETTLE_CROP, computeInscribedRect, and the initial full-frame\n\t// crop all centre it).\n\tconst viewScaleRest = useMemo(\n\t\t() =>\n\t\t\tgetViewScale(\n\t\t\t\tstate.cropRect,\n\t\t\t\tcanvasSize,\n\t\t\t\tvisualSize,\n\t\t\t\tSETTLE_TARGET_CANVAS_FILL,\n\t\t\t\tMAX_VIEW_SCALE\n\t\t\t),\n\t\t[ state.cropRect, canvasSize, visualSize ]\n\t);\n\t// During a resize the magnification is frozen at its pre-drag value rather\n\t// than recomputed per pointer move: recomputing live would zoom the scene\n\t// under the cursor, and snapping to 1 would reset the zoom the moment a\n\t// handle is grabbed. `handleResizeStart` snapshots the current rest value\n\t// into `frozenViewScale`; on release the settle recomputes from the new crop.\n\tconst [ frozenViewScale, setFrozenViewScale ] = useState( 1 );\n\tconst viewScale = isResizing ? frozenViewScale : viewScaleRest;\n\tconst scaledVisualSize = useMemo(\n\t\t() => ( {\n\t\t\twidth: visualSize.width * viewScale,\n\t\t\theight: visualSize.height * viewScale,\n\t\t} ),\n\t\t[ visualSize.width, visualSize.height, viewScale ]\n\t);\n\t// CSS pixels rendered per source pixel: the contain fit\n\t// (elementSize / natural), times zoom and the view-scale magnification.\n\tconst displayScale =\n\t\tnaturalWidth > 0\n\t\t\t? ( elementSize.width / naturalWidth ) * state.zoom * viewScale\n\t\t\t: 0;\n\tconst keyboardResizeStep = useMemo( () => {\n\t\tif (\n\t\t\tdisplayScale < PIXEL_SNAP_DISPLAY_SCALE ||\n\t\t\t( aspectRatio && aspectRatio > 0 ) ||\n\t\t\tnaturalWidth <= 0 ||\n\t\t\tnaturalHeight <= 0\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\t\tif (\n\t\t\tMath.abs( state.rotation - snapRotation ) >=\n\t\t\tCARDINAL_ROTATION_EPSILON\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst bbox = getRotatedBBox(\n\t\t\tnaturalWidth,\n\t\t\tnaturalHeight,\n\t\t\tsnapRotation\n\t\t);\n\t\tif ( bbox.width <= 0 || bbox.height <= 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\t// Keyboard steps are normalized crop-space deltas, but snapping wants\n\t\t// one source pixel per key press. The normalized delta for one source\n\t\t// pixel is different on each axis when the snap-rotation bbox is not\n\t\t// square, so this must be an object with separate width/height steps\n\t\t// instead of a single scalar.\n\t\treturn {\n\t\t\twidth: state.zoom / bbox.width,\n\t\t\theight: state.zoom / bbox.height,\n\t\t};\n\t}, [\n\t\tdisplayScale,\n\t\taspectRatio,\n\t\tnaturalWidth,\n\t\tnaturalHeight,\n\t\tstate.rotation,\n\t\tstate.zoom,\n\t] );\n\n\t// Per-axis minimum crop size in normalized space, expressing a pixel floor\n\t// on the captured source region. cropRect is normalized in the viewport's\n\t// snap-rotation bbox; the captured source-pixel width is\n\t// `cropRect.width * bbox.width / zoom`, so the normalized floor scales with\n\t// `zoom` to keep the source-pixel floor constant. The floor itself adapts to\n\t// the on-screen display scale (fit × zoom × view scale) via\n\t// `getMinCropPixels`, so on a large image shown small the crop can't shrink\n\t// until the handles collapse — it yields to the 24px source floor only once\n\t// the image is shown large enough.\n\tconst minCropSize: Size | undefined = useMemo( () => {\n\t\tif ( naturalWidth <= 0 || naturalHeight <= 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\t\tconst bbox = getRotatedBBox(\n\t\t\tnaturalWidth,\n\t\t\tnaturalHeight,\n\t\t\tsnapRotation\n\t\t);\n\t\tconst minPixels = getMinCropPixels( displayScale );\n\t\treturn {\n\t\t\twidth: Math.min( 1, ( minPixels * state.zoom ) / bbox.width ),\n\t\t\theight: Math.min( 1, ( minPixels * state.zoom ) / bbox.height ),\n\t\t};\n\t}, [\n\t\tnaturalWidth,\n\t\tnaturalHeight,\n\t\tstate.rotation,\n\t\tstate.zoom,\n\t\tdisplayScale,\n\t] );\n\n\tconst snapCropRect = useCallback(\n\t\t( rect: NormalizedRect, handle: HandlePosition ): NormalizedRect => {\n\t\t\tif (\n\t\t\t\tdisplayScale < PIXEL_SNAP_DISPLAY_SCALE ||\n\t\t\t\tnaturalWidth <= 0 ||\n\t\t\t\tnaturalHeight <= 0\n\t\t\t) {\n\t\t\t\treturn rect;\n\t\t\t}\n\t\t\treturn snapCropRectToSourcePixels(\n\t\t\t\tstate,\n\t\t\t\t{ width: naturalWidth, height: naturalHeight },\n\t\t\t\trect,\n\t\t\t\thandle\n\t\t\t);\n\t\t},\n\t\t[ displayScale, naturalWidth, naturalHeight, state ]\n\t);\n\n\tconst wasPixelSnapEnabledRef = useRef( false );\n\tuseEffect( () => {\n\t\tconst isPixelSnapEnabled =\n\t\t\tfreeformCrop &&\n\t\t\t( ! aspectRatio || aspectRatio <= 0 ) &&\n\t\t\tdisplayScale >= PIXEL_SNAP_DISPLAY_SCALE &&\n\t\t\tnaturalWidth > 0 &&\n\t\t\tnaturalHeight > 0;\n\t\tconst wasPixelSnapEnabled = wasPixelSnapEnabledRef.current;\n\t\twasPixelSnapEnabledRef.current = isPixelSnapEnabled;\n\n\t\tif ( ! isPixelSnapEnabled || wasPixelSnapEnabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst snappedCropRect = snapCropRectToSourcePixelGrid(\n\t\t\tstate,\n\t\t\t{ width: naturalWidth, height: naturalHeight },\n\t\t\tstate.cropRect\n\t\t);\n\t\tconst currentCropRect = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( currentCropRect.x - snappedCropRect.x ) <\n\t\t\t\tCROP_RECT_EPSILON &&\n\t\t\tMath.abs( currentCropRect.y - snappedCropRect.y ) <\n\t\t\t\tCROP_RECT_EPSILON &&\n\t\t\tMath.abs( currentCropRect.width - snappedCropRect.width ) <\n\t\t\t\tCROP_RECT_EPSILON &&\n\t\t\tMath.abs( currentCropRect.height - snappedCropRect.height ) <\n\t\t\t\tCROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetCropRect( snappedCropRect );\n\t}, [\n\t\taspectRatio,\n\t\tdisplayScale,\n\t\tfreeformCrop,\n\t\tnaturalWidth,\n\t\tnaturalHeight,\n\t\tsetCropRect,\n\t\tstate,\n\t] );\n\n\t// Use the interaction hook for mouse, touch, and keyboard events.\n\tconst {\n\t\thandlers,\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isInteractionPlacementActive,\n\t} = useInteraction( state, controller, canvasSize, scaledVisualSize, {\n\t\tminZoom: effectiveMinZoom,\n\t\tmaxZoom,\n\t\tonGestureStart,\n\t\tonGestureEnd,\n\t} );\n\n\t// Compose focus-visibility tracking into the canvas event handlers.\n\t// Kept as a spread rather than explicit props to avoid triggering\n\t// jsx-a11y/no-noninteractive-element-interactions on role=\"group\".\n\t//\n\t// The pointer/key tracking lives in the capture phase so it runs\n\t// before any child handler — handles call stopPropagation in their\n\t// own onPointerDown / onKeyDown, which would otherwise prevent the\n\t// keyboard-active state from updating when the user interacts with\n\t// a handle directly.\n\tconst canvasHandlers = {\n\t\t...handlers,\n\t\tonPointerDownCapture: () => {\n\t\t\tsetIsFocusVisible( false );\n\t\t},\n\t\tonTouchStartCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.touches.length > 1 ) {\n\t\t\t\tsetTouchPinching( true );\n\t\t\t}\n\t\t},\n\t\tonTouchMoveCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.touches.length > 1 ) {\n\t\t\t\tsetTouchPinching( true );\n\t\t\t}\n\t\t},\n\t\tonTouchEndCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.touches.length === 0 ) {\n\t\t\t\tsetTouchPinching( false );\n\t\t\t}\n\t\t},\n\t\tonTouchCancelCapture: ( event: React.TouchEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.touches.length === 0 ) {\n\t\t\t\tsetTouchPinching( false );\n\t\t\t}\n\t\t},\n\t\tonKeyDownCapture: ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t\t// Modifier-only keypresses precede another key rather than\n\t\t\t// indicating deliberate keyboard interaction on their own.\n\t\t\tif (\n\t\t\t\t! [ 'Shift', 'Control', 'Alt', 'Meta' ].includes( event.key )\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( true );\n\t\t\t}\n\t\t},\n\t\tonPointerDown: ( event: React.PointerEvent< HTMLDivElement > ) => {\n\t\t\tif (\n\t\t\t\tisResizingRef.current ||\n\t\t\t\tisTouchPinchingRef.current ||\n\t\t\t\t( event.pointerType === 'touch' && event.isPrimary === false )\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\thandlers.onPointerDown?.( event );\n\t\t\t// Re-assert false after handlers run — el.focus() inside the\n\t\t\t// handler fires onFocus, which may otherwise set it back to true.\n\t\t\tsetIsFocusVisible( false );\n\t\t},\n\t};\n\n\t// Register wheel handler natively with { passive: false } so\n\t// preventDefault works. React's onWheel registers as passive. Bound\n\t// to the canvas (not the root) so pointer geometry inside the handler\n\t// resolves against the canvas box.\n\tuseEffect( () => {\n\t\tconst el = canvasRef.current;\n\t\tif ( ! el ) {\n\t\t\treturn;\n\t\t}\n\t\tconst handleWheel = ( event: WheelEvent ) => {\n\t\t\t// Block wheel zoom while resizing or settling — the stage CSS\n\t\t\t// transform changes getBoundingClientRect() during this window,\n\t\t\t// so focal-point math would resolve against the wrong center.\n\t\t\tif ( isResizingRef.current || isSettlingRef.current ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tonWheelNative( event );\n\t\t};\n\t\tel.addEventListener( 'wheel', handleWheel, {\n\t\t\tpassive: false,\n\t\t} );\n\t\treturn () => {\n\t\t\tel.removeEventListener( 'wheel', handleWheel );\n\t\t};\n\t}, [ onWheelNative ] );\n\n\t// Use the unscaled contain-fit footprint here. `imageStyle` prepends\n\t// `scale(viewScale)` to this matrix, so pan translations are magnified with\n\t// the rest of the scene; using `scaledVisualSize` here would apply viewScale\n\t// to pan twice.\n\tconst transformString = useTransformStyle( state, visualSize );\n\n\t/**\n\t * Handle the image load event.\n\t */\n\tconst handleImageLoad = useCallback(\n\t\t( event: React.SyntheticEvent< HTMLImageElement > ) => {\n\t\t\tconst img = event.currentTarget;\n\t\t\tconst size: Size = {\n\t\t\t\twidth: img.naturalWidth,\n\t\t\t\theight: img.naturalHeight,\n\t\t\t};\n\n\t\t\tsetImage( {\n\t\t\t\tsrc,\n\t\t\t\tnaturalWidth: size.width,\n\t\t\t\tnaturalHeight: size.height,\n\t\t\t} );\n\n\t\t\tonImageLoaded?.( size );\n\t\t},\n\t\t[ src, setImage, onImageLoaded ]\n\t);\n\n\tconst handleCropChange = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tif ( isTouchPinchingRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetCropRect( rect );\n\t\t\t// During a resize drag, pan the viewport so the handle stays\n\t\t\t// visible even when the crop extends beyond the canvas edge.\n\t\t\tif (\n\t\t\t\tisResizingRef.current &&\n\t\t\t\tscaledVisualSize.width > 0 &&\n\t\t\t\tscaledVisualSize.height > 0\n\t\t\t) {\n\t\t\t\tconst offsetX =\n\t\t\t\t\t( canvasSize.width - scaledVisualSize.width ) / 2;\n\t\t\t\tconst offsetY =\n\t\t\t\t\t( canvasSize.height - scaledVisualSize.height ) / 2;\n\t\t\t\tconst rightOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\toffsetX +\n\t\t\t\t\t\t( rect.x + rect.width ) * scaledVisualSize.width -\n\t\t\t\t\t\tcanvasSize.width\n\t\t\t\t);\n\t\t\t\tconst leftOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\t-( offsetX + rect.x * scaledVisualSize.width )\n\t\t\t\t);\n\t\t\t\tconst bottomOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\toffsetY +\n\t\t\t\t\t\t( rect.y + rect.height ) * scaledVisualSize.height -\n\t\t\t\t\t\tcanvasSize.height\n\t\t\t\t);\n\t\t\t\tconst topOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\t-( offsetY + rect.y * scaledVisualSize.height )\n\t\t\t\t);\n\t\t\t\tsetViewportPan( {\n\t\t\t\t\tx: -rightOverflow + leftOverflow,\n\t\t\t\t\ty: -bottomOverflow + topOverflow,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ setCropRect, setViewportPan, canvasSize, scaledVisualSize ]\n\t);\n\n\t// Settling animation: brief transition after resize end.\n\tconst [ settling, setSettling ] = useState( false );\n\tconst settleTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\tconst finishSettling = useCallback( () => {\n\t\tclearTimeout( settleTimerRef.current );\n\t\tisSettlingRef.current = false;\n\t\tsetSettling( false );\n\t}, [] );\n\n\t// Clear the pending settle timer on unmount so it can't fire a\n\t// state update on an unmounted component.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( settleTimerRef.current );\n\t\t};\n\t}, [] );\n\n\tconst isInteractiveGrid = showGrid === 'interactive';\n\tconst showInteractiveGrid =\n\t\tisInteractiveGrid &&\n\t\t( isInteractionPlacementActive || isResizing || isPlacementActive );\n\n\t// Output crop size in source pixels — drives the live tooltip\n\t// overlay. Only computed during pointer drags, so the per-frame\n\t// state churn during pan/zoom doesn't pay for it.\n\tconst outputSize = useMemo( () => {\n\t\tif ( ! showDimensions || ! activeHandle || ! state.image ) {\n\t\t\treturn null;\n\t\t}\n\t\tconst region = getSourceRegion( state, {\n\t\t\twidth: state.image.naturalWidth,\n\t\t\theight: state.image.naturalHeight,\n\t\t} );\n\t\treturn { width: region.width, height: region.height };\n\t}, [ showDimensions, activeHandle, state ] );\n\n\t/**\n\t * Handle Escape on a resize handle — return focus to the canvas so\n\t * arrow keys pan the image rather than resize.\n\t */\n\tconst handleEscape = useCallback( () => {\n\t\t// Escape is always a keyboard action, so show the outline immediately\n\t\t// rather than relying on the focus handler's :focus-visible check.\n\t\tsetIsFocusVisible( true );\n\t\tcanvasRef.current?.focus( { preventScroll: true } );\n\t}, [] );\n\n\tconst handleResizeStart = useCallback(\n\t\t( handle?: HandlePosition ) => {\n\t\t\tif ( isTouchPinchingRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Freeze the magnification at its current value so grabbing a\n\t\t\t// handle doesn't reset the zoom; it holds for the whole drag.\n\t\t\tsetFrozenViewScale( viewScaleRest );\n\t\t\tisResizingRef.current = true;\n\t\t\tsetIsResizing( true );\n\t\t\tsetActiveHandle( handle ?? null );\n\t\t\t// Clear any in-flight settle so transitions don't apply during the\n\t\t\t// new drag (rapid successive resizes would otherwise inherit the\n\t\t\t// previous settle animation).\n\t\t\tfinishSettling();\n\t\t\tresetViewport();\n\t\t\tonGestureStart?.();\n\t\t},\n\t\t[ finishSettling, onGestureStart, resetViewport, viewScaleRest ]\n\t);\n\n\t/**\n\t * Handle resize end — settle the crop rect (re-center, fill height)\n\t * and reset the viewport pan back to neutral.\n\t */\n\tconst handleResizeEnd = useCallback( () => {\n\t\tconst isCancellingForPinch = isTouchPinchingRef.current;\n\t\tisResizingRef.current = false;\n\t\tsetIsResizing( false );\n\t\tsetActiveHandle( null );\n\t\tclearTimeout( settleTimerRef.current );\n\n\t\tif ( isCancellingForPinch ) {\n\t\t\t// A pinch took over mid-resize. Tear down resize UI without\n\t\t\t// settling or firing onGestureEnd: the pinch owns the gesture\n\t\t\t// boundary and fires the end on its own touchend. The resize and\n\t\t\t// the pinch therefore collapse into a single undo step, since\n\t\t\t// `beginGesture` is idempotent and the snapshot captured at resize\n\t\t\t// start is flushed by the pinch's `endGesture`.\n\t\t\tfinishSettling();\n\t\t\tresetViewport();\n\t\t\treturn;\n\t\t}\n\n\t\tisSettlingRef.current = true;\n\t\tsetSettling( true );\n\t\t// Reset viewport pan first so it transitions back to zero in sync\n\t\t// with the settle animation on the image.\n\t\tresetViewport();\n\t\tsettleCrop();\n\t\tonGestureEnd?.();\n\t\t// Normal completion is driven by transitionend so settling cannot clear\n\t\t// before the browser has actually finished animating. Keep a fallback for\n\t\t// cases where the computed transform is unchanged and no event fires.\n\t\tsettleTimerRef.current = setTimeout(\n\t\t\tfinishSettling,\n\t\t\tSETTLE_TRANSITION_FALLBACK_MS\n\t\t);\n\t}, [ finishSettling, settleCrop, onGestureEnd, resetViewport ] );\n\n\t/**\n\t * Finish settling when the settle transform transition actually completes.\n\t * The handler lives on the stage, but in the common (un-panned) case the\n\t * transform transition runs on the image layer and its `transitionend`\n\t * bubbles up to here. Other transitionend events (stencil left/top/width/\n\t * height) also bubble up, so only the transform transition should clear the\n\t * settle state.\n\t */\n\tconst handleSettleTransitionEnd = useCallback(\n\t\t( event: React.TransitionEvent< HTMLDivElement > ) => {\n\t\t\tif (\n\t\t\t\t! isSettlingRef.current ||\n\t\t\t\tevent.propertyName !== 'transform'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfinishSettling();\n\t\t},\n\t\t[ finishSettling ]\n\t);\n\n\tlet imageTransition: string | undefined;\n\tif ( settling ) {\n\t\timageTransition = SETTLE_TRANSFORM_TRANSITION;\n\t} else if ( isZooming ) {\n\t\timageTransition = 'transform 150ms linear';\n\t}\n\tconst settleStencilTransition = settling\n\t\t? SETTLE_STENCIL_TRANSITION\n\t\t: undefined;\n\n\t// Compute the image's CSS style. The element keeps its contain-fit box; the\n\t// view-scale magnification is folded into the transform as an outer\n\t// `scale()` so the whole settle motion (zoom, pan, and magnification) is one\n\t// coherent transform that interpolates as a unit — the image slides/scales\n\t// to its position rather than animating its box separately. Magnifying\n\t// around the centred box keeps the (centred) crop centred.\n\tconst imageStyle = useMemo( (): React.CSSProperties => {\n\t\tif ( elementSize.width === 0 || elementSize.height === 0 ) {\n\t\t\treturn {};\n\t\t}\n\t\tconst centerX = ( canvasSize.width - elementSize.width ) / 2;\n\t\tconst centerY = ( canvasSize.height - elementSize.height ) / 2;\n\t\t// Above 1:1 the image is upscaled, so render nearest-neighbour to keep\n\t\t// pixel boundaries crisp (e.g. small images the cropper magnifies);\n\t\t// below 1:1 leave smoothing on for downscaled large images.\n\t\treturn {\n\t\t\twidth: elementSize.width,\n\t\t\theight: elementSize.height,\n\t\t\tmaxWidth: elementSize.width,\n\t\t\tmaxHeight: elementSize.height,\n\t\t\tleft: centerX,\n\t\t\ttop: centerY,\n\t\t\t// Always lead with `scale()` (identity at rest) so the transform's\n\t\t\t// function list stays structurally constant across rest, resize, and\n\t\t\t// settle. A conditional that dropped `scale()` at viewScale === 1\n\t\t\t// would change the list shape exactly when the settle transition\n\t\t\t// crosses 1:1, forcing the browser to fall back to matrix-decomposition\n\t\t\t// interpolation instead of interpolating each function in turn.\n\t\t\ttransform: `scale(${ viewScale }) ${ transformString }`,\n\t\t\ttransition: imageTransition,\n\t\t\timageRendering: displayScale > 1 ? 'pixelated' : undefined,\n\t\t};\n\t}, [\n\t\tcanvasSize,\n\t\telementSize,\n\t\ttransformString,\n\t\timageTransition,\n\t\tdisplayScale,\n\t\tviewScale,\n\t] );\n\n\t// Viewport pan CSS transform for the stage div. Applied during resize\n\t// drags to keep handles visible when the crop extends past the canvas edge.\n\t// Transitions back to zero during the settle animation.\n\t// will-change promotes the stage to its own compositor layer while the\n\t// transform is active, keeping per-frame pan updates off the main thread.\n\tconst settleTransition = settling ? SETTLE_TRANSFORM_TRANSITION : undefined;\n\tconst willChange = isResizing || settling ? 'transform' : undefined;\n\tlet stageStyle: React.CSSProperties | undefined;\n\tif ( viewportState.pan.x !== 0 || viewportState.pan.y !== 0 ) {\n\t\tstageStyle = {\n\t\t\ttransform: `translate(${ viewportState.pan.x }px, ${ viewportState.pan.y }px)`,\n\t\t\ttransition: settleTransition,\n\t\t\twillChange,\n\t\t};\n\t} else if ( settling ) {\n\t\t// Animate the viewport pan back to an explicit identity translate rather\n\t\t// than dropping the transform property, so the reset eases instead of\n\t\t// snapping (transitions to a removed transform are unreliable).\n\t\tstageStyle = {\n\t\t\ttransform: 'translate(0px, 0px)',\n\t\t\ttransition: settleTransition,\n\t\t\twillChange,\n\t\t};\n\t}\n\n\t// Forward the root element to the consumer's ref.\n\tconst setContainerRef = useCallback(\n\t\t( element: HTMLDivElement | null ) => {\n\t\t\tif ( typeof ref === 'function' ) {\n\t\t\t\tref( element );\n\t\t\t} else if ( ref ) {\n\t\t\t\t(\n\t\t\t\t\tref as React.MutableRefObject< HTMLDivElement | null >\n\t\t\t\t ).current = element;\n\t\t\t}\n\t\t},\n\t\t[ ref ]\n\t);\n\n\treturn (\n\t\t<div\n\t\t\tref={ setContainerRef }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wp-media-editor-image-editor',\n\t\t\t\tisDragging && 'wp-media-editor-image-editor--dragging',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t>\n\t\t\t{ /*\n\t\t\t * The canvas is the interactive, inset surface. Handles and\n\t\t\t * the ARIA role/tabIndex live here so pointer geometry\n\t\t\t * (getBoundingClientRect on e.currentTarget) resolves against\n\t\t\t * the same box that crop math uses. The root stays as the\n\t\t\t * clipping shell for the dimming overlay's box-shadow.\n\t\t\t *\n\t\t\t * Not role=\"application\" — that disables the screen reader's\n\t\t\t * normal keyboard interception, too heavy-handed for a single\n\t\t\t * widget. Screen reader users get the ARIA live region below\n\t\t\t * as the announcement channel.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tref={ canvasRef }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wp-media-editor-image-editor__canvas',\n\t\t\t\t\tisInteractiveGrid &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--grid-interactive',\n\t\t\t\t\tshowInteractiveGrid &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--show-grid',\n\t\t\t\t\tsettling &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--settling',\n\t\t\t\t\t// Marks the cropper as in keyboard-interaction mode.\n\t\t\t\t\t// CSS uses :focus on the canvas to show the stencil\n\t\t\t\t\t// outline and :focus on a handle to show its ring,\n\t\t\t\t\t// so the class applies whenever any cropper element\n\t\t\t\t\t// has keyboard focus.\n\t\t\t\t\tisFocusVisible &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--focus-visible'\n\t\t\t\t) }\n\t\t\t\ttabIndex={ 0 }\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={ __( 'Crop area' ) }\n\t\t\t\taria-describedby={\n\t\t\t\t\tisCropAreaFocused ? cropAreaDescriptionId : undefined\n\t\t\t\t}\n\t\t\t\tonFocus={ handleCropAreaFocus }\n\t\t\t\tonBlur={ handleCropAreaBlur }\n\t\t\t\t{ ...canvasHandlers }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tid={ cropAreaDescriptionId }\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ /*\n\t\t\t\t * The stage is an inner full-size div that receives the\n\t\t\t\t * viewport pan CSS transform. Keeping the transform here\n\t\t\t\t * (rather than on the canvas) means the canvas always stays\n\t\t\t\t * at its natural position, so the root div's background is\n\t\t\t\t * never exposed when the stage is panned during a resize drag.\n\t\t\t\t */ }\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"wp-media-editor-image-editor__stage\"\n\t\t\t\t\tdata-testid=\"cropper-stage\"\n\t\t\t\t\tstyle={ stageStyle }\n\t\t\t\t\tonTransitionEnd={ handleSettleTransitionEnd }\n\t\t\t\t>\n\t\t\t\t\t{ /* The image layer */ }\n\t\t\t\t\t<img\n\t\t\t\t\t\tclassName=\"wp-media-editor-image-editor__image\"\n\t\t\t\t\t\tdata-testid=\"cropper-image\"\n\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tonLoad={ handleImageLoad }\n\t\t\t\t\t\tstyle={ imageStyle }\n\t\t\t\t\t\tdraggable={ false }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ /* Dimming overlay outside the crop area */ }\n\t\t\t\t\t{ showDimming && (\n\t\t\t\t\t\t<DimmingOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ scaledVisualSize }\n\t\t\t\t\t\t\ttransition={ settleStencilTransition }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ /* The stencil (crop area with handles) */ }\n\t\t\t\t\t<StencilComponent\n\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\timageSize={ scaledVisualSize }\n\t\t\t\t\t\tonCropChange={ handleCropChange }\n\t\t\t\t\t\tonResizeStart={ handleResizeStart }\n\t\t\t\t\t\tonResizeEnd={ handleResizeEnd }\n\t\t\t\t\t\tonEscape={ handleEscape }\n\t\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\t\tfreeformCrop={ freeformCrop }\n\t\t\t\t\t\tisResizeDisabled={ isTouchPinching }\n\t\t\t\t\t\tstencilTransition={ settleStencilTransition }\n\t\t\t\t\t\tcropBounds={ cropBounds }\n\t\t\t\t\t\tminCropSize={ minCropSize }\n\t\t\t\t\t\tsnapCropRect={ snapCropRect }\n\t\t\t\t\t\tkeyboardResizeStep={ keyboardResizeStep }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ /* Rule-of-thirds grid */ }\n\t\t\t\t\t{ ( showGrid === true || isInteractiveGrid ) && (\n\t\t\t\t\t\t<GridOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ scaledVisualSize }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ /* Live dimensions tooltip pinned to the dragged handle. */ }\n\t\t\t\t\t{ activeHandle && outputSize && (\n\t\t\t\t\t\t<DimensionsOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ scaledVisualSize }\n\t\t\t\t\t\t\tactiveHandle={ activeHandle }\n\t\t\t\t\t\t\toutputWidth={ outputSize.width }\n\t\t\t\t\t\t\toutputHeight={ outputSize.height }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nconst CropperInnerWithRef = forwardRef< HTMLDivElement, CropperProps >(\n\tCropperInner\n);\n\nexport const Cropper = forwardRef< HTMLDivElement, CropperProps >(\n\t( props, ref ) => (\n\t\t<ViewportProvider>\n\t\t\t<CropperInnerWithRef { ...props } ref={ ref } />\n\t\t</ViewportProvider>\n\t)\n);\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AASnB,SAAS,aAAa,gBAAgB,oBAAoB;AAC1D,SAAS,oBAAoB,kBAAkB;AAC/C;AA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EF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/image-editor/react/components/overlays/dimensions-overlay.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import { useLayoutEffect, useRef, useState } from '@wordpress/element';\nimport type { HandlePosition, NormalizedRect, Size } from '../../../core/types';\n\nconst HANDLE_GAP_PX = 12;\n\n/**\n * Which side of the handle a tooltip axis sits on. `before` places the\n * tooltip on the negative side of the handle (above for Y, left for X),\n * `after` on the positive side, `center` keeps it aligned with the handle.\n */\ntype AxisSide = 'before' | 'center' | 'after';\n\ninterface Anchor {\n\tx: AxisSide;\n\ty: AxisSide;\n}\n\nconst TRANSLATE_PERCENT: Record< AxisSide, string > = {\n\tbefore: '-100%',\n\tcenter: '-50%',\n\tafter: '0',\n};\n\nconst GAP_DIRECTION: Record< AxisSide, number > = {\n\tbefore: -1,\n\tcenter: 0,\n\tafter: 1,\n};\n\nconst OPPOSITE_SIDE: Record< AxisSide, AxisSide > = {\n\tbefore: 'after',\n\tcenter: 'center',\n\tafter: 'before',\n};\n\n/**\n * Preferred anchor for a handle, before edge-clipping is considered:\n * tooltip sits outward from the crop rectangle's center.\n *\n * @param handle\n */\nfunction preferredAnchor( handle: HandlePosition ): Anchor {\n\tlet x: AxisSide = 'center';\n\tif ( handle.includes( 'w' ) ) {\n\t\tx = 'before';\n\t} else if ( handle.includes( 'e' ) ) {\n\t\tx = 'after';\n\t}\n\n\tlet y: AxisSide = 'center';\n\tif ( handle.includes( 'n' ) ) {\n\t\ty = 'before';\n\t} else if ( handle.includes( 's' ) ) {\n\t\ty = 'after';\n\t}\n\n\treturn { x, y };\n}\n\n/**\n * Start coordinate of a tooltip placed on the given side of `handlePos`,\n * accounting for the per-side handle gap and the tooltip's own length.\n *\n * @param side\n * @param handlePos\n * @param length\n */\nfunction sideStart(\n\tside: AxisSide,\n\thandlePos: number,\n\tlength: number\n): number {\n\tif ( side === 'before' ) {\n\t\treturn handlePos - HANDLE_GAP_PX - length;\n\t}\n\tif ( side === 'after' ) {\n\t\treturn handlePos + HANDLE_GAP_PX;\n\t}\n\treturn handlePos - length / 2;\n}\n\n/**\n * Picks a side that keeps the tooltip inside the container along one\n * axis, preferring the supplied side and falling back to its opposite,\n * then center.\n *\n * @param preferred\n * @param handlePos\n * @param length\n * @param containerLength\n */\nfunction fittingSide(\n\tpreferred: AxisSide,\n\thandlePos: number,\n\tlength: number,\n\tcontainerLength: number\n): AxisSide {\n\tconst fits = ( side: AxisSide ) => {\n\t\tconst start = sideStart( side, handlePos, length );\n\t\treturn start >= 0 && start + length <= containerLength;\n\t};\n\n\tif ( fits( preferred ) ) {\n\t\treturn preferred;\n\t}\n\tconst opposite = OPPOSITE_SIDE[ preferred ];\n\tif ( opposite !== preferred && fits( opposite ) ) {\n\t\treturn opposite;\n\t}\n\tif ( preferred !== 'center' && fits( 'center' ) ) {\n\t\treturn 'center';\n\t}\n\t// None of the candidates fully fit — pick the one that pushes the\n\t// least past the container edge. Without this, the chain falls back\n\t// to `preferred`, which is the off-canvas side that triggered the\n\t// flip in the first place, so the tooltip ends up clipped.\n\tconst overflow = ( side: AxisSide ) => {\n\t\tconst start = sideStart( side, handlePos, length );\n\t\treturn (\n\t\t\tMath.max( 0, -start ) +\n\t\t\tMath.max( 0, start + length - containerLength )\n\t\t);\n\t};\n\tconst candidates: AxisSide[] = [ preferred, opposite, 'center' ];\n\treturn candidates.reduce( ( best, side ) =>\n\t\toverflow( side ) < overflow( best ) ? side : best\n\t);\n}\n\ninterface DimensionsOverlayProps {\n\t/** Crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** Container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** Rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n\t/** Currently-dragged handle, or null when no pointer drag is active. */\n\tactiveHandle: HandlePosition | null;\n\t/** Output crop width in source pixels. */\n\toutputWidth: number;\n\t/** Output crop height in source pixels. */\n\toutputHeight: number;\n}\n\n/**\n * Tooltip that follows the active resize handle during a pointer drag,\n * showing the current output dimensions of the crop in source pixels.\n *\n * Renders nothing outside of a pointer-driven resize, so keyboard\n * arrow-key adjustments and pan/zoom gestures stay quiet.\n *\n * @param props\n * @param props.cropRect\n * @param props.containerSize\n * @param props.imageSize\n * @param props.activeHandle\n * @param props.outputWidth\n * @param props.outputHeight\n */\nexport function DimensionsOverlay( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\tactiveHandle,\n\toutputWidth,\n\toutputHeight,\n}: DimensionsOverlayProps ) {\n\tconst tooltipRef = useRef< HTMLDivElement >( null );\n\tconst [ tooltipSize, setTooltipSize ] = useState< Size | null >( null );\n\n\t// Measure the rendered tooltip so we can flip its anchor when it\n\t// would otherwise be clipped by the cropper's `overflow: hidden`\n\t// root. Runs synchronously before paint, so the user never sees\n\t// the un-flipped position. Tracks `outputWidth`/`outputHeight`\n\t// because they drive the digit count, the only thing that changes\n\t// the tooltip's intrinsic size during a drag.\n\tuseLayoutEffect( () => {\n\t\tif ( ! tooltipRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = tooltipRef.current.getBoundingClientRect();\n\t\tsetTooltipSize( ( prev ) => {\n\t\t\tif (\n\t\t\t\tprev &&\n\t\t\t\tprev.width === rect.width &&\n\t\t\t\tprev.height === rect.height\n\t\t\t) {\n\t\t\t\treturn prev;\n\t\t\t}\n\t\t\treturn { width: rect.width, height: rect.height };\n\t\t} );\n\t}, [ outputWidth, outputHeight ] );\n\n\tif (\n\t\t! activeHandle ||\n\t\tcontainerSize.width === 0 ||\n\t\tcontainerSize.height === 0\n\t) {\n\t\treturn null;\n\t}\n\n\tconst offsetX = ( containerSize.width - imageSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - imageSize.height ) / 2;\n\tconst left = offsetX + cropRect.x * imageSize.width;\n\tconst top = offsetY + cropRect.y * imageSize.height;\n\tconst width = cropRect.width * imageSize.width;\n\tconst height = cropRect.height * imageSize.height;\n\n\t// Handle pixel position within the container. Same math as the\n\t// stencil's handle layout, just keyed by direction here so the\n\t// tooltip can anchor to any of the eight.\n\tlet handleX = left + width / 2;\n\tif ( activeHandle.includes( 'w' ) ) {\n\t\thandleX = left;\n\t} else if ( activeHandle.includes( 'e' ) ) {\n\t\thandleX = left + width;\n\t}\n\tlet handleY = top + height / 2;\n\tif ( activeHandle.includes( 'n' ) ) {\n\t\thandleY = top;\n\t} else if ( activeHandle.includes( 's' ) ) {\n\t\thandleY = top + height;\n\t}\n\n\tconst preferred = preferredAnchor( activeHandle );\n\tconst anchor: Anchor = tooltipSize\n\t\t? {\n\t\t\t\tx: fittingSide(\n\t\t\t\t\tpreferred.x,\n\t\t\t\t\thandleX,\n\t\t\t\t\ttooltipSize.width,\n\t\t\t\t\tcontainerSize.width\n\t\t\t\t),\n\t\t\t\ty: fittingSide(\n\t\t\t\t\tpreferred.y,\n\t\t\t\t\thandleY,\n\t\t\t\t\ttooltipSize.height,\n\t\t\t\t\tcontainerSize.height\n\t\t\t\t),\n\t\t }\n\t\t: preferred;\n\n\treturn (\n\t\t<div\n\t\t\tref={ tooltipRef }\n\t\t\tclassName=\"wp-media-editor-image-editor__dimensions-tooltip\"\n\t\t\tdata-testid=\"cropper-dimensions-tooltip\"\n\t\t\tstyle={ {\n\t\t\t\tleft: handleX + GAP_DIRECTION[ anchor.x ] * HANDLE_GAP_PX,\n\t\t\t\ttop: handleY + GAP_DIRECTION[ anchor.y ] * HANDLE_GAP_PX,\n\t\t\t\ttransform: `translate(${ TRANSLATE_PERCENT[ anchor.x ] }, ${\n\t\t\t\t\tTRANSLATE_PERCENT[ anchor.y ]\n\t\t\t\t})`,\n\t\t\t} }\n\t\t\taria-hidden=\"true\"\n\t\t>\n\t\t\t{ `W: ${ Math.round( outputWidth ) }px H: ${ Math.round(\n\t\t\t\toutputHeight\n\t\t\t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I,GAAI;AACnC,cAAU;AAAA,EACX,WAAY,aAAa,SAAU,GAAI,GAAI;AAC1C,cAAU,OAAO;AAAA,EAClB;AACA,MAAI,UAAU,MAAM,SAAS;AAC7B,MAAK,aAAa,SAAU,GAAI,GAAI;AACnC,cAAU;AAAA,EACX,WAAY,aAAa,SAAU,GAAI,GAAI;AAC1C,cAAU,MAAM;AAAA,EACjB;AAEA,QAAM,YAAY,gBAAiB,YAAa;AAChD,QAAM,SAAiB,cACpB;AAAA,IACA,GAAG;AAAA,MACF,UAAU;AAAA,MACV;AAAA,MACA,YAAY;AAAA,MACZ,cAAc;AAAA,IACf;AAAA,IACA,GAAG;AAAA,MACF,UAAU;AAAA,MACV;AAAA,MACA,YAAY;AAAA,MACZ,cAAc;AAAA,IACf;AAAA,EACA,IACA;AAEH,SACC;AAAA,IAAC;AAAA;AAAA,MACA,KAAM;AAAA,MACN,WAAU;AAAA,MACV,eAAY;AAAA,MACZ,OAAQ;AAAA,QACP,MAAM,UAAU,cAAe,OAAO,CAAE,IAAI;AAAA,QAC5C,KAAK,UAAU,cAAe,OAAO,CAAE,IAAI;AAAA,QAC3C,WAAW,aAAc,kBAAmB,OAAO,CAAE,CAAE,KACtD,kBAAmB,OAAO,CAAE,CAC7B;AAAA,MACD;AAAA,MACA,eAAY;AAAA,MAEV,gBAAO,KAAK,MAAO,WAAY,CAAE,SAAU,KAAK;AAAA,QACjD;AAAA,MACD,CAAE;AAAA;AAAA,EACH;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/image-editor/react/components/overlays/dimming-overlay.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type { NormalizedRect, Size } from '../../../core/types';\n\n/**\n * Props for the DimmingOverlay component.\n */\ninterface DimmingOverlayProps {\n\t/** The crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** The container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** The rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n\t/** CSS transition string, e.g. during settle animation. */\n\ttransition?: string;\n}\n\n// Renders a semi-transparent overlay outside the crop rectangle using a\n// box-shadow that dims everything outside the crop rect position.\nexport function DimmingOverlay( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\ttransition,\n}: DimmingOverlayProps ) {\n\tif ( containerSize.width === 0 || containerSize.height === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst offsetX = ( containerSize.width - imageSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - imageSize.height ) / 2;\n\tconst left = offsetX + cropRect.x * imageSize.width;\n\tconst top = offsetY + cropRect.y * imageSize.height;\n\tconst width = cropRect.width * imageSize.width;\n\tconst height = cropRect.height * imageSize.height;\n\n\t// Compose any incoming transition with the stylesheet's box-shadow\n\t// transition so the drag-dimming effect isn't overwritten.\n\tconst composedTransition = transition\n\t\t? `${ transition }, box-shadow 0.15s ease`\n\t\t: undefined;\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-media-editor-image-editor__dimming\"\n\t\t\tdata-testid=\"cropper-dimming\"\n\t\t\tstyle={ {\n\t\t\t\tleft,\n\t\t\t\ttop,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\ttransition: composedTransition,\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AA0CE;AAxBK,SAAS,eAAgB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAyB;AACxB,MAAK,cAAc,UAAU,KAAK,cAAc,WAAW,GAAI;AAC9D,WAAO;AAAA,EACR;AAEA,QAAM,WAAY,cAAc,QAAQ,UAAU,SAAU;AAC5D,QAAM,WAAY,cAAc,SAAS,UAAU,UAAW;AAC9D,QAAM,OAAO,UAAU,SAAS,IAAI,UAAU;AAC9C,QAAM,MAAM,UAAU,SAAS,IAAI,UAAU;AAC7C,QAAM,QAAQ,SAAS,QAAQ,UAAU;AACzC,QAAM,SAAS,SAAS,SAAS,UAAU;AAI3C,QAAM,qBAAqB,aACxB,GAAI,UAAW,4BACf;AAEH,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,eAAY;AAAA,MACZ,OAAQ;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,YAAY;AAAA,MACb;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/image-editor/react/components/overlays/grid-overlay.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type { NormalizedRect, Size } from '../../../core/types';\n\n/**\n * Props for the GridOverlay component.\n */\ninterface GridOverlayProps {\n\t/** The crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** The container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** The rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n}\n\n/**\n * Renders a rule-of-thirds grid inside the crop rectangle.\n *\n * Displays 2 horizontal and 2 vertical lines at 1/3 and 2/3\n * positions within the crop area.\n *\n * @param props Component props.\n * @param props.cropRect The crop rectangle in normalized coordinates.\n * @param props.containerSize The container element dimensions in pixels.\n * @param props.imageSize The rendered image dimensions in pixels.\n * @return The grid overlay element.\n */\nexport function GridOverlay( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n}: GridOverlayProps ) {\n\tif ( containerSize.width === 0 || containerSize.height === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst offsetX = ( containerSize.width - imageSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - imageSize.height ) / 2;\n\tconst left = offsetX + cropRect.x * imageSize.width;\n\tconst top = offsetY + cropRect.y * imageSize.height;\n\tconst width = cropRect.width * imageSize.width;\n\tconst height = cropRect.height * imageSize.height;\n\n\tconst thirdW = width / 3;\n\tconst thirdH = height / 3;\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-media-editor-image-editor__grid\"\n\t\t\tdata-testid=\"cropper-grid\"\n\t\t\tstyle={ {\n\t\t\t\tleft,\n\t\t\t\ttop,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t} }\n\t\t>\n\t\t\t{ /* Horizontal lines at 1/3 and 2/3 */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--horizontal\"\n\t\t\t\tstyle={ { top: thirdH } }\n\t\t\t/>\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--horizontal\"\n\t\t\t\tstyle={ { top: thirdH * 2 } }\n\t\t\t/>\n\t\t\t{ /* Vertical lines at 1/3 and 2/3 */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--vertical\"\n\t\t\t\tstyle={ { left: thirdW } }\n\t\t\t/>\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--vertical\"\n\t\t\t\tstyle={ { left: thirdW * 2 } }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AA8CE,SAWC,KAXD;AApBK,SAAS,YAAa;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AACD,GAAsB;AACrB,MAAK,cAAc,UAAU,KAAK,cAAc,WAAW,GAAI;AAC9D,WAAO;AAAA,EACR;AAEA,QAAM,WAAY,cAAc,QAAQ,UAAU,SAAU;AAC5D,QAAM,WAAY,cAAc,SAAS,UAAU,UAAW;AAC9D,QAAM,OAAO,UAAU,SAAS,IAAI,UAAU;AAC9C,QAAM,MAAM,UAAU,SAAS,IAAI,UAAU;AAC7C,QAAM,QAAQ,SAAS,QAAQ,UAAU;AACzC,QAAM,SAAS,SAAS,SAAS,UAAU;AAE3C,QAAM,SAAS,QAAQ;AACvB,QAAM,SAAS,SAAS;AAExB,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,eAAY;AAAA,MACZ,OAAQ;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,MAGA;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ,EAAE,KAAK,OAAO;AAAA;AAAA,QACvB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ,EAAE,KAAK,SAAS,EAAE;AAAA;AAAA,QAC3B;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ,EAAE,MAAM,OAAO;AAAA;AAAA,QACxB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ,EAAE,MAAM,SAAS,EAAE;AAAA;AAAA,QAC5B;AAAA;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|