@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/react/components/stencils/rectangle-stencil.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseMemo,\n\tuseRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { StencilProps, NormalizedRect } from '../../../core/types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n} from '../../../core/constants';\nimport {\n\tcomputeFreeResizeRect,\n\tcomputeLockedResizeRect,\n\tcomputeShiftLockedResizeRect,\n\ttype HandlePosition,\n\ttype CropBounds,\n\ttype ResizeDragState,\n\ttype ResizeDriverAxis,\n} from '../../../core/stencil-math';\nimport { VISUALLY_HIDDEN_STYLE } from '../../visually-hidden-style';\n\n/**\n * Corner handle positions only — used when aspect ratio is locked.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst CORNER_POSITIONS: HandlePosition[] = [ 'nw', 'ne', 'se', 'sw' ];\n\n/**\n * All handle positions rendered by the stencil.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst ALL_POSITIONS: HandlePosition[] = [\n\t'nw',\n\t'n',\n\t'ne',\n\t'e',\n\t'se',\n\t's',\n\t'sw',\n\t'w',\n];\n\n/**\n * Get the translated aria-label for a resize handle position.\n *\n * @param pos The handle position identifier.\n * @return The translated label string.\n */\nfunction getHandleLabel( pos: HandlePosition ): string {\n\tswitch ( pos ) {\n\t\tcase 'n':\n\t\t\treturn __( 'Resize from top edge' );\n\t\tcase 's':\n\t\t\treturn __( 'Resize from bottom edge' );\n\t\tcase 'e':\n\t\t\treturn __( 'Resize from right edge' );\n\t\tcase 'w':\n\t\t\treturn __( 'Resize from left edge' );\n\t\tcase 'nw':\n\t\t\treturn __( 'Resize from top-left corner' );\n\t\tcase 'ne':\n\t\t\treturn __( 'Resize from top-right corner' );\n\t\tcase 'sw':\n\t\t\treturn __( 'Resize from bottom-left corner' );\n\t\tcase 'se':\n\t\t\treturn __( 'Resize from bottom-right corner' );\n\t}\n}\n\n/** Delay before keyboard resize triggers settle (ms). */\nconst KEYBOARD_SETTLE_DELAY = 500;\n\n/**\n * Props for the RectangleStencil component.\n */\ntype RectangleStencilProps = StencilProps;\n\n/**\n * A rectangular crop stencil with resize handles.\n *\n * In freeform mode, handles resize the crop area. Clicks inside the\n * crop pass through to the container for image panning. The crop\n * auto-centers after resize via SETTLE_CROP.\n *\n * @param props Component props implementing StencilProps.\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 * @param props.onCropChange Callback fired when the crop rect changes.\n * @param props.onResizeStart Callback fired when a resize drag starts.\n * @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).\n * @param props.aspectRatio Optional fixed aspect ratio (width / height).\n * @param props.freeformCrop Whether resize handles are shown.\n * @param props.isResizeDisabled Whether resize handles should ignore pointer and keyboard input.\n * @param props.stencilTransition CSS transition string for settle animation.\n * @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).\n * @param props.onEscape Called when Escape is pressed on a resize handle.\n * @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @param props.snapCropRect Optional post-processor for freeform resize output.\n * @param props.keyboardResizeStep Optional keyboard resize step in normalized space, per axis.\n * @return The rectangle stencil element.\n */\nexport function RectangleStencil( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\tonCropChange,\n\tonResizeStart,\n\tonResizeEnd,\n\taspectRatio,\n\tfreeformCrop = false,\n\tisResizeDisabled = false,\n\tstencilTransition,\n\tcropBounds,\n\tonEscape,\n\tminCropSize,\n\tsnapCropRect,\n\tkeyboardResizeStep,\n}: RectangleStencilProps ) {\n\t// Use cropBounds from the camera if available, otherwise default to [0,1].\n\tconst boundsMinX = cropBounds?.minX ?? 0;\n\tconst boundsMinY = cropBounds?.minY ?? 0;\n\tconst boundsMaxX = cropBounds?.maxX ?? 1;\n\tconst boundsMaxY = cropBounds?.maxY ?? 1;\n\tconst bounds: CropBounds = useMemo(\n\t\t() => ( {\n\t\t\tminX: boundsMinX,\n\t\t\tminY: boundsMinY,\n\t\t\tmaxX: boundsMaxX,\n\t\t\tmaxY: boundsMaxY,\n\t\t} ),\n\t\t[ boundsMinX, boundsMinY, boundsMaxX, boundsMaxY ]\n\t);\n\tconst keyboardSettleTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\tconst keyboardResizeActiveRef = useRef( false );\n\tconst resizeHandleDescriptionId = useId();\n\tconst hasLockedRatio = !! ( aspectRatio && aspectRatio > 0 );\n\tconst activePointerResizeRef = useRef< {\n\t\tcancel: ( notifyResizeEnd?: boolean ) => void;\n\t} | null >( null );\n\n\t// Clear the pending keyboard settle timer on unmount so it can't\n\t// fire onResizeEnd / dispatch onto an unmounted parent.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\tactivePointerResizeRef.current?.cancel( false );\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isResizeDisabled ) {\n\t\t\tactivePointerResizeRef.current?.cancel();\n\t\t}\n\t}, [ isResizeDisabled ] );\n\n\t// Latest callbacks for the drag listeners. The drag closure in\n\t// handlePointerDown reads from this ref so it always sees current\n\t// props without having to re-attach listeners mid-drag. Previously,\n\t// drag listeners lived in a useEffect that re-ran whenever `bounds`\n\t// changed (every SET_CROP_RECT dispatch), creating a window where\n\t// pointerup could be missed and the crop would never settle.\n\tconst latestHandlersRef = useRef< {\n\t\thasLockedRatio: boolean;\n\t\tcomputeLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number,\n\t\t\tdriverAxis?: ResizeDriverAxis\n\t\t) => NormalizedRect;\n\t\tcomputeFreeRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tcomputeShiftLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tonCropChange: ( rect: NormalizedRect ) => void;\n\t\tonResizeEnd?: () => void;\n\t\tsnapCropRect?: (\n\t\t\trect: NormalizedRect,\n\t\t\thandle: HandlePosition\n\t\t) => NormalizedRect;\n\t} | null >( null );\n\n\t// The normalized aspect ratio: the w/h ratio in normalized space that\n\t// produces the desired pixel aspect ratio.\n\t// pixelW = w * imageSize.width, pixelH = h * imageSize.height\n\t// pixelW / pixelH = aspectRatio => w / h = aspectRatio * imageSize.height / imageSize.width\n\tconst normalizedRatio = useMemo( () => {\n\t\tif ( ! hasLockedRatio || imageSize.width === 0 ) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn ( aspectRatio * imageSize.height ) / imageSize.width;\n\t}, [ aspectRatio, hasLockedRatio, imageSize.width, imageSize.height ] );\n\n\t// Convert normalized crop rect to pixel bounds, accounting for the\n\t// image offset within the container.\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/**\n\t * Start a resize drag on a handle. Registers pointer listeners\n\t * synchronously so no events are missed between capture and the\n\t * next React commit.\n\t */\n\tconst handlePointerDown = useCallback(\n\t\t( handle: HandlePosition, event: React.PointerEvent ) => {\n\t\t\tif (\n\t\t\t\tisResizeDisabled ||\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\tevent.stopPropagation();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t\t// Blur any previously focused handle.\n\t\t\tconst ownerDoc = event.currentTarget.ownerDocument;\n\t\t\tif ( ownerDoc.activeElement instanceof HTMLElement ) {\n\t\t\t\townerDoc.activeElement.blur();\n\t\t\t}\n\t\t\t// Capture pointer so drag works across iframe boundaries.\n\t\t\tconst el = event.currentTarget as HTMLButtonElement;\n\t\t\tel.setPointerCapture( event.pointerId );\n\n\t\t\tconst drag: ResizeDragState = {\n\t\t\t\thandle,\n\t\t\t\tstartX: event.clientX,\n\t\t\t\tstartY: event.clientY,\n\t\t\t\tstartRect: { ...cropRect },\n\t\t\t};\n\n\t\t\t// RAF-throttle: stash the latest pointer position and\n\t\t\t// process it once per animation frame. Avoids dispatching\n\t\t\t// on every pointermove (which fires at much higher than\n\t\t\t// screen refresh rate) and matches the pan-drag path in\n\t\t\t// InteractionController.\n\t\t\tlet rafId = 0;\n\t\t\tlet latestX = event.clientX;\n\t\t\tlet latestY = event.clientY;\n\t\t\tlet latestShift = event.shiftKey;\n\n\t\t\tconst onMove = ( e: Event ) => {\n\t\t\t\tconst pe = e as PointerEvent;\n\t\t\t\tlatestX = pe.clientX;\n\t\t\t\tlatestY = pe.clientY;\n\t\t\t\tlatestShift = pe.shiftKey;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\trafId = requestAnimationFrame( () => {\n\t\t\t\t\trafId = 0;\n\t\t\t\t\tconst h = latestHandlersRef.current;\n\t\t\t\t\tif ( ! h ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet newRect: NormalizedRect;\n\t\t\t\t\tif ( h.hasLockedRatio ) {\n\t\t\t\t\t\tnewRect = h.computeLockedRect( drag, latestX, latestY );\n\t\t\t\t\t} else if ( latestShift ) {\n\t\t\t\t\t\tnewRect = h.computeShiftLockedRect(\n\t\t\t\t\t\t\tdrag,\n\t\t\t\t\t\t\tlatestX,\n\t\t\t\t\t\t\tlatestY\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewRect = h.computeFreeRect( drag, latestX, latestY );\n\t\t\t\t\t\tnewRect =\n\t\t\t\t\t\t\th.snapCropRect?.( newRect, drag.handle ) ?? newRect;\n\t\t\t\t\t}\n\t\t\t\t\th.onCropChange( newRect );\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Guard against duplicate firing: pointerup and\n\t\t\t// lostpointercapture both fire on normal release.\n\t\t\tlet ended = false;\n\t\t\tconst endResize = (\n\t\t\t\tnotifyResizeEnd = true,\n\t\t\t\trestoreFocus = true\n\t\t\t) => {\n\t\t\t\tif ( ended ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tended = true;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\tcancelAnimationFrame( rafId );\n\t\t\t\t\trafId = 0;\n\t\t\t\t}\n\t\t\t\tel.removeEventListener( 'pointermove', onMove );\n\t\t\t\tel.removeEventListener( 'pointerup', onEnd );\n\t\t\t\tel.removeEventListener( 'lostpointercapture', onEnd );\n\t\t\t\tactivePointerResizeRef.current = null;\n\t\t\t\tif ( notifyResizeEnd ) {\n\t\t\t\t\tlatestHandlersRef.current?.onResizeEnd?.();\n\t\t\t\t}\n\t\t\t\t// Restore focus to the handle so arrow keys work\n\t\t\t\t// immediately after a mouse drag. Browsers suppress\n\t\t\t\t// :focus-visible after pointer interactions, so the\n\t\t\t\t// focus ring stays hidden until the user presses a key.\n\t\t\t\tif ( restoreFocus ) {\n\t\t\t\t\tel.focus( { preventScroll: true } );\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst cancelResize = ( notifyResizeEnd = true ) =>\n\t\t\t\tendResize( notifyResizeEnd, false );\n\t\t\tconst onEnd = () => endResize();\n\n\t\t\tel.addEventListener( 'pointermove', onMove );\n\t\t\tel.addEventListener( 'pointerup', onEnd );\n\t\t\tel.addEventListener( 'lostpointercapture', onEnd );\n\t\t\tactivePointerResizeRef.current = { cancel: cancelResize };\n\n\t\t\tonResizeStart?.( handle );\n\t\t\t// Cancel any pending keyboard settle so it can't fire onResizeEnd\n\t\t\t// mid-drag if the user switches from keyboard to pointer within\n\t\t\t// the settle window.\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t},\n\t\t[ cropRect, isResizeDisabled, onResizeStart ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a free (no aspect ratio) resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeFreeRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeFreeResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a locked-aspect-ratio corner resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number,\n\t\t\tdriverAxis?: ResizeDriverAxis\n\t\t): NormalizedRect =>\n\t\t\tcomputeLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tnormalizedRatio,\n\t\t\t\tminCropSize,\n\t\t\t\tdriverAxis\n\t\t\t),\n\t\t[ imageSize, bounds, normalizedRatio, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect when Shift is held during a freeform\n\t * resize — preserves the start rect's aspect ratio.\n\t */\n\tconst computeShiftLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeShiftLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\tlatestHandlersRef.current = {\n\t\thasLockedRatio,\n\t\tcomputeLockedRect,\n\t\tcomputeFreeRect,\n\t\tcomputeShiftLockedRect,\n\t\tonCropChange,\n\t\tonResizeEnd,\n\t\tsnapCropRect,\n\t};\n\n\t/**\n\t * Handle keyboard events on a resize handle.\n\t * Arrow keys resize; Escape returns focus to the canvas.\n\t * Shift multiplies the step size by 10 for coarser movement.\n\t */\n\tconst handleKeyDown = useCallback(\n\t\t( handle: HandlePosition, event: React.KeyboardEvent ) => {\n\t\t\tconst key = event.key;\n\n\t\t\tif ( isResizeDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( key === 'Escape' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tonEscape?.();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tkey !== 'ArrowUp' &&\n\t\t\t\tkey !== 'ArrowDown' &&\n\t\t\t\tkey !== 'ArrowLeft' &&\n\t\t\t\tkey !== 'ArrowRight'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\n\t\t\tif ( ! keyboardResizeActiveRef.current ) {\n\t\t\t\tkeyboardResizeActiveRef.current = true;\n\t\t\t\tonResizeStart?.( handle );\n\t\t\t}\n\n\t\t\tconst scheduleKeyboardResizeEnd = () => {\n\t\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\t\tkeyboardSettleTimerRef.current = setTimeout( () => {\n\t\t\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\t\t\tonResizeEnd?.();\n\t\t\t\t}, KEYBOARD_SETTLE_DELAY );\n\t\t\t};\n\n\t\t\tconst stepMultiplier = event.shiftKey\n\t\t\t\t? KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t\t: 1;\n\t\t\tconst stepX = keyboardResizeStep?.width ?? DEFAULT_KEYBOARD_STEP;\n\t\t\tconst stepY = keyboardResizeStep?.height ?? DEFAULT_KEYBOARD_STEP;\n\t\t\tconst adjustedStepX = stepX * stepMultiplier;\n\t\t\tconst adjustedStepY = stepY * stepMultiplier;\n\n\t\t\t// Determine the normalized delta from the arrow key.\n\t\t\tlet dx = 0;\n\t\t\tlet dy = 0;\n\t\t\tif ( key === 'ArrowLeft' ) {\n\t\t\t\tdx = -adjustedStepX;\n\t\t\t}\n\t\t\tif ( key === 'ArrowRight' ) {\n\t\t\t\tdx = adjustedStepX;\n\t\t\t}\n\t\t\tif ( key === 'ArrowUp' ) {\n\t\t\t\tdy = -adjustedStepY;\n\t\t\t}\n\t\t\tif ( key === 'ArrowDown' ) {\n\t\t\t\tdy = adjustedStepY;\n\t\t\t}\n\t\t\tconst keyboardDriverAxis: ResizeDriverAxis =\n\t\t\t\tdx !== 0 ? 'width' : 'height';\n\n\t\t\tif ( hasLockedRatio ) {\n\t\t\t\t// For locked aspect ratio, synthesize a drag from the\n\t\t\t\t// current rect and apply the delta via computeLockedRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tonCropChange(\n\t\t\t\t\tcomputeLockedRect(\n\t\t\t\t\t\tsyntheticDrag,\n\t\t\t\t\t\tclientX,\n\t\t\t\t\t\tclientY,\n\t\t\t\t\t\tkeyboardDriverAxis\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t} else {\n\t\t\t\t// For freeform resize, synthesize a drag via computeFreeRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tconst rect = computeFreeRect( syntheticDrag, clientX, clientY );\n\t\t\t\tonCropChange( snapCropRect?.( rect, handle ) ?? rect );\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tcropRect,\n\t\t\thasLockedRatio,\n\t\t\timageSize.width,\n\t\t\timageSize.height,\n\t\t\tcomputeLockedRect,\n\t\t\tcomputeFreeRect,\n\t\t\tonCropChange,\n\t\t\tonResizeStart,\n\t\t\tonResizeEnd,\n\t\t\tonEscape,\n\t\t\tkeyboardResizeStep,\n\t\t\tsnapCropRect,\n\t\t\tisResizeDisabled,\n\t\t]\n\t);\n\n\tif ( containerSize.width === 0 || containerSize.height === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-media-editor-image-editor__stencil\"\n\t\t\tdata-testid=\"cropper-stencil\"\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: stencilTransition,\n\t\t\t} }\n\t\t>\n\t\t\t{ freeformCrop && (\n\t\t\t\t<div\n\t\t\t\t\tid={ resizeHandleDescriptionId }\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'Use arrow keys to resize the crop area. Hold Shift for larger steps.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /* The crop rectangle border. pointer-events: none is set in\n\t\t\t\t CSS so clicks pass through to the container for panning. */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__stencil-rect\"\n\t\t\t\tstyle={ {\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\theight: '100%',\n\t\t\t\t\ttop: 0,\n\t\t\t\t\tleft: 0,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t{ /* Resize handles — only in freeform mode.\n\t\t\t\t Semantics: role=\"button\" with aria-label describing\n\t\t\t\t which edge/corner. Arrow keys resize (onKeyDown).\n\t\t\t\t role=\"slider\" would be more precise but requires\n\t\t\t\t per-handle aria-valuemin/max/now which don't map\n\t\t\t\t cleanly to a 2D crop rect. */ }\n\t\t\t{ freeformCrop &&\n\t\t\t\thandles.map( ( pos ) => (\n\t\t\t\t\t<button\n\t\t\t\t\t\tkey={ pos }\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName={ `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${ pos }` }\n\t\t\t\t\t\tonPointerDown={ ( event ) =>\n\t\t\t\t\t\t\thandlePointerDown( pos, event )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonTouchStart={ ( event ) => {\n\t\t\t\t\t\t\tif ( event.touches.length < 2 ) {\n\t\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonKeyDown={ ( event ) => handleKeyDown( pos, event ) }\n\t\t\t\t\t\taria-label={ getHandleLabel( pos ) }\n\t\t\t\t\t\taria-describedby={ resizeHandleDescriptionId }\n\t\t\t\t\t/>\n\t\t\t\t) ) }\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import {\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseMemo,\n\tuseRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport type { StencilProps, NormalizedRect } from '../../../core/types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n} from '../../../core/constants';\nimport {\n\tcomputeFreeResizeRect,\n\tcomputeLockedResizeRect,\n\tcomputeShiftLockedResizeRect,\n\ttype HandlePosition,\n\ttype CropBounds,\n\ttype ResizeDragState,\n\ttype ResizeDriverAxis,\n} from '../../../core/stencil-math';\nimport { VISUALLY_HIDDEN_STYLE } from '../../visually-hidden-style';\n\n/**\n * Corner handle positions only — used when aspect ratio is locked.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst CORNER_POSITIONS: HandlePosition[] = [ 'nw', 'ne', 'se', 'sw' ];\n\n/**\n * All handle positions rendered by the stencil.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst ALL_POSITIONS: HandlePosition[] = [\n\t'nw',\n\t'n',\n\t'ne',\n\t'e',\n\t'se',\n\t's',\n\t'sw',\n\t'w',\n];\n\n/**\n * Get the translated aria-label for a resize handle position.\n *\n * @param pos The handle position identifier.\n * @return The translated label string.\n */\nfunction getHandleLabel( pos: HandlePosition ): string {\n\tswitch ( pos ) {\n\t\tcase 'n':\n\t\t\treturn __( 'Resize from top edge' );\n\t\tcase 's':\n\t\t\treturn __( 'Resize from bottom edge' );\n\t\tcase 'e':\n\t\t\treturn __( 'Resize from right edge' );\n\t\tcase 'w':\n\t\t\treturn __( 'Resize from left edge' );\n\t\tcase 'nw':\n\t\t\treturn __( 'Resize from top-left corner' );\n\t\tcase 'ne':\n\t\t\treturn __( 'Resize from top-right corner' );\n\t\tcase 'sw':\n\t\t\treturn __( 'Resize from bottom-left corner' );\n\t\tcase 'se':\n\t\t\treturn __( 'Resize from bottom-right corner' );\n\t}\n}\n\n/** Delay before keyboard resize triggers settle (ms). */\nconst KEYBOARD_SETTLE_DELAY = 500;\n\n/**\n * Props for the RectangleStencil component.\n */\ntype RectangleStencilProps = StencilProps;\n\n/**\n * A rectangular crop stencil with resize handles.\n *\n * In freeform mode, handles resize the crop area. Clicks inside the\n * crop pass through to the container for image panning. The crop\n * auto-centers after resize via SETTLE_CROP.\n *\n * @param props Component props implementing StencilProps.\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 * @param props.onCropChange Callback fired when the crop rect changes.\n * @param props.onResizeStart Callback fired when a resize drag starts.\n * @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).\n * @param props.aspectRatio Optional fixed aspect ratio (width / height).\n * @param props.freeformCrop Whether resize handles are shown.\n * @param props.isResizeDisabled Whether resize handles should ignore pointer and keyboard input.\n * @param props.stencilTransition CSS transition string for settle animation.\n * @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).\n * @param props.onEscape Called when Escape is pressed on a resize handle.\n * @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @param props.snapCropRect Optional post-processor for freeform resize output.\n * @param props.keyboardResizeStep Optional keyboard resize step in normalized space, per axis.\n * @return The rectangle stencil element.\n */\nexport function RectangleStencil( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\tonCropChange,\n\tonResizeStart,\n\tonResizeEnd,\n\taspectRatio,\n\tfreeformCrop = false,\n\tisResizeDisabled = false,\n\tstencilTransition,\n\tcropBounds,\n\tonEscape,\n\tminCropSize,\n\tsnapCropRect,\n\tkeyboardResizeStep,\n}: RectangleStencilProps ) {\n\t// Use cropBounds from the camera if available, otherwise default to [0,1].\n\tconst boundsMinX = cropBounds?.minX ?? 0;\n\tconst boundsMinY = cropBounds?.minY ?? 0;\n\tconst boundsMaxX = cropBounds?.maxX ?? 1;\n\tconst boundsMaxY = cropBounds?.maxY ?? 1;\n\tconst bounds: CropBounds = useMemo(\n\t\t() => ( {\n\t\t\tminX: boundsMinX,\n\t\t\tminY: boundsMinY,\n\t\t\tmaxX: boundsMaxX,\n\t\t\tmaxY: boundsMaxY,\n\t\t} ),\n\t\t[ boundsMinX, boundsMinY, boundsMaxX, boundsMaxY ]\n\t);\n\tconst keyboardSettleTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\tconst keyboardResizeActiveRef = useRef( false );\n\tconst resizeHandleDescriptionId = useId();\n\tconst hasLockedRatio = !! ( aspectRatio && aspectRatio > 0 );\n\tconst activePointerResizeRef = useRef< {\n\t\tcancel: ( notifyResizeEnd?: boolean ) => void;\n\t} | null >( null );\n\n\t// Clear the pending keyboard settle timer on unmount so it can't\n\t// fire onResizeEnd / dispatch onto an unmounted parent.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\tactivePointerResizeRef.current?.cancel( false );\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isResizeDisabled ) {\n\t\t\tactivePointerResizeRef.current?.cancel();\n\t\t}\n\t}, [ isResizeDisabled ] );\n\n\t// Latest callbacks for the drag listeners. The drag closure in\n\t// handlePointerDown reads from this ref so it always sees current\n\t// props without having to re-attach listeners mid-drag. Previously,\n\t// drag listeners lived in a useEffect that re-ran whenever `bounds`\n\t// changed (every SET_CROP_RECT dispatch), creating a window where\n\t// pointerup could be missed and the crop would never settle.\n\tconst latestHandlersRef = useRef< {\n\t\thasLockedRatio: boolean;\n\t\tcomputeLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number,\n\t\t\tdriverAxis?: ResizeDriverAxis\n\t\t) => NormalizedRect;\n\t\tcomputeFreeRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tcomputeShiftLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tonCropChange: ( rect: NormalizedRect ) => void;\n\t\tonResizeEnd?: () => void;\n\t\tsnapCropRect?: (\n\t\t\trect: NormalizedRect,\n\t\t\thandle: HandlePosition\n\t\t) => NormalizedRect;\n\t} | null >( null );\n\n\t// The normalized aspect ratio: the w/h ratio in normalized space that\n\t// produces the desired pixel aspect ratio.\n\t// pixelW = w * imageSize.width, pixelH = h * imageSize.height\n\t// pixelW / pixelH = aspectRatio => w / h = aspectRatio * imageSize.height / imageSize.width\n\tconst normalizedRatio = useMemo( () => {\n\t\tif ( ! hasLockedRatio || imageSize.width === 0 ) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn ( aspectRatio * imageSize.height ) / imageSize.width;\n\t}, [ aspectRatio, hasLockedRatio, imageSize.width, imageSize.height ] );\n\n\t// Convert normalized crop rect to pixel bounds, accounting for the\n\t// image offset within the container.\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/**\n\t * Start a resize drag on a handle. Registers pointer listeners\n\t * synchronously so no events are missed between capture and the\n\t * next React commit.\n\t */\n\tconst handlePointerDown = useCallback(\n\t\t( handle: HandlePosition, event: React.PointerEvent ) => {\n\t\t\tif (\n\t\t\t\tisResizeDisabled ||\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\tevent.stopPropagation();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t\t// Blur any previously focused handle.\n\t\t\tconst ownerDoc = event.currentTarget.ownerDocument;\n\t\t\tif ( ownerDoc.activeElement instanceof HTMLElement ) {\n\t\t\t\townerDoc.activeElement.blur();\n\t\t\t}\n\t\t\t// Capture pointer so drag works across iframe boundaries.\n\t\t\tconst el = event.currentTarget as HTMLButtonElement;\n\t\t\tel.setPointerCapture( event.pointerId );\n\n\t\t\tconst drag: ResizeDragState = {\n\t\t\t\thandle,\n\t\t\t\tstartX: event.clientX,\n\t\t\t\tstartY: event.clientY,\n\t\t\t\tstartRect: { ...cropRect },\n\t\t\t};\n\n\t\t\t// RAF-throttle: stash the latest pointer position and\n\t\t\t// process it once per animation frame. Avoids dispatching\n\t\t\t// on every pointermove (which fires at much higher than\n\t\t\t// screen refresh rate) and matches the pan-drag path in\n\t\t\t// InteractionController.\n\t\t\tlet rafId = 0;\n\t\t\tlet latestX = event.clientX;\n\t\t\tlet latestY = event.clientY;\n\t\t\tlet latestShift = event.shiftKey;\n\n\t\t\tconst onMove = ( e: Event ) => {\n\t\t\t\tconst pe = e as PointerEvent;\n\t\t\t\tlatestX = pe.clientX;\n\t\t\t\tlatestY = pe.clientY;\n\t\t\t\tlatestShift = pe.shiftKey;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\trafId = requestAnimationFrame( () => {\n\t\t\t\t\trafId = 0;\n\t\t\t\t\tconst h = latestHandlersRef.current;\n\t\t\t\t\tif ( ! h ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet newRect: NormalizedRect;\n\t\t\t\t\tif ( h.hasLockedRatio ) {\n\t\t\t\t\t\tnewRect = h.computeLockedRect( drag, latestX, latestY );\n\t\t\t\t\t} else if ( latestShift ) {\n\t\t\t\t\t\tnewRect = h.computeShiftLockedRect(\n\t\t\t\t\t\t\tdrag,\n\t\t\t\t\t\t\tlatestX,\n\t\t\t\t\t\t\tlatestY\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewRect = h.computeFreeRect( drag, latestX, latestY );\n\t\t\t\t\t\tnewRect =\n\t\t\t\t\t\t\th.snapCropRect?.( newRect, drag.handle ) ?? newRect;\n\t\t\t\t\t}\n\t\t\t\t\th.onCropChange( newRect );\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Guard against duplicate firing: pointerup and\n\t\t\t// lostpointercapture both fire on normal release.\n\t\t\tlet ended = false;\n\t\t\tconst endResize = (\n\t\t\t\tnotifyResizeEnd = true,\n\t\t\t\trestoreFocus = true\n\t\t\t) => {\n\t\t\t\tif ( ended ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tended = true;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\tcancelAnimationFrame( rafId );\n\t\t\t\t\trafId = 0;\n\t\t\t\t}\n\t\t\t\tel.removeEventListener( 'pointermove', onMove );\n\t\t\t\tel.removeEventListener( 'pointerup', onEnd );\n\t\t\t\tel.removeEventListener( 'lostpointercapture', onEnd );\n\t\t\t\tactivePointerResizeRef.current = null;\n\t\t\t\tif ( notifyResizeEnd ) {\n\t\t\t\t\tlatestHandlersRef.current?.onResizeEnd?.();\n\t\t\t\t}\n\t\t\t\t// Restore focus to the handle so arrow keys work\n\t\t\t\t// immediately after a mouse drag. Browsers suppress\n\t\t\t\t// :focus-visible after pointer interactions, so the\n\t\t\t\t// focus ring stays hidden until the user presses a key.\n\t\t\t\tif ( restoreFocus ) {\n\t\t\t\t\tel.focus( { preventScroll: true } );\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst cancelResize = ( notifyResizeEnd = true ) =>\n\t\t\t\tendResize( notifyResizeEnd, false );\n\t\t\tconst onEnd = () => endResize();\n\n\t\t\tel.addEventListener( 'pointermove', onMove );\n\t\t\tel.addEventListener( 'pointerup', onEnd );\n\t\t\tel.addEventListener( 'lostpointercapture', onEnd );\n\t\t\tactivePointerResizeRef.current = { cancel: cancelResize };\n\n\t\t\tonResizeStart?.( handle );\n\t\t\t// Cancel any pending keyboard settle so it can't fire onResizeEnd\n\t\t\t// mid-drag if the user switches from keyboard to pointer within\n\t\t\t// the settle window.\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t},\n\t\t[ cropRect, isResizeDisabled, onResizeStart ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a free (no aspect ratio) resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeFreeRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeFreeResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a locked-aspect-ratio corner resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number,\n\t\t\tdriverAxis?: ResizeDriverAxis\n\t\t): NormalizedRect =>\n\t\t\tcomputeLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tnormalizedRatio,\n\t\t\t\tminCropSize,\n\t\t\t\tdriverAxis\n\t\t\t),\n\t\t[ imageSize, bounds, normalizedRatio, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect when Shift is held during a freeform\n\t * resize — preserves the start rect's aspect ratio.\n\t */\n\tconst computeShiftLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeShiftLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\tlatestHandlersRef.current = {\n\t\thasLockedRatio,\n\t\tcomputeLockedRect,\n\t\tcomputeFreeRect,\n\t\tcomputeShiftLockedRect,\n\t\tonCropChange,\n\t\tonResizeEnd,\n\t\tsnapCropRect,\n\t};\n\n\t/**\n\t * Handle keyboard events on a resize handle.\n\t * Arrow keys resize; Escape returns focus to the canvas.\n\t * Shift multiplies the step size by 10 for coarser movement.\n\t */\n\tconst handleKeyDown = useCallback(\n\t\t( handle: HandlePosition, event: React.KeyboardEvent ) => {\n\t\t\tconst key = event.key;\n\n\t\t\tif ( isResizeDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( key === 'Escape' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tonEscape?.();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tkey !== 'ArrowUp' &&\n\t\t\t\tkey !== 'ArrowDown' &&\n\t\t\t\tkey !== 'ArrowLeft' &&\n\t\t\t\tkey !== 'ArrowRight'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\n\t\t\tif ( ! keyboardResizeActiveRef.current ) {\n\t\t\t\tkeyboardResizeActiveRef.current = true;\n\t\t\t\tonResizeStart?.( handle );\n\t\t\t}\n\n\t\t\tconst scheduleKeyboardResizeEnd = () => {\n\t\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\t\tkeyboardSettleTimerRef.current = setTimeout( () => {\n\t\t\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\t\t\tonResizeEnd?.();\n\t\t\t\t}, KEYBOARD_SETTLE_DELAY );\n\t\t\t};\n\n\t\t\tconst stepMultiplier = event.shiftKey\n\t\t\t\t? KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t\t: 1;\n\t\t\tconst stepX = keyboardResizeStep?.width ?? DEFAULT_KEYBOARD_STEP;\n\t\t\tconst stepY = keyboardResizeStep?.height ?? DEFAULT_KEYBOARD_STEP;\n\t\t\tconst adjustedStepX = stepX * stepMultiplier;\n\t\t\tconst adjustedStepY = stepY * stepMultiplier;\n\n\t\t\t// Determine the normalized delta from the arrow key.\n\t\t\tlet dx = 0;\n\t\t\tlet dy = 0;\n\t\t\tif ( key === 'ArrowLeft' ) {\n\t\t\t\tdx = -adjustedStepX;\n\t\t\t}\n\t\t\tif ( key === 'ArrowRight' ) {\n\t\t\t\tdx = adjustedStepX;\n\t\t\t}\n\t\t\tif ( key === 'ArrowUp' ) {\n\t\t\t\tdy = -adjustedStepY;\n\t\t\t}\n\t\t\tif ( key === 'ArrowDown' ) {\n\t\t\t\tdy = adjustedStepY;\n\t\t\t}\n\t\t\tconst keyboardDriverAxis: ResizeDriverAxis =\n\t\t\t\tdx !== 0 ? 'width' : 'height';\n\n\t\t\tif ( hasLockedRatio ) {\n\t\t\t\t// For locked aspect ratio, synthesize a drag from the\n\t\t\t\t// current rect and apply the delta via computeLockedRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tonCropChange(\n\t\t\t\t\tcomputeLockedRect(\n\t\t\t\t\t\tsyntheticDrag,\n\t\t\t\t\t\tclientX,\n\t\t\t\t\t\tclientY,\n\t\t\t\t\t\tkeyboardDriverAxis\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t} else {\n\t\t\t\t// For freeform resize, synthesize a drag via computeFreeRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tconst rect = computeFreeRect( syntheticDrag, clientX, clientY );\n\t\t\t\tonCropChange( snapCropRect?.( rect, handle ) ?? rect );\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tcropRect,\n\t\t\thasLockedRatio,\n\t\t\timageSize.width,\n\t\t\timageSize.height,\n\t\t\tcomputeLockedRect,\n\t\t\tcomputeFreeRect,\n\t\t\tonCropChange,\n\t\t\tonResizeStart,\n\t\t\tonResizeEnd,\n\t\t\tonEscape,\n\t\t\tkeyboardResizeStep,\n\t\t\tsnapCropRect,\n\t\t\tisResizeDisabled,\n\t\t]\n\t);\n\n\tif ( containerSize.width === 0 || containerSize.height === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-media-editor-image-editor__stencil\"\n\t\t\tdata-testid=\"cropper-stencil\"\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: stencilTransition,\n\t\t\t} }\n\t\t>\n\t\t\t{ freeformCrop && (\n\t\t\t\t<div\n\t\t\t\t\tid={ resizeHandleDescriptionId }\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'Use arrow keys to resize the crop area. Hold Shift for larger steps.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /* The crop rectangle border. pointer-events: none is set in\n\t\t\t\t CSS so clicks pass through to the container for panning. */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__stencil-rect\"\n\t\t\t\tstyle={ {\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\theight: '100%',\n\t\t\t\t\ttop: 0,\n\t\t\t\t\tleft: 0,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t{ /* Resize handles — only in freeform mode.\n\t\t\t\t Semantics: role=\"button\" with aria-label describing\n\t\t\t\t which edge/corner. Arrow keys resize (onKeyDown).\n\t\t\t\t role=\"slider\" would be more precise but requires\n\t\t\t\t per-handle aria-valuemin/max/now which don't map\n\t\t\t\t cleanly to a 2D crop rect. */ }\n\t\t\t{ freeformCrop &&\n\t\t\t\thandles.map( ( pos ) => (\n\t\t\t\t\t<button\n\t\t\t\t\t\tkey={ pos }\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName={ `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${ pos }` }\n\t\t\t\t\t\tonPointerDown={ ( event ) =>\n\t\t\t\t\t\t\thandlePointerDown( pos, event )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonTouchStart={ ( event ) => {\n\t\t\t\t\t\t\tif ( event.touches.length < 2 ) {\n\t\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonKeyDown={ ( event ) => handleKeyDown( pos, event ) }\n\t\t\t\t\t\taria-label={ getHandleLabel( pos ) }\n\t\t\t\t\t\taria-describedby={ resizeHandleDescriptionId }\n\t\t\t\t\t/>\n\t\t\t\t) ) }\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAMO;AACP,kBAAmB;AAEnB,uBAGO;AACP,0BAQO;AACP,mCAAsC;AA2gBpC;AArgBF,IAAM,mBAAqC,CAAE,MAAM,MAAM,MAAM,IAAK;AAMpE,IAAM,gBAAkC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAQA,SAAS,eAAgB,KAA8B;AACtD,UAAS,KAAM;AAAA,IACd,KAAK;AACJ,iBAAO,gBAAI,sBAAuB;AAAA,IACnC,KAAK;AACJ,iBAAO,gBAAI,yBAA0B;AAAA,IACtC,KAAK;AACJ,iBAAO,gBAAI,wBAAyB;AAAA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tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseViewportState,\n\ttype UseViewportStateReturn,\n} from '../hooks/use-viewport-state';\n\ntype ViewportContextValue = UseViewportStateReturn;\n\nconst ViewportContext = createContext< ViewportContextValue | null >( null );\n\nexport function ViewportProvider( {\n\tchildren,\n}: {\n\tchildren: React.ReactNode;\n} ) {\n\tconst viewportState = useViewportState();\n\treturn (\n\t\t<ViewportContext.Provider value={ viewportState }>\n\t\t\t{ children }\n\t\t</ViewportContext.Provider>\n\t);\n}\n\nexport function useViewport(): UseViewportStateReturn {\n\tconst context = useContext( ViewportContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useViewport must be used within a ViewportProvider.'\n\t\t);\n\t}\n\treturn context;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0C;AAC1C,gCAGO;AAaL;AATF,IAAM,sBAAkB,8BAA8C,IAAK;AAEpE,SAAS,iBAAkB;AAAA,EACjC;AACD,GAEI;AACH,QAAM,oBAAgB,4CAAiB;AACvC,SACC,4CAAC,gBAAgB,UAAhB,EAAyB,OAAQ,eAC/B,UACH;AAEF;AAEO,SAAS,cAAsC;AACrD,QAAM,cAAU,2BAAY,eAAgB;AAC5C,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/build-cropper-setters.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import type {\n\tCropperAction,\n\tCropperState,\n\tFlip,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tTransformOperation,\n} from '../../core/types';\nimport { buildFocalPointZoomAction } from '../../core/setter-helpers';\n\n/**\n * The named cropper setters shared by every hook that drives the\n * cropper reducer — the pure `useCropperReducer` and any composite\n * store that delegates cropper actions (e.g. `useMediaEditorState`).\n *\n * `setImage` and `reset` are intentionally NOT included: each hook\n * has additional bookkeeping for them (dirty-baseline, history clear)\n * that doesn't fit a shared factory.\n */\nexport interface CropperSetters {\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\tsetZoom: ( zoom: number ) => void;\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\tsetRotation: ( rotation: number ) => void;\n\tsetFlip: ( flip: Flip ) => void;\n\ttoggleFlip: ( direction: 'horizontal' | 'vertical' ) => void;\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\tsetCropRect: ( rect: NormalizedRect ) => void;\n\tsettleCrop: () => void;\n\tapplyOperation: ( op: TransformOperation ) => void;\n}\n\n/**\n * Build the named cropper setters from a dispatch function and a\n * state getter. The two consuming hooks differ in how they dispatch:\n *\n * - `useCropperReducer` dispatches directly into its `useReducer`.\n * - `useMediaEditorState` wraps cropper actions in a composite\n * `CROPPER` envelope so the history machinery can record them.\n *\n * Both pass their own dispatch function and a getter that returns\n * the current `CropperState`. The factory shape keeps the two hooks\n * in lockstep — add a setter here once, both hooks get it.\n *\n * @param dispatchCropperAction Apply a `CropperAction` to the\n * underlying reducer.\n * @param getCropperState Return the current `CropperState`.\n * Used by setters that need to read\n * the latest state to compute their\n * payload (focal-point zoom, flip toggle).\n * @return The named cropper setters.\n */\nexport function buildCropperSetters(\n\tdispatchCropperAction: ( action: CropperAction ) => void,\n\tgetCropperState: () => CropperState\n): CropperSetters {\n\treturn {\n\t\tsetPan: ( pan ) =>\n\t\t\tdispatchCropperAction( { type: 'SET_PAN', payload: pan } ),\n\t\tsetZoom: ( zoom ) => {\n\t\t\tconst action = buildFocalPointZoomAction( getCropperState(), zoom );\n\t\t\tif ( action ) {\n\t\t\t\tdispatchCropperAction( action );\n\t\t\t}\n\t\t},\n\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\t\t\tpayload: { zoom, pan },\n\t\t\t} ),\n\t\tsetRotation: ( rotation ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_ROTATION',\n\t\t\t\tpayload: rotation,\n\t\t\t} ),\n\t\tsetFlip: ( flip ) =>\n\t\t\tdispatchCropperAction( { type: 'SET_FLIP', payload: flip } ),\n\t\ttoggleFlip: ( direction ) => {\n\t\t\tconst { flip } = getCropperState();\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_FLIP',\n\t\t\t\tpayload: { ...flip, [ direction ]: ! flip[ direction ] },\n\t\t\t} );\n\t\t},\n\t\tsnapRotate90: ( direction ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SNAP_ROTATE_90',\n\t\t\t\tpayload: { direction },\n\t\t\t} ),\n\t\tsetCropRect: ( rect ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: rect,\n\t\t\t} ),\n\t\tsettleCrop: () => dispatchCropperAction( { type: 'SETTLE_CROP' } ),\n\t\tapplyOperation: ( op ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'APPLY_OPERATION',\n\t\t\t\tpayload: op,\n\t\t\t} ),\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,4BAA0C;AA4CnC,SAAS,oBACf,uBACA,iBACiB;AACjB,SAAO;AAAA,IACN,QAAQ,CAAE,QACT,sBAAuB,EAAE,MAAM,WAAW,SAAS,IAAI,CAAE;AAAA,IAC1D,SAAS,CAAE,SAAU;AACpB,YAAM,aAAS,iDAA2B,gBAAgB,GAAG,IAAK;AAClE,UAAK,QAAS;AACb,8BAAuB,MAAO;AAAA,MAC/B;AAAA,IACD;AAAA,IACA,gBAAgB,CAAE,MAAM,QACvB,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS,EAAE,MAAM,IAAI;AAAA,IACtB,CAAE;AAAA,IACH,aAAa,CAAE,aACd,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA,IACV,CAAE;AAAA,IACH,SAAS,CAAE,SACV,sBAAuB,EAAE,MAAM,YAAY,SAAS,KAAK,CAAE;AAAA,IAC5D,YAAY,CAAE,cAAe;AAC5B,YAAM,EAAE,KAAK,IAAI,gBAAgB;AACjC,4BAAuB;AAAA,QACtB,MAAM;AAAA,QACN,SAAS,EAAE,GAAG,MAAM,CAAE,SAAU,GAAG,CAAE,KAAM,SAAU,EAAE;AAAA,MACxD,CAAE;AAAA,IACH;AAAA,IACA,cAAc,CAAE,cACf,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS,EAAE,UAAU;AAAA,IACtB,CAAE;AAAA,IACH,aAAa,CAAE,SACd,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA,IACV,CAAE;AAAA,IACH,YAAY,MAAM,sBAAuB,EAAE,MAAM,cAAc,CAAE;AAAA,IACjE,gBAAgB,CAAE,OACjB,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA,IACV,CAAE;AAAA,EACJ;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-aria-announcer.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { speak } from '@wordpress/a11y';\nimport { useEffect, useLayoutEffect, useRef } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport type { CropperState } from '../../core/types';\nimport { getSourceRegion } from '../../core/source-region';\n\n/** Debounce delay for ARIA live announcements (ms). */\nconst ARIA_DEBOUNCE_MS = 300;\n\nfunction getFlipAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string | undefined {\n\tif (\n\t\t! previousState ||\n\t\t( previousState.flip.horizontal === state.flip.horizontal &&\n\t\t\tpreviousState.flip.vertical === state.flip.vertical )\n\t) {\n\t\treturn undefined;\n\t}\n\tconst { horizontal, vertical } = state.flip;\n\tif ( horizontal && vertical ) {\n\t\treturn __( 'Flipped horizontally and vertically' );\n\t}\n\tif ( horizontal ) {\n\t\treturn __( 'Flipped horizontally' );\n\t}\n\tif ( vertical ) {\n\t\treturn __( 'Flipped vertically' );\n\t}\n\treturn __( 'Flip removed' );\n}\n\nfunction getRotationAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string | undefined {\n\tif (\n\t\tpreviousState &&\n\t\tMath.round( previousState.rotation ) === Math.round( state.rotation )\n\t) {\n\t\treturn undefined;\n\t}\n\t// Announce the visual rotation — what the user perceives on screen. A\n\t// single-axis flip mirrors the image, reversing the entire on-screen\n\t// rotation relative to the stored field (the same S·R·S inversion the\n\t// reducer applies), so negate the whole angle in that case.\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\t// Normalize to (-180, 180] so the sign indicates direction.\n\tlet visualRotation = ( Math.round( state.rotation ) * visualDir ) % 360;\n\tif ( visualRotation > 180 ) {\n\t\tvisualRotation -= 360;\n\t}\n\tif ( visualRotation <= -180 ) {\n\t\tvisualRotation += 360;\n\t}\n\tif ( visualRotation === 0 ) {\n\t\treturn previousState ? __( 'Rotation 0 degrees' ) : undefined;\n\t}\n\tif ( visualRotation > 0 ) {\n\t\treturn sprintf(\n\t\t\t/* translators: %d: rotation angle in degrees. */\n\t\t\t__( 'Rotated %d degrees clockwise' ),\n\t\t\tvisualRotation\n\t\t);\n\t}\n\treturn sprintf(\n\t\t/* translators: %d: rotation angle in degrees. */\n\t\t__( 'Rotated %d degrees counterclockwise' ),\n\t\tMath.abs( visualRotation )\n\t);\n}\n\nfunction getCropAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string | undefined {\n\tif ( ! state.image ) {\n\t\treturn undefined;\n\t}\n\tconst imageSize = {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t};\n\tconst region = getSourceRegion( state, imageSize );\n\t// Announce only when the crop's pixel dimensions change. Measuring both the\n\t// previous and current crop rects under the current rotation and zoom keeps\n\t// the comparison in the same pixel units we announce, and leaves a zoom-only\n\t// change — which doesn't move the crop rect — silent.\n\tif ( previousState?.image ) {\n\t\tconst previousRegion = getSourceRegion(\n\t\t\t{ ...state, cropRect: previousState.cropRect },\n\t\t\timageSize\n\t\t);\n\t\tif (\n\t\t\tMath.round( previousRegion.width ) === Math.round( region.width ) &&\n\t\t\tMath.round( previousRegion.height ) === Math.round( region.height )\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t}\n\treturn sprintf(\n\t\t/* translators: 1: crop width in pixels, 2: crop height in pixels. */\n\t\t__( 'Crop %1$d by %2$d pixels' ),\n\t\tMath.round( region.width ),\n\t\tMath.round( region.height )\n\t);\n}\n\nfunction getZoomAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string | undefined {\n\tif (\n\t\tpreviousState &&\n\t\tMath.round( previousState.zoom * 100 ) ===\n\t\t\tMath.round( state.zoom * 100 )\n\t) {\n\t\treturn undefined;\n\t}\n\treturn sprintf(\n\t\t/* translators: %d: zoom level as a percentage. */\n\t\t__( 'Zoom %d%%' ),\n\t\tMath.round( state.zoom * 100 )\n\t);\n}\n\nfunction buildAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string {\n\t// Flip changes are announced alone.\n\tconst flip = getFlipAnnouncement( state, previousState );\n\tif ( flip ) {\n\t\treturn flip;\n\t}\n\n\tconst parts = [\n\t\tgetRotationAnnouncement( state, previousState ),\n\t\tgetZoomAnnouncement( state, previousState ),\n\t\tgetCropAnnouncement( state, previousState ),\n\t].filter( ( part ): part is string => part !== undefined );\n\n\treturn parts.join( ', ' );\n}\n\n/**\n * Debounce and dedupe ARIA-live announcements for screen readers as the\n * cropper state changes. Calls `speak()` from `@wordpress/a11y` to use the\n * centralized, persistent live region instead of a local one that may be\n * dynamically mounted.\n *\n * Debouncing avoids flooding announcements during drag/pointermove bursts;\n * deduping avoids re-announcing the same state.\n *\n * @param state The current cropper state to announce.\n */\nexport function useAriaAnnouncer( state: CropperState ): void {\n\tconst timerRef = useRef< ReturnType< typeof setTimeout > >();\n\tconst prevMessageRef = useRef( '' );\n\tconst prevStateRef = useRef< CropperState | null >( null );\n\tconst latestStateRef = useRef( state );\n\tuseLayoutEffect( () => {\n\t\tlatestStateRef.current = state;\n\t}, [ state ] );\n\n\tuseEffect( () => {\n\t\tclearTimeout( timerRef.current );\n\t\ttimerRef.current = setTimeout( () => {\n\t\t\tconst current = latestStateRef.current;\n\t\t\tconst msg = buildAnnouncement( current, prevStateRef.current );\n\t\t\tprevStateRef.current = current;\n\t\t\tif ( msg !== prevMessageRef.current ) {\n\t\t\t\tprevMessageRef.current = msg;\n\t\t\t\tspeak( msg );\n\t\t\t}\n\t\t}, ARIA_DEBOUNCE_MS );\n\n\t\treturn () => {\n\t\t\tclearTimeout( timerRef.current );\n\t\t};\n\t}, [\n\t\tstate.zoom,\n\t\tstate.rotation,\n\t\tstate.cropRect.width,\n\t\tstate.cropRect.height,\n\t\tstate.flip.horizontal,\n\t\tstate.flip.vertical,\n\t] );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;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AAe,uBAA+B,IAAK;AACzD,QAAM,qBAAiB,uBAAQ,KAAM;AACrC,sCAAiB,MAAM;AACtB,mBAAe,UAAU;AAAA,EAC1B,GAAG,CAAE,KAAM,CAAE;AAEb,gCAAW,MAAM;AAChB,iBAAc,SAAS,OAAQ;AAC/B,aAAS,UAAU,WAAY,MAAM;AACpC,YAAM,UAAU,eAAe;AAC/B,YAAM,MAAM,kBAAmB,SAAS,aAAa,OAAQ;AAC7D,mBAAa,UAAU;AACvB,UAAK,QAAQ,eAAe,SAAU;AACrC,uBAAe,UAAU;AACzB,+BAAO,GAAI;AAAA,MACZ;AAAA,IACD,GAAG,gBAAiB;AAEpB,WAAO,MAAM;AACZ,mBAAc,SAAS,OAAQ;AAAA,IAChC;AAAA,EACD,GAAG;AAAA,IACF,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM,SAAS;AAAA,IACf,MAAM,SAAS;AAAA,IACf,MAAM,KAAK;AAAA,IACX,MAAM,KAAK;AAAA,EACZ,CAAE;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-cropper-reducer.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import {\n\tuseReducer,\n\tuseCallback,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport type {\n\tCropperState,\n\tCropperAction,\n\tNormalizedRect,\n\tSize,\n} from '../../core/types';\nimport { DEFAULT_STATE } from '../../core/constants';\nimport { exportCroppedImage } from '../../core/export/canvas-renderer';\nimport {\n\tcropperReducer,\n\tenforceContainment,\n\tisStateDirty,\n} from '../../core/state';\nimport {\n\tbuildCropperSetters,\n\ttype CropperSetters,\n} from './build-cropper-setters';\n\n/**\n * The cropper controller surface — the contract the Cropper component\n * and its interaction hooks consume.\n *\n * History (undo / redo / commitHistory) is intentionally NOT part of\n * this interface. The cropper is a pure state machine; history is a\n * higher-layer concern owned by a composite store\n * (see media-editor/src/state).\n */\nexport interface CropperController extends CropperSetters {\n\t/** The current cropper state (read-only). */\n\tstate: CropperState;\n\t/** Set the loaded image (natural size and src). */\n\tsetImage: ( image: CropperState[ 'image' ] ) => void;\n\t/** Reset the state. Optionally merge partial state overrides. */\n\treset: ( resetState?: Partial< CropperState > ) => void;\n\t/** Whether the current state differs from the initial state. */\n\tisDirty: boolean;\n\t/**\n\t * Export the cropped image as a Blob. Throws on failure — see\n\t * `exportCroppedImage` for error semantics.\n\t */\n\tgetCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;\n\t/**\n\t * Report the current rendered image size to the controller. The\n\t * Cropper component calls this on visualSize changes; composite\n\t * controllers use it to compute aspect-ratio reshapes. The pure\n\t * cropper hook ignores it (no-op).\n\t */\n\tsetVisualSize: ( size: Size ) => void;\n\t/**\n\t * Adjust the cropRect in response to a viewport change (window\n\t * resize, canvas resize). Behaves like `setCropRect` but, in\n\t * composite controllers, does NOT record an undo entry — viewport\n\t * reshapes aren't editor actions. The pure cropper hook aliases\n\t * this to `setCropRect` (history is a composite concern).\n\t */\n\tadjustCropRectForViewport: ( rect: NormalizedRect ) => void;\n}\n\nfunction areCropperImagesEqual(\n\ta: CropperState[ 'image' ],\n\tb: CropperState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * Pure reducer hook for the image cropper.\n *\n * Wraps the framework-agnostic `cropperReducer` and exposes named\n * setters (built from the shared `buildCropperSetters` factory).\n * Does NOT manage undo/redo history — that responsibility belongs to\n * the surrounding application (see `useMediaEditorState` for the\n * composite store used by the media editor).\n *\n * @param initialState Optional partial state to merge with DEFAULT_STATE.\n * @return The cropper controller — state, setters, and helpers.\n */\nexport function useCropperReducer(\n\tinitialState?: Partial< CropperState >\n): CropperController {\n\tconst [ state, dispatch ] = useReducer(\n\t\tcropperReducer,\n\t\tinitialState,\n\t\t( init ) => enforceContainment( { ...DEFAULT_STATE, ...init } )\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. Stored in state (not a ref) so the comparison reads\n\t// a value, not a ref's `current`. `setImage` and `reset` refresh\n\t// this when the consumer establishes a new baseline.\n\tconst [ initialBaseline, setInitialBaseline ] = useState< CropperState >(\n\t\t() => enforceContainment( { ...DEFAULT_STATE, ...initialState } )\n\t);\n\t// Latest-state ref used by setters that need to read fresh state\n\t// (focal-point zoom, toggleFlip, reset, setImage). Updated\n\t// synchronously inside `dispatchAndSync` so multiple actions in\n\t// one event see each other's output before React commits.\n\tconst stateRef = useRef( state );\n\n\tconst dispatchAndSync = useCallback( ( action: CropperAction ) => {\n\t\tconst next = cropperReducer( stateRef.current, action );\n\t\tstateRef.current = next;\n\t\tdispatch( action );\n\t\treturn next;\n\t}, [] );\n\n\tconst setImage = useCallback(\n\t\t( image: CropperState[ 'image' ] ) => {\n\t\t\tif ( areCropperImagesEqual( stateRef.current.image, image ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst next = dispatchAndSync( {\n\t\t\t\ttype: 'SET_IMAGE',\n\t\t\t\tpayload: image,\n\t\t\t} );\n\t\t\t// Refresh the \"clean\" snapshot to match the post-load state\n\t\t\t// produced by the reducer. Otherwise containment can nudge\n\t\t\t// pan/zoom by tiny amounts on load and `isDirty` would\n\t\t\t// report true from the start.\n\t\t\tsetInitialBaseline( next );\n\t\t},\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tconst nextInitialState = dispatchAndSync( {\n\t\t\t\ttype: 'RESET',\n\t\t\t\tpayload: resetState,\n\t\t\t} );\n\t\t\t// Mirror the reducer's RESET exactly so isDirty stays in\n\t\t\t// sync. The containment step can tweak pan/zoom/cropRect by\n\t\t\t// float ulp; fold those into the \"initial\" snapshot or\n\t\t\t// isDirty would report true after a reset.\n\t\t\tsetInitialBaseline( nextInitialState );\n\t\t},\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst setters = useMemo(\n\t\t() => buildCropperSetters( dispatchAndSync, () => stateRef.current ),\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst isDirty = isStateDirty( state, initialBaseline );\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded — call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.image.src,\n\t\t\t\tstate,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state ]\n\t);\n\n\t// No-op for the pure hook — visualSize matters only when a\n\t// composite store needs to compute aspect-ratio reshapes\n\t// (see useMediaEditorState). Typed to accept a Size so it\n\t// satisfies the controller surface; the value is intentionally\n\t// ignored.\n\tconst setVisualSize = useCallback( () => {}, [] );\n\n\t// In the pure hook, history isn't a concern — viewport-driven\n\t// reshape is identical to setCropRect.\n\tconst adjustCropRectForViewport = setters.setCropRect;\n\n\tconst controller: CropperController = {\n\t\t...setters,\n\t\tstate,\n\t\tsetImage,\n\t\treset,\n\t\tisDirty,\n\t\tgetCroppedImage,\n\t\tsetVisualSize,\n\t\tadjustCropRectForViewport,\n\t};\n\treturn controller;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAMO;AAOP,uBAA8B;AAC9B,6BAAmC;AACnC,mBAIO;AACP,mCAGO;AA0CP,SAAS,sBACR,GACA,GACU;AACV,SACC,GAAG,QAAQ,GAAG,OACd,GAA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,QAAQ;AAAA,UACd,IAAI,MAAO,wCAAyC;AAAA,QACrD;AAAA,MACD;AACA,iBAAO;AAAA,QACN,MAAM,MAAM;AAAA,QACZ;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,KAAM;AAAA,EACT;AAOA,QAAM,oBAAgB,4BAAa,MAAM;AAAA,EAAC,GAAG,CAAC,CAAE;AAIhD,QAAM,4BAA4B,QAAQ;AAE1C,QAAM,aAAgC;AAAA,IACrC,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-interaction.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler — must be registered with { passive: false }. */\n\tonWheelNative: ( e: WheelEvent ) => void;\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n\t/** Whether the user is currently performing a placement interaction. */\n\tisPlacementActive: boolean;\n}\n\n/**\n * Options for the useInteraction hook.\n */\nexport interface UseInteractionOptions {\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n}\n\n/** How long keyboard placement stays active after the latest handled key. */\nconst KEYBOARD_INTERACTION_IDLE_MS = 300;\n\nfunction isHandledKeyboardPan( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown':\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isHandledKeyboardZoom( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase '+':\n\t\tcase '=':\n\t\tcase '-':\n\t\tcase '_':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Mouse, touch, and keyboard event handling for pan, zoom,\n * and crop manipulation.\n *\n * Returns event handler props to spread on the container element.\n * Uses requestAnimationFrame for drag/pinch updates to avoid\n * layout thrashing.\n *\n * @param state The current cropper state.\n * @param actions Named state updates for cropper interactions.\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param options Optional configuration for zoom and keyboard behavior.\n * @return Event handler props for the container element.\n */\nexport function useInteraction(\n\tstate: CropperState,\n\tactions: CropperInteractionActions,\n\tcontainerSize: Size,\n\timageSize?: Size,\n\toptions?: UseInteractionOptions\n): UseInteractionReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst [ isZooming, setIsZooming ] = useState( false );\n\tconst [ isGestureActive, setIsGestureActive ] = useState( false );\n\tconst [ isKeyboardPanning, setIsKeyboardPanning ] = useState( false );\n\tconst keyboardInteractionTimerRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >();\n\t// Tracks whether a keyboard gesture (pan or zoom) is currently active so\n\t// onGestureStart is only fired once per gesture, not on every key repeat.\n\tconst isKeyboardGestureActiveRef = useRef( false );\n\n\t// Keep mutable refs so the controller always reads fresh values\n\t// without needing to be recreated.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\tconst containerSizeRef = useRef( containerSize );\n\tcontainerSizeRef.current = containerSize;\n\tconst imageSizeRef = useRef( imageSize );\n\timageSizeRef.current = imageSize;\n\tconst optionsRef = useRef( options );\n\toptionsRef.current = options;\n\tconst actionsRef = useRef( actions );\n\tactionsRef.current = actions;\n\n\tconst controllerRef = useRef< InteractionController | null >( null );\n\tconst startPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( true );\n\t}, [] );\n\tconst stopPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( false );\n\t}, [] );\n\t// Shared timer logic for any keyboard gesture (pan or zoom): fires\n\t// onGestureStart once per burst and onGestureEnd after the idle window.\n\tconst signalKeyboardGesture = useCallback( () => {\n\t\tif ( ! isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = true;\n\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\tkeyboardInteractionTimerRef.current = setTimeout( () => {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tsetIsKeyboardPanning( false );\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}, KEYBOARD_INTERACTION_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Create / destroy the controller. The controller reads all volatile\n\t// values through refs, so it can stay mounted across render updates.\n\tuseEffect( () => {\n\t\tconst controller = new InteractionController( {\n\t\t\tgetState: () => stateRef.current,\n\t\t\tactions: {\n\t\t\t\tsetPan: ( pan ) => actionsRef.current.setPan( pan ),\n\t\t\t\tsetZoom: ( zoom ) => actionsRef.current.setZoom( zoom ),\n\t\t\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\t\t\tactionsRef.current.setZoomAtPoint( zoom, pan ),\n\t\t\t\tsnapRotate90: ( direction ) =>\n\t\t\t\t\tactionsRef.current.snapRotate90( direction ),\n\t\t\t\ttoggleFlip: ( direction ) =>\n\t\t\t\t\tactionsRef.current.toggleFlip?.( direction ),\n\t\t\t},\n\t\t\tgetContainerSize: () => containerSizeRef.current,\n\t\t\tgetImageSize: () => imageSizeRef.current,\n\t\t\tget minZoom() {\n\t\t\t\treturn optionsRef.current?.minZoom;\n\t\t\t},\n\t\t\tget maxZoom() {\n\t\t\t\treturn optionsRef.current?.maxZoom;\n\t\t\t},\n\t\t\tget zoomSpeed() {\n\t\t\t\treturn optionsRef.current?.zoomSpeed;\n\t\t\t},\n\t\t\tget keyboardStep() {\n\t\t\t\treturn optionsRef.current?.keyboardStep;\n\t\t\t},\n\t\t\tget doubleTapZoom() {\n\t\t\t\treturn optionsRef.current?.doubleTapZoom;\n\t\t\t},\n\t\t\tonGestureStart: () => {\n\t\t\t\tstartPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t\t},\n\t\t\tonGestureEnd: () => {\n\t\t\t\tstopPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t\t},\n\t\t\tonStatusChange: ( status ) => {\n\t\t\t\tsetIsDragging( status.isDragging );\n\t\t\t\tsetIsZooming( status.isZooming );\n\t\t\t},\n\t\t} );\n\t\tcontrollerRef.current = controller;\n\t\treturn () => {\n\t\t\tcontroller.destroy();\n\t\t\tcontrollerRef.current = null;\n\t\t};\n\t}, [ startPlacementGesture, stopPlacementGesture ] );\n\n\tconst onPointerDown = useCallback( ( e: React.PointerEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tcontrollerRef.current?.handlePointerDown( e.nativeEvent, el );\n\t}, [] );\n\n\tconst onTouchStart = useCallback( ( e: React.TouchEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tconst rect = el.getBoundingClientRect();\n\t\tcontrollerRef.current?.handleTouchStart(\n\t\t\te.nativeEvent,\n\t\t\trect,\n\t\t\tel.ownerDocument\n\t\t);\n\t}, [] );\n\n\tconst onKeyDown = useCallback(\n\t\t( e: React.KeyboardEvent ) => {\n\t\t\tif ( isHandledKeyboardPan( e.nativeEvent ) ) {\n\t\t\t\tsetIsKeyboardPanning( true );\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t} else if ( isHandledKeyboardZoom( e.nativeEvent ) ) {\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t}\n\t\t\tcontrollerRef.current?.handleKeyDown( e.nativeEvent );\n\t\t},\n\t\t[ signalKeyboardGesture ]\n\t);\n\n\tconst onWheelNative = useCallback( ( e: WheelEvent ) => {\n\t\tcontrollerRef.current?.handleWheel( e );\n\t}, [] );\n\n\treturn {\n\t\thandlers: {\n\t\t\tonPointerDown,\n\t\t\tonTouchStart,\n\t\t\tonKeyDown,\n\t\t},\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isGestureActive || isKeyboardPanning || isZooming,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAyD;AAEzD,oCAGO;AA8CP,IAAM,+BAA+B;AAErC,SAAS,qBAAsB,OAAgC;AAC9D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IAC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A,MAChC;AAAA,IACD,CAAE;AACF,kBAAc,UAAU;AACxB,WAAO,MAAM;AACZ,iBAAW,QAAQ;AACnB,oBAAc,UAAU;AAAA,IACzB;AAAA,EACD,GAAG,CAAE,uBAAuB,oBAAqB,CAAE;AAEnD,QAAM,oBAAgB,4BAAa,CAAE,MAA2B;AAC/D,UAAM,KAAK,EAAE;AACb,kBAAc,SAAS,kBAAmB,EAAE,aAAa,EAAG;AAAA,EAC7D,GAAG,CAAC,CAAE;AAEN,QAAM,mBAAe,4BAAa,CAAE,MAAyB;AAC5D,UAAM,KAAK,EAAE;AACb,UAAM,OAAO,GAAG,sBAAsB;AACtC,kBAAc,SAAS;AAAA,MACtB,EAAE;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,gBAAY;AAAA,IACjB,CAAE,MAA4B;AAC7B,UAAK,qBAAsB,EAAE,WAAY,GAAI;AAC5C,6BAAsB,IAAK;AAC3B,8BAAsB;AAAA,MACvB,WAAY,sBAAuB,EAAE,WAAY,GAAI;AACpD,8BAAsB;AAAA,MACvB;AACA,oBAAc,SAAS,cAAe,EAAE,WAAY;AAAA,IACrD;AAAA,IACA,CAAE,qBAAsB;AAAA,EACzB;AAEA,QAAM,oBAAgB,4BAAa,CAAE,MAAmB;AACvD,kBAAc,SAAS,YAAa,CAAE;AAAA,EACvC,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,UAAU;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,mBAAmB,qBAAqB;AAAA,EAC5D;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-transform-style.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { useMemo } from '@wordpress/element';\nimport type { CropperState, Size } from '../../core/types';\nimport { computeTransformStyle } from '../../core/transform-style';\n\n/**\n * React hook that computes a memoized CSS matrix() transform string\n * from the cropper state.\n *\n * Delegates to the pure `computeTransformStyle` function in core.\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 useTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\treturn useMemo(\n\t\t() => computeTransformStyle( state, imageSize ),\n\t\t[ state, imageSize ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,6BAAsC;AAY/B,SAAS,kBACf,OACA,WACS;AACT,aAAO;AAAA,IACN,UAAM,8CAAuB,OAAO,SAAU;AAAA,IAC9C,CAAE,OAAO,SAAU;AAAA,EACpB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-viewport-state.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { useReducer, useCallback, useMemo } from '@wordpress/element';\nimport type { ViewportState } from '../../core/types';\nimport {\n\tviewportReducer,\n\tDEFAULT_VIEWPORT_STATE,\n} from '../../core/viewport-state';\n\nexport interface UseViewportStateReturn {\n\tviewport: ViewportState;\n\t/**\n\t * Unused in the current Cropper implementation — scaffolded for the\n\t * upcoming navigator panel (viewport zoom slider).\n\t */\n\tsetViewportZoom: ( zoom: number ) => void;\n\tsetViewportPan: ( pan: { x: number; y: number } ) => void;\n\tresetViewport: () => void;\n}\n\nexport function useViewportState(): UseViewportStateReturn {\n\tconst [ viewport, dispatch ] = useReducer(\n\t\tviewportReducer,\n\t\tDEFAULT_VIEWPORT_STATE\n\t);\n\n\tconst setViewportZoom = useCallback( ( zoom: number ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_ZOOM', payload: zoom } );\n\t}, [] );\n\n\tconst setViewportPan = useCallback( ( pan: { x: number; y: number } ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_PAN', payload: pan } );\n\t}, [] );\n\n\tconst resetViewport = useCallback( () => {\n\t\tdispatch( { type: 'RESET_VIEWPORT' } );\n\t}, [] );\n\n\treturn useMemo(\n\t\t() => ( { viewport, setViewportZoom, setViewportPan, resetViewport } ),\n\t\t[ viewport, setViewportZoom, setViewportPan, resetViewport ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAiD;AAEjD,4BAGO;AAaA,SAAS,mBAA2C;AAC1D,QAAM,CAAE,UAAU,QAAS,QAAI;AAAA,IAC9B;AAAA,IACA;AAAA,EACD;AAEA,QAAM,sBAAkB,4BAAa,CAAE,SAAkB;AACxD,aAAU,EAAE,MAAM,qBAAqB,SAAS,KAAK,CAAE;AAAA,EACxD,GAAG,CAAC,CAAE;AAEN,QAAM,qBAAiB,4BAAa,CAAE,QAAmC;AACxE,aAAU,EAAE,MAAM,oBAAoB,SAAS,IAAI,CAAE;AAAA,EACtD,GAAG,CAAC,CAAE;AAEN,QAAM,oBAAgB,4BAAa,MAAM;AACxC,aAAU,EAAE,MAAM,iBAAiB,CAAE;AAAA,EACtC,GAAG,CAAC,CAAE;AAEN,aAAO;AAAA,IACN,OAAQ,EAAE,UAAU,iBAAiB,gBAAgB,cAAc;AAAA,IACnE,CAAE,UAAU,iBAAiB,gBAAgB,aAAc;AAAA,EAC5D;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/lock-unlock.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/media-editor'\n\t);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAiE;AAE1D,IAAM,EAAE,MAAM,OAAO,QAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/private-apis.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { lock } from './lock-unlock';\nimport { store } from './store';\nimport { MediaEditorModal } from './components/media-editor-modal';\nimport { MediaEditor } from './components/media-editor';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tstore,\n\tMediaEditor,\n\tMediaEditorModal,\n} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAqB;AACrB,mBAAsB;AACtB,gCAAiC;AACjC,0BAA4B;AAErB,IAAM,cAAc,CAAC;AAAA,IAC5B,yBAAM,aAAa;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/state/composite-reducer.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import {\n\tcropperReducer,\n\tareCropperStatesEqual,\n\tcomputeInscribedRect,\n\ttype CropperState,\n} from '../image-editor';\nimport {\n\tDEFAULT_CROP_OPTIONS,\n\ttype CropOptionsSlice,\n\ttype MediaEditorAction,\n\ttype MediaEditorState,\n} from './types';\n\n/**\n * Pure composite reducer for the media editor.\n *\n * Delegates `CROPPER`-tagged actions to the framework-agnostic\n * `cropperReducer` and owns first-class transitions for the sidebar\n * `cropOptions` slice. `RESTORE_SNAPSHOT` replaces the whole composite\n * in one transaction (used by undo/redo).\n *\n * Note: this reducer carries NO history of its own. Snapshots and\n * stacks live in the `useMediaEditorState` hook that wraps it.\n *\n * @param state Current composite state.\n * @param action Action to apply.\n * @return Next composite state.\n */\nexport function mediaEditorReducer(\n\tstate: MediaEditorState,\n\taction: MediaEditorAction\n): MediaEditorState {\n\tswitch ( action.type ) {\n\t\tcase 'CROPPER': {\n\t\t\tconst nextCropper = cropperReducer( state.cropper, action.action );\n\t\t\tif ( nextCropper === state.cropper ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, cropper: nextCropper };\n\t\t}\n\t\tcase 'SET_ASPECT_RATIO_VALUE': {\n\t\t\tconst { presetKey, resolved, visualSize } = action.payload;\n\t\t\t// Atomically: update the preset key AND reshape the\n\t\t\t// cropRect (when the ratio is non-Free and we have a\n\t\t\t// visualSize). One transaction = one undo entry.\n\t\t\tconst shouldReshape =\n\t\t\t\tresolved !== undefined &&\n\t\t\t\tresolved > 0 &&\n\t\t\t\tvisualSize.width > 0 &&\n\t\t\t\tvisualSize.height > 0;\n\t\t\tconst nextCropOptions: CropOptionsSlice = {\n\t\t\t\t...state.cropOptions,\n\t\t\t\taspectRatioValue: presetKey,\n\t\t\t};\n\t\t\tif ( ! shouldReshape ) {\n\t\t\t\tif ( state.cropOptions.aspectRatioValue === presetKey ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\treturn { ...state, cropOptions: nextCropOptions };\n\t\t\t}\n\t\t\tconst newCropRect = computeInscribedRect( resolved, visualSize );\n\t\t\tconst nextCropper = cropperReducer( state.cropper, {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: newCropRect,\n\t\t\t} );\n\t\t\treturn {\n\t\t\t\tcropper: nextCropper,\n\t\t\t\tcropOptions: nextCropOptions,\n\t\t\t};\n\t\t}\n\t\tcase 'RESET_CROP_OPTIONS': {\n\t\t\tif (\n\t\t\t\tstate.cropOptions.aspectRatioValue ===\n\t\t\t\tDEFAULT_CROP_OPTIONS.aspectRatioValue\n\t\t\t) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS },\n\t\t\t};\n\t\t}\n\t\tcase 'RESTORE_SNAPSHOT':\n\t\t\treturn action.payload;\n\t\tcase 'VIEWPORT_ADJUST_CROP_RECT': {\n\t\t\tconst nextCropper = cropperReducer( state.cropper, {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: action.payload,\n\t\t\t} );\n\t\t\tif ( nextCropper === state.cropper ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, cropper: nextCropper };\n\t\t}\n\t}\n}\n\n/**\n * Value-equality check for two composite states. Used by the history\n * machinery to dedup snapshots when an action turned out to be a no-op.\n *\n * @param a First composite state.\n * @param b Second composite state.\n * @return Whether `a` and `b` are value-equal across all slices.\n */\nexport function areMediaEditorStatesEqual(\n\ta: MediaEditorState,\n\tb: MediaEditorState\n): boolean {\n\tif ( a === b ) {\n\t\treturn true;\n\t}\n\treturn (\n\t\tareCropperStatesEqual( a.cropper, b.cropper ) &&\n\t\ta.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue\n\t);\n}\n\n/**\n * Build the initial composite state from optional partial overrides.\n *\n * @param initialCropper Initial cropper-slice fields to merge.\n * @param initialOptions Initial cropOptions-slice fields to merge.\n * @return Composite initial state.\n */\nexport function buildInitialMediaEditorState(\n\tinitialCropper: CropperState,\n\tinitialOptions?: Partial< CropOptionsSlice >\n): MediaEditorState {\n\treturn {\n\t\tcropper: initialCropper,\n\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS, ...initialOptions },\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAKO;AACP,mBAKO;AAiBA,SAAS,mBACf,OACA,QACmB;AACnB,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,WAAW;AACf,YAAM,kBAAc,oCAAgB,MAAM,SAAS,OAAO,MAAO;AACjE,UAAK,gBAAgB,MAAM,SAAU;AACpC,eAAO;AAAA,MACR;AACA,aAAO,EAAE,GAAG,OAAO,SAAS,YAAY;AAAA,IACzC;AAAA,IACA,KAAK,0BAA0B;AAC9B,YAAM,EAAE,WAAW,UAAU,WAAW,IAAI,OAAO;AAInD,YAAM,gBACL,aAAa,UACb,WAAW,KACX,WAAW,QAAQ,KACnB,WAAW,SAAS;AACrB,YAAM,kBAAoC;AAAA,QACzC,GAAG,MAAM;AAAA,QACT,kBAAkB;AAAA,MACnB;AACA,UAAK,CAAE,eAAgB;AACtB,YAAK,MAAM,YAAY,qBAAqB,WAAY;AACvD,iBAAO;AAAA,QACR;AACA,eAAO,EAAE,GAAG,OAAO,aAAa,gBAAgB;AAAA,MACjD;AACA,YAAM,kBAAc,0CAAsB,UAAU,UAAW;AAC/D,YAAM,kBAAc,oCAAgB,MAAM,SAAS;AAAA,QAClD,MAAM;AAAA,QACN,SAAS;AAAA,MACV,CAAE;AACF,aAAO;AAAA,QACN,SAAS;AAAA,QACT,aAAa;AAAA,MACd;AAAA,IACD;AAAA,IACA,KAAK,sBAAsB;AAC1B,UACC,MAAM,YAAY,qBAClB,kCAAqB,kBACpB;AACD,eAAO;AAAA,MACR;AACA,aAAO;AAAA,QACN,GAAG;AAAA,QACH,aAAa,EAAE,GAAG,kCAAqB;AAAA,MACxC;AAAA,IACD;AAAA,IACA,KAAK;AACJ,aAAO,OAAO;AAAA,IACf,KAAK,6BAA6B;AACjC,YAAM,kBAAc,oCAAgB,MAAM,SAAS;AAAA,QAClD,MAAM;AAAA,QACN,SAAS,OAAO;AAAA,MACjB,CAAE;AACF,UAAK,gBAAgB,MAAM,SAAU;AACpC,eAAO;AAAA,MACR;AACA,aAAO,EAAE,GAAG,OAAO,SAAS,YAAY;AAAA,IACzC;AAAA,EACD;AACD;AAUO,SAAS,0BACf,GACA,GACU;AACV,MAAK,MAAM,GAAI;AACd,WAAO;AAAA,EACR;AACA,aACC,2CAAuB,EAAE,SAAS,EAAE,OAAQ,KAC5C,EAAE,YAAY,qBAAqB,EAAE,YAAY;AAEnD;AASO,SAAS,6BACf,gBACA,gBACmB;AACnB,SAAO;AAAA,IACN,SAAS;AAAA,IACT,aAAa,EAAE,GAAG,mCAAsB,GAAG,eAAe;AAAA,EAC3D;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/state/media-editor-state-provider.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { createContext, useContext } from '@wordpress/element';\nimport type { CropperState } from '../image-editor';\nimport {\n\tuseMediaEditorState,\n\ttype MediaEditorController,\n} from './use-media-editor-state';\nimport type { CropOptionsSlice } from './types';\n\nconst MediaEditorStateContext = createContext< MediaEditorController | null >(\n\tnull\n);\n\ninterface MediaEditorStateProviderProps {\n\t/** Optional cropper-slice initial state. */\n\tinitialCropperState?: Partial< CropperState >;\n\t/** Optional cropOptions-slice initial state. */\n\tinitialCropOptions?: Partial< CropOptionsSlice >;\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Provider that vends the composite media-editor controller via\n * context. Wrap the media editor in this so every consumer\n * (canvas, toolbar, sidebar) reads from the same store.\n *\n * @param props\n * @param props.initialCropperState\n * @param props.initialCropOptions\n * @param props.children\n */\nexport function MediaEditorStateProvider( {\n\tinitialCropperState,\n\tinitialCropOptions,\n\tchildren,\n}: MediaEditorStateProviderProps ) {\n\tconst controller = useMediaEditorState( {\n\t\tcropper: initialCropperState,\n\t\tcropOptions: initialCropOptions,\n\t} );\n\n\treturn (\n\t\t<MediaEditorStateContext.Provider value={ controller }>\n\t\t\t{ children }\n\t\t</MediaEditorStateContext.Provider>\n\t);\n}\n\n/**\n * Consume the composite media-editor controller. Throws if used\n * outside a `<MediaEditorStateProvider>`.\n *\n * @return The composite controller.\n */\nexport function useMediaEditor(): MediaEditorController {\n\tconst context = useContext( MediaEditorStateContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditor must be used within a MediaEditorStateProvider.'\n\t\t);\n\t}\n\treturn context;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0C;AAE1C,oCAGO;AAqCL;AAlCF,IAAM,8BAA0B;AAAA,EAC/B;AACD;AAqBO,SAAS,yBAA0B;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACD,GAAmC;AAClC,QAAM,iBAAa,mDAAqB;AAAA,IACvC,SAAS;AAAA,IACT,aAAa;AAAA,EACd,CAAE;AAEF,SACC,4CAAC,wBAAwB,UAAxB,EAAiC,OAAQ,YACvC,UACH;AAEF;AAQO,SAAS,iBAAwC;AACvD,QAAM,cAAU,2BAAY,uBAAwB;AACpD,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/state/types.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import type {\n\tCropperAction,\n\tCropperState,\n\tNormalizedRect,\n\tSize,\n} from '../image-editor';\n\n/**\n * Sidebar control state for the cropper. Lives in the composite store\n * so it participates in the same undo history as cropper geometry.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * Default values for the crop-options slice. Mirrors the initial state\n * used by the sidebar before the user has touched anything.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * The full composite state for the media editor — cropper geometry\n * plus the sidebar control slice. Future feature slices (text\n * overlays, filters, …) extend this object.\n *\n * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay\n * referentially equal across actions that don't touch them.\n */\nexport interface MediaEditorState {\n\tcropper: CropperState;\n\tcropOptions: CropOptionsSlice;\n}\n\n/**\n * Composite reducer action union.\n *\n * Cropper geometry actions are wrapped in a `CROPPER` envelope and\n * delegated to the pure `cropperReducer`. Sidebar and history\n * concerns are first-class actions on this reducer.\n */\nexport type MediaEditorAction =\n\t/**\n\t * Delegate to the underlying cropper reducer. Used for every\n\t * geometry transition (pan / zoom / rotation / flip / cropRect /\n\t * settle / etc.).\n\t */\n\t| {\n\t\t\ttype: 'CROPPER';\n\t\t\taction: CropperAction;\n\t }\n\t/**\n\t * Set the aspect-ratio preset. Atomically updates the preset key\n\t * and the cropRect (computed from the resolved ratio and the\n\t * current visualSize). One transaction = one undo entry.\n\t */\n\t| {\n\t\t\ttype: 'SET_ASPECT_RATIO_VALUE';\n\t\t\tpayload: {\n\t\t\t\t/** Preset key as it appears in the dropdown. */\n\t\t\t\tpresetKey: string;\n\t\t\t\t/**\n\t\t\t\t * Resolved width/height ratio. `undefined` = Free\n\t\t\t\t * (no lock; cropRect stays where it is).\n\t\t\t\t */\n\t\t\t\tresolved: number | undefined;\n\t\t\t\t/**\n\t\t\t\t * Rendered image size used to compute the inscribed\n\t\t\t\t * rect. Caller supplies it because the reducer is\n\t\t\t\t * framework-agnostic and has no DOM access.\n\t\t\t\t */\n\t\t\t\tvisualSize: Size;\n\t\t\t};\n\t }\n\t/** Reset cropOptions to defaults. */\n\t| { type: 'RESET_CROP_OPTIONS' }\n\t/**\n\t * Replace the entire composite state with `payload`. Used by\n\t * undo/redo to restore a full snapshot atomically.\n\t */\n\t| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState }\n\t/**\n\t * Adjust the cropper's cropRect in response to a viewport change\n\t * (e.g., window resize). Behaviorally identical to a `CROPPER\n\t * SET_CROP_RECT` dispatch, but tagged so the hook layer can skip\n\t * history recording — viewport reshapes aren't editor actions.\n\t */\n\t| {\n\t\t\ttype: 'VIEWPORT_ADJUST_CROP_RECT';\n\t\t\tpayload: NormalizedRect;\n\t };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,IAAM,uBAAyC;AAAA,EACrD,kBAAkB;AACnB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|