@wordpress/media-editor 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/media-editor/index.cjs +185 -42
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs +2 -26
- package/build/components/media-editor/use-crop-options.cjs.map +2 -2
- package/build/components/media-editor-canvas/index.cjs +2 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +24 -21
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-fine-rotation/index.cjs +81 -0
- package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +25 -7
- package/build/components/media-editor-modal/index.cjs.map +2 -2
- package/build/components/media-editor-transform-controls/index.cjs +84 -0
- package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
- package/build/hooks/use-crop-gesture-handlers.cjs +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +1 -1
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +1 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +1 -3
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +1 -1
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/state/composite-reducer.cjs +2 -14
- package/build/state/composite-reducer.cjs.map +2 -2
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +2 -2
- package/build/state/use-media-editor-state.cjs +0 -11
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build/store/actions.cjs +4 -2
- package/build/store/actions.cjs.map +2 -2
- package/build/store/reducer.cjs +5 -3
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +5 -0
- package/build/store/selectors.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +191 -44
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs +3 -27
- package/build-module/components/media-editor/use-crop-options.mjs.map +2 -2
- package/build-module/components/media-editor-canvas/index.mjs +2 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +25 -26
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +26 -8
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
- package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs +1 -1
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +1 -1
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +1 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +1 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +1 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/state/composite-reducer.mjs +2 -14
- package/build-module/state/composite-reducer.mjs.map +2 -2
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +2 -2
- package/build-module/state/use-media-editor-state.mjs +0 -11
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-module/store/actions.mjs +4 -2
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/reducer.mjs +5 -3
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +4 -0
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-style/style-rtl.css +51 -35
- package/build-style/style.css +51 -35
- package/build-types/components/media-editor/index.d.ts +14 -2
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +3 -5
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +3 -10
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts +14 -0
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/types.d.ts +3 -11
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +2 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +3 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +3 -0
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +1 -0
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/components/media-editor/index.tsx +226 -57
- package/src/components/media-editor/style.scss +0 -9
- package/src/components/media-editor/test/use-crop-options.tsx +1 -55
- package/src/components/media-editor/use-crop-options.ts +6 -42
- package/src/components/media-editor-canvas/index.tsx +2 -2
- package/src/components/media-editor-crop-panel/index.tsx +35 -33
- package/src/components/media-editor-crop-panel/test/index.tsx +39 -20
- package/src/components/media-editor-fine-rotation/index.tsx +74 -0
- package/src/components/media-editor-modal/index.tsx +20 -4
- package/src/components/media-editor-modal/style.scss +80 -0
- package/src/components/media-editor-modal/test/index.tsx +3 -0
- package/src/components/media-editor-transform-controls/index.tsx +70 -0
- package/src/components/media-editor-transform-controls/style.scss +8 -0
- package/src/hooks/use-crop-gesture-handlers.ts +1 -3
- package/src/image-editor/docs/recipes.md +2 -2
- package/src/image-editor/react/components/cropper.tsx +1 -3
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +1 -3
- package/src/image-editor/react/hooks/use-aria-announcer.ts +1 -3
- package/src/image-editor/react/hooks/use-interaction.ts +2 -3
- package/src/state/composite-reducer.ts +2 -17
- package/src/state/test/use-media-editor-state.ts +3 -75
- package/src/state/types.ts +3 -9
- package/src/state/use-media-editor-state.ts +3 -19
- package/src/store/actions.ts +3 -0
- package/src/store/reducer.ts +6 -1
- package/src/store/selectors.ts +4 -0
- package/src/store/test/reducer.ts +9 -0
- package/src/style.scss +1 -1
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-toolbar/index.cjs +0 -218
- package/build/components/media-editor-toolbar/index.cjs.map +0 -7
- package/build-module/components/media-editor-toolbar/index.mjs +0 -194
- package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/src/components/media-editor-toolbar/index.tsx +0 -213
- package/src/components/media-editor-toolbar/style.scss +0 -49
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// packages/media-editor/src/components/media-editor-transform-controls/index.tsx
|
|
2
|
+
import { Button } from "@wordpress/components";
|
|
3
|
+
import { __ } from "@wordpress/i18n";
|
|
4
|
+
import {
|
|
5
|
+
rotateLeft,
|
|
6
|
+
rotateRight,
|
|
7
|
+
flipHorizontal,
|
|
8
|
+
flipVertical
|
|
9
|
+
} from "@wordpress/icons";
|
|
10
|
+
import { useMediaEditor } from "../../state/index.mjs";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
function MediaEditorTransformControls() {
|
|
13
|
+
const { state, setFlip, snapRotate90 } = useMediaEditor();
|
|
14
|
+
return /* @__PURE__ */ jsxs("div", { className: "media-editor-transform-controls", children: [
|
|
15
|
+
/* @__PURE__ */ jsx(
|
|
16
|
+
Button,
|
|
17
|
+
{
|
|
18
|
+
size: "compact",
|
|
19
|
+
icon: rotateLeft,
|
|
20
|
+
label: __("Rotate 90\xB0 counter-clockwise"),
|
|
21
|
+
showTooltip: true,
|
|
22
|
+
onClick: () => snapRotate90(-1)
|
|
23
|
+
}
|
|
24
|
+
),
|
|
25
|
+
/* @__PURE__ */ jsx(
|
|
26
|
+
Button,
|
|
27
|
+
{
|
|
28
|
+
size: "compact",
|
|
29
|
+
icon: rotateRight,
|
|
30
|
+
label: __("Rotate 90\xB0 clockwise"),
|
|
31
|
+
showTooltip: true,
|
|
32
|
+
onClick: () => snapRotate90(1)
|
|
33
|
+
}
|
|
34
|
+
),
|
|
35
|
+
/* @__PURE__ */ jsx(
|
|
36
|
+
Button,
|
|
37
|
+
{
|
|
38
|
+
size: "compact",
|
|
39
|
+
icon: flipHorizontal,
|
|
40
|
+
label: __("Flip horizontal"),
|
|
41
|
+
showTooltip: true,
|
|
42
|
+
isPressed: state.flip.horizontal,
|
|
43
|
+
onClick: () => setFlip({
|
|
44
|
+
horizontal: !state.flip.horizontal,
|
|
45
|
+
vertical: state.flip.vertical
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
),
|
|
49
|
+
/* @__PURE__ */ jsx(
|
|
50
|
+
Button,
|
|
51
|
+
{
|
|
52
|
+
size: "compact",
|
|
53
|
+
icon: flipVertical,
|
|
54
|
+
label: __("Flip vertical"),
|
|
55
|
+
showTooltip: true,
|
|
56
|
+
isPressed: state.flip.vertical,
|
|
57
|
+
onClick: () => setFlip({
|
|
58
|
+
horizontal: state.flip.horizontal,
|
|
59
|
+
vertical: !state.flip.vertical
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
] });
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
MediaEditorTransformControls as default
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/media-editor-transform-controls/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../../state';\n\n/**\n * Snap-rotate and flip controls for the media-editor footer. Rotation and\n * reflection are both geometric transforms, hence \"transform controls\".\n * Lives separately from the fine-rotation slider so the footer can place\n * the two halves on different rows at intermediate viewport widths.\n */\nexport default function MediaEditorTransformControls() {\n\tconst { state, setFlip, snapRotate90 } = useMediaEditor();\n\treturn (\n\t\t<div className=\"media-editor-transform-controls\">\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateLeft }\n\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateRight }\n\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipHorizontal }\n\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipVertical }\n\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,cAAc;AACvB,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,SAAS,sBAAsB;AAW7B,SACC,KADD;AAHa,SAAR,+BAAgD;AACtD,QAAM,EAAE,OAAO,SAAS,aAAa,IAAI,eAAe;AACxD,SACC,qBAAC,SAAI,WAAU,mCACd;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,MAAO;AAAA,QACP,OAAQ,GAAI,iCAA+B;AAAA,QAC3C,aAAW;AAAA,QACX,SAAU,MAAM,aAAc,EAAG;AAAA;AAAA,IAClC;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,MAAO;AAAA,QACP,OAAQ,GAAI,yBAAuB;AAAA,QACnC,aAAW;AAAA,QACX,SAAU,MAAM,aAAc,CAAE;AAAA;AAAA,IACjC;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,MAAO;AAAA,QACP,OAAQ,GAAI,iBAAkB;AAAA,QAC9B,aAAW;AAAA,QACX,WAAY,MAAM,KAAK;AAAA,QACvB,SAAU,MACT,QAAS;AAAA,UACR,YAAY,CAAE,MAAM,KAAK;AAAA,UACzB,UAAU,MAAM,KAAK;AAAA,QACtB,CAAE;AAAA;AAAA,IAEJ;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,MAAO;AAAA,QACP,OAAQ,GAAI,eAAgB;AAAA,QAC5B,aAAW;AAAA,QACX,WAAY,MAAM,KAAK;AAAA,QACvB,SAAU,MACT,QAAS;AAAA,UACR,YAAY,MAAM,KAAK;AAAA,UACvB,UAAU,CAAE,MAAM,KAAK;AAAA,QACxB,CAAE;AAAA;AAAA,IAEJ;AAAA,KACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -6,7 +6,7 @@ var KEYBOARD_GESTURE_IDLE_MS = 300;
|
|
|
6
6
|
function useCropGestureHandlers(options = {}) {
|
|
7
7
|
const { commitOnKeyUp = true } = options;
|
|
8
8
|
const { beginGesture, endGesture } = useMediaEditor();
|
|
9
|
-
const keyboardTimerRef = useRef(
|
|
9
|
+
const keyboardTimerRef = useRef();
|
|
10
10
|
const clearKeyboardTimer = useCallback(() => {
|
|
11
11
|
clearTimeout(keyboardTimerRef.current);
|
|
12
12
|
}, []);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/use-crop-gesture-handlers.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../state';\n\n/**\n * Data attribute applied to crop control wrappers. The modal's keyboard\n * shortcut handler uses this to distinguish crop controls (where custom\n * undo/redo should fire) from metadata text fields (where the browser's\n * native undo should be preserved).\n */\nexport const CROP_CONTROL_ATTR = 'data-crop-control';\n\n/** Idle window used to group repeated keyboard input into one gesture. */\nconst KEYBOARD_GESTURE_IDLE_MS = 300;\n\nexport interface UseCropGestureHandlersOptions {\n\t/**\n\t * When `true` (default), key-up closes the gesture so each\n\t * discrete keypress becomes its own undo step. Set to `false` for\n\t * continuous-input controls (e.g. the rotation ruler) where rapid\n\t * keypresses should coalesce into a single history entry across\n\t * the whole gesture.\n\t */\n\tcommitOnKeyUp?: boolean;\n}\n\n/**\n * Event handler props to spread onto a wrapper element around a crop\n * control. Marks the wrapper as a crop control (via `data-crop-control`)\n * so the modal's Cmd+Z handler can identify it, and wires gesture\n * boundaries on the composite store so a slider drag becomes a single\n * undo entry rather than one per tick.\n *\n * Usage:\n * const gestureHandlers = useCropGestureHandlers();\n * <div role=\"presentation\" { ...gestureHandlers }>\n * <RangeControl ... />\n * </div>\n *\n * @param options Optional behavior flags.\n */\nexport function useCropGestureHandlers(\n\toptions: UseCropGestureHandlersOptions = {}\n) {\n\tconst { commitOnKeyUp = true } = options;\n\tconst { beginGesture, endGesture } = useMediaEditor();\n\tconst keyboardTimerRef = useRef
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa,WAAW,cAAc;AAK/C,SAAS,sBAAsB;AAQxB,IAAM,oBAAoB;AAGjC,IAAM,2BAA2B;AA4B1B,SAAS,uBACf,UAAyC,CAAC,GACzC;AACD,QAAM,EAAE,gBAAgB,KAAK,IAAI;AACjC,QAAM,EAAE,cAAc,WAAW,IAAI,eAAe;AACpD,QAAM,mBAAmB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../state';\n\n/**\n * Data attribute applied to crop control wrappers. The modal's keyboard\n * shortcut handler uses this to distinguish crop controls (where custom\n * undo/redo should fire) from metadata text fields (where the browser's\n * native undo should be preserved).\n */\nexport const CROP_CONTROL_ATTR = 'data-crop-control';\n\n/** Idle window used to group repeated keyboard input into one gesture. */\nconst KEYBOARD_GESTURE_IDLE_MS = 300;\n\nexport interface UseCropGestureHandlersOptions {\n\t/**\n\t * When `true` (default), key-up closes the gesture so each\n\t * discrete keypress becomes its own undo step. Set to `false` for\n\t * continuous-input controls (e.g. the rotation ruler) where rapid\n\t * keypresses should coalesce into a single history entry across\n\t * the whole gesture.\n\t */\n\tcommitOnKeyUp?: boolean;\n}\n\n/**\n * Event handler props to spread onto a wrapper element around a crop\n * control. Marks the wrapper as a crop control (via `data-crop-control`)\n * so the modal's Cmd+Z handler can identify it, and wires gesture\n * boundaries on the composite store so a slider drag becomes a single\n * undo entry rather than one per tick.\n *\n * Usage:\n * const gestureHandlers = useCropGestureHandlers();\n * <div role=\"presentation\" { ...gestureHandlers }>\n * <RangeControl ... />\n * </div>\n *\n * @param options Optional behavior flags.\n */\nexport function useCropGestureHandlers(\n\toptions: UseCropGestureHandlersOptions = {}\n) {\n\tconst { commitOnKeyUp = true } = options;\n\tconst { beginGesture, endGesture } = useMediaEditor();\n\tconst keyboardTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\n\tconst clearKeyboardTimer = useCallback( () => {\n\t\tclearTimeout( keyboardTimerRef.current );\n\t}, [] );\n\n\tconst scheduleKeyboardEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tkeyboardTimerRef.current = setTimeout( () => {\n\t\t\tendGesture();\n\t\t}, KEYBOARD_GESTURE_IDLE_MS );\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tuseEffect( () => clearKeyboardTimer, [ clearKeyboardTimer ] );\n\n\tconst handlePointerDownCapture = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tbeginGesture();\n\t}, [ beginGesture, clearKeyboardTimer ] );\n\n\tconst handlePointerEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tendGesture();\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tconst handleKeyDownCapture = useCallback( () => {\n\t\tbeginGesture();\n\t\tif ( ! commitOnKeyUp ) {\n\t\t\tscheduleKeyboardEnd();\n\t\t}\n\t}, [ beginGesture, commitOnKeyUp, scheduleKeyboardEnd ] );\n\n\tconst handleKeyUp = useCallback( () => {\n\t\tif ( commitOnKeyUp ) {\n\t\t\tendGesture();\n\t\t\treturn;\n\t\t}\n\t\tscheduleKeyboardEnd();\n\t}, [ commitOnKeyUp, endGesture, scheduleKeyboardEnd ] );\n\n\treturn {\n\t\t[ CROP_CONTROL_ATTR ]: true,\n\t\tonPointerDownCapture: handlePointerDownCapture,\n\t\tonPointerUp: handlePointerEnd,\n\t\tonPointerCancel: handlePointerEnd,\n\t\tonKeyDownCapture: handleKeyDownCapture,\n\t\tonKeyUp: handleKeyUp,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa,WAAW,cAAc;AAK/C,SAAS,sBAAsB;AAQxB,IAAM,oBAAoB;AAGjC,IAAM,2BAA2B;AA4B1B,SAAS,uBACf,UAAyC,CAAC,GACzC;AACD,QAAM,EAAE,gBAAgB,KAAK,IAAI;AACjC,QAAM,EAAE,cAAc,WAAW,IAAI,eAAe;AACpD,QAAM,mBAAmB,OAA0C;AAEnE,QAAM,qBAAqB,YAAa,MAAM;AAC7C,iBAAc,iBAAiB,OAAQ;AAAA,EACxC,GAAG,CAAC,CAAE;AAEN,QAAM,sBAAsB,YAAa,MAAM;AAC9C,uBAAmB;AACnB,qBAAiB,UAAU,WAAY,MAAM;AAC5C,iBAAW;AAAA,IACZ,GAAG,wBAAyB;AAAA,EAC7B,GAAG,CAAE,oBAAoB,UAAW,CAAE;AAEtC,YAAW,MAAM,oBAAoB,CAAE,kBAAmB,CAAE;AAE5D,QAAM,2BAA2B,YAAa,MAAM;AACnD,uBAAmB;AACnB,iBAAa;AAAA,EACd,GAAG,CAAE,cAAc,kBAAmB,CAAE;AAExC,QAAM,mBAAmB,YAAa,MAAM;AAC3C,uBAAmB;AACnB,eAAW;AAAA,EACZ,GAAG,CAAE,oBAAoB,UAAW,CAAE;AAEtC,QAAM,uBAAuB,YAAa,MAAM;AAC/C,iBAAa;AACb,QAAK,CAAE,eAAgB;AACtB,0BAAoB;AAAA,IACrB;AAAA,EACD,GAAG,CAAE,cAAc,eAAe,mBAAoB,CAAE;AAExD,QAAM,cAAc,YAAa,MAAM;AACtC,QAAK,eAAgB;AACpB,iBAAW;AACX;AAAA,IACD;AACA,wBAAoB;AAAA,EACrB,GAAG,CAAE,eAAe,YAAY,mBAAoB,CAAE;AAEtD,SAAO;AAAA,IACN,CAAE,iBAAkB,GAAG;AAAA,IACvB,sBAAsB;AAAA,IACtB,aAAa;AAAA,IACb,iBAAiB;AAAA,IACjB,kBAAkB;AAAA,IAClB,SAAS;AAAA,EACV;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -299,7 +299,7 @@ function CropperInner({
|
|
|
299
299
|
[setCropRect, setViewportPan, canvasSize, visualSize]
|
|
300
300
|
);
|
|
301
301
|
const [settling, setSettling] = useState(false);
|
|
302
|
-
const settleTimerRef = useRef(
|
|
302
|
+
const settleTimerRef = useRef();
|
|
303
303
|
useEffect(() => {
|
|
304
304
|
return () => {
|
|
305
305
|
clearTimeout(settleTimerRef.current);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/components/cropper.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tuseCallback,\n\tuseMemo,\n\tuseRef,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseId,\n\tforwardRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tHandlePosition,\n\tStencilProps,\n\tSize,\n\tNormalizedRect,\n} from '../../core/types';\nimport type { CropperController } from '../hooks/use-cropper-reducer';\nimport { getImageFit, getRotatedBBox } from '../../core/camera';\nimport { getImageCropBounds, getMinZoom } from '../../core/containment';\nimport { MIN_CROP_PIXELS } from '../../core/constants';\nimport { computeInscribedRect } from '../../core/crop-rect';\nimport { useInteraction } from '../hooks/use-interaction';\nimport { useTransformStyle } from '../hooks/use-transform-style';\nimport { useAriaAnnouncer } from '../hooks/use-aria-announcer';\nimport { RectangleStencil } from './stencils/rectangle-stencil';\nimport { DimmingOverlay } from './overlays/dimming-overlay';\nimport { GridOverlay } from './overlays/grid-overlay';\nimport { DimensionsOverlay } from './overlays/dimensions-overlay';\nimport { getSourceRegion } from '../../core/source-region';\nimport { ViewportProvider, useViewport } from './viewport-provider';\nimport { VISUALLY_HIDDEN_STYLE } from '../visually-hidden-style';\n\n/** Threshold for comparing normalized crop rect values. */\nconst CROP_RECT_EPSILON = 1e-6;\n\n/**\n * Props for the Cropper component.\n */\nexport interface CropperProps {\n\t/** Image source URL. */\n\tsrc: string;\n\t/** The cropper controller from `useCropperReducer` or a composite store. */\n\tcontroller: CropperController;\n\t/** Stencil component for the crop area. Defaults to RectangleStencil. */\n\tstencil?: React.ComponentType< StencilProps >;\n\t/** Show the rule-of-thirds grid overlay, or only during interactions. */\n\tshowGrid?: boolean | 'interactive';\n\t/** Whether external placement activity should keep the grid visible. */\n\tisPlacementActive?: boolean;\n\t/** Show the dimming overlay outside the crop area. */\n\tshowDimming?: boolean;\n\t/** Show the live output dimensions tooltip during a resize. */\n\tshowDimensions?: boolean;\n\t/** Minimum zoom level override. Defaults to the coverage-aware minimum. */\n\tminZoom?: number;\n\t/** Maximum zoom level. */\n\tmaxZoom?: number;\n\t/** Fixed aspect ratio (width / height) in pixel space for the crop area. */\n\taspectRatio?: number;\n\t/**\n\t * Enable freeform crop mode with resizable handles.\n\t * When false (default), the crop area is fixed and centered.\n\t * When true, the crop area has resize handles and can be freely repositioned.\n\t */\n\tfreeformCrop?: boolean;\n\t/** Focus the crop area when the cropper mounts. */\n\tfocusOnMount?: boolean;\n\t/** Callback fired when the image is loaded. */\n\tonImageLoaded?: ( size: Size ) => void;\n\t/**\n\t * Callback fired on every state change. Fires at pointermove rate\n\t * during drags, so keep the handler light \u2014 no heavy work, no\n\t * expensive parent re-renders. For commit-style events (drag end,\n\t * settled crop), use `onGestureEnd` instead.\n\t *\n\t * Useful for lightweight syncing with external tools, analytics,\n\t * or AI agents. Receives the full state so consumers can derive\n\t * whatever they need.\n\t */\n\tonStateChange?: ( state: CropperState ) => void;\n\t/** Fires when a continuous gesture begins (pan drag, handle resize, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointerup, resize settle). */\n\tonGestureEnd?: () => void;\n\t/** Additional className for the container. */\n\tclassName?: string;\n}\n\n/**\n * The main image cropper component.\n *\n * Renders an image within a container with interactive crop overlays.\n * Creates the camera once per render via getImageFit, then passes\n * derived values to stencil, overlays, and interaction hooks.\n *\n * The component fills its parent container (100% width and height).\n * Wrap it in a sized container to control its dimensions.\n *\n * @param root0 Component props implementing CropperProps.\n * @param root0.src Image source URL.\n * @param root0.controller The cropper controller from `useCropperReducer` or a composite store.\n * @param root0.stencil Custom stencil component.\n * @param root0.showGrid Grid overlay mode: false | true | 'interactive'.\n * @param root0.isPlacementActive Keep grid visible during external placement activity.\n * @param root0.showDimming Show dimming overlay outside crop.\n * @param root0.showDimensions Show live dimensions tooltip during resize.\n * @param root0.minZoom Minimum zoom level override.\n * @param root0.maxZoom Maximum zoom level.\n * @param root0.aspectRatio Fixed aspect ratio (width/height).\n * @param root0.freeformCrop Enable resize handles.\n * @param root0.focusOnMount Focus the crop area on mount.\n * @param root0.onImageLoaded Image load callback.\n * @param root0.onStateChange Every-frame state callback.\n * @param root0.onGestureStart Gesture boundary start.\n * @param root0.onGestureEnd Gesture boundary end.\n * @param root0.className Additional CSS class.\n * @param ref Forwarded ref for the container div.\n */\nfunction CropperInner(\n\t{\n\t\tsrc,\n\t\tcontroller,\n\t\tstencil: StencilComponent = RectangleStencil,\n\t\tshowGrid = false,\n\t\tisPlacementActive = false,\n\t\tshowDimming = true,\n\t\tshowDimensions = true,\n\t\tminZoom,\n\t\tmaxZoom,\n\t\taspectRatio,\n\t\tfreeformCrop = false,\n\t\tfocusOnMount = false,\n\t\tonImageLoaded,\n\t\tonStateChange,\n\t\tonGestureStart,\n\t\tonGestureEnd,\n\t\tclassName,\n\t}: CropperProps,\n\tref: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst {\n\t\tstate,\n\t\tsetImage,\n\t\tsetCropRect,\n\t\tsettleCrop,\n\t\tsetVisualSize,\n\t\tadjustCropRectForViewport,\n\t} = controller;\n\tconst {\n\t\tviewport: viewportState,\n\t\tsetViewportPan,\n\t\tresetViewport,\n\t} = useViewport();\n\t// Canvas measurement via ResizeObserver. The canvas is the inner\n\t// positioning context for image/stencil/handles \u2014 inset from the root\n\t// by the handle gutter, so crop math operates on the reduced box.\n\tconst canvasRef = useRef< HTMLDivElement >( null );\n\tconst cropAreaDescriptionId = useId();\n\tconst [ isCropAreaFocused, setIsCropAreaFocused ] =\n\t\tuseState( focusOnMount );\n\tconst [ isFocusVisible, setIsFocusVisible ] = useState( false );\n\tconst [ canvasSize, setCanvasSize ] = useState< Size >( {\n\t\twidth: 0,\n\t\theight: 0,\n\t} );\n\n\tuseLayoutEffect( () => {\n\t\tif ( focusOnMount ) {\n\t\t\tcanvasRef.current?.focus( { preventScroll: true } );\n\t\t}\n\t}, [ focusOnMount ] );\n\n\tconst handleCropAreaFocus = useCallback(\n\t\t( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tif ( target === event.currentTarget ) {\n\t\t\t\tsetIsCropAreaFocused( true );\n\t\t\t}\n\t\t\t// Show the outline only when focus arrived via keyboard\n\t\t\t// navigation. relatedTarget is null for pointer-initiated and\n\t\t\t// cross-window focus, so it reliably excludes those cases\n\t\t\t// without needing a separate ref or flag. Applies to focus\n\t\t\t// arriving on the canvas itself or on a descendant handle.\n\t\t\tif (\n\t\t\t\tevent.relatedTarget !== null &&\n\t\t\t\ttarget.matches( ':focus-visible' )\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( true );\n\t\t\t}\n\t\t},\n\t\t[]\n\t);\n\n\tconst handleCropAreaBlur = useCallback(\n\t\t( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.target === event.currentTarget ) {\n\t\t\t\tsetIsCropAreaFocused( false );\n\t\t\t}\n\t\t\t// Reset keyboard-active styling only when focus leaves the\n\t\t\t// cropper entirely. Moves between the canvas and a handle (or\n\t\t\t// between handles) keep the keyboard-active state intact.\n\t\t\tif (\n\t\t\t\t! event.currentTarget.contains(\n\t\t\t\t\tevent.relatedTarget as Node | null\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( false );\n\t\t\t}\n\t\t},\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\tconst element = canvasRef.current;\n\t\tif ( ! element ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new ResizeObserver( ( entries ) => {\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst { width, height } = entry.contentRect;\n\t\t\t\tsetCanvasSize( ( prev ) => {\n\t\t\t\t\tif ( prev.width === width && prev.height === height ) {\n\t\t\t\t\t\treturn prev;\n\t\t\t\t\t}\n\t\t\t\t\treturn { width, height };\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t\tobserver.observe( element );\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [] );\n\n\t// Notify consumer of state changes.\n\tuseEffect( () => {\n\t\tonStateChange?.( state );\n\t}, [ state, onStateChange ] );\n\n\t// ARIA live region: announce significant state changes for screen readers.\n\tconst ariaMessage = useAriaAnnouncer( state );\n\n\t// Compute fitted image dimensions and visual bounds from camera math.\n\tconst naturalWidth = state.image?.naturalWidth ?? 0;\n\tconst naturalHeight = state.image?.naturalHeight ?? 0;\n\tconst { elementSize, visualSize } = useMemo(\n\t\t() =>\n\t\t\tgetImageFit(\n\t\t\t\tcanvasSize,\n\t\t\t\t{ width: naturalWidth, height: naturalHeight },\n\t\t\t\tstate.rotation\n\t\t\t),\n\t\t[ canvasSize, naturalWidth, naturalHeight, state.rotation ]\n\t);\n\n\t// Per-axis minimum crop size in normalized space, expressing a\n\t// pixel floor on the captured source region. cropRect is normalized\n\t// in the viewport's snap-rotation bbox; the captured source-pixel\n\t// width is `cropRect.width * bbox.width / zoom`, so the normalized\n\t// floor scales with `zoom` to keep the source-pixel floor constant.\n\t// Without this, SETTLE_CROP zooms in proportional to the shrink and\n\t// successive drags can crop arbitrarily small.\n\tconst minCropSize: Size | undefined = useMemo( () => {\n\t\tif ( naturalWidth <= 0 || naturalHeight <= 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\t\tconst bbox = getRotatedBBox(\n\t\t\tnaturalWidth,\n\t\t\tnaturalHeight,\n\t\t\tsnapRotation\n\t\t);\n\t\treturn {\n\t\t\twidth: Math.min( 1, ( MIN_CROP_PIXELS * state.zoom ) / bbox.width ),\n\t\t\theight: Math.min(\n\t\t\t\t1,\n\t\t\t\t( MIN_CROP_PIXELS * state.zoom ) / bbox.height\n\t\t\t),\n\t\t};\n\t}, [ naturalWidth, naturalHeight, state.rotation, state.zoom ] );\n\n\t// Report the rendered image size to the controller. Composite\n\t// controllers need it to compute aspect-ratio reshapes from the\n\t// reducer (the dropdown dispatches without DOM access); pure\n\t// controllers ignore it.\n\tuseEffect( () => {\n\t\tsetVisualSize( visualSize );\n\t}, [ visualSize, setVisualSize ] );\n\n\t// In fixed-crop mode, auto-size the crop rect only when a fixed\n\t// aspect ratio is selected. With \"Free\" selected, turning freeform\n\t// handles off should preserve the user's current unconstrained\n\t// crop. Uses `adjustCropRectForViewport` so window-resize-driven\n\t// reshapes don't create undo entries (composite controller); the\n\t// dedup at lines below avoids redundant dispatches when the\n\t// reducer has already updated the cropRect for an aspect change.\n\tuseEffect( () => {\n\t\tif (\n\t\t\tfreeformCrop ||\n\t\t\tvisualSize.width === 0 ||\n\t\t\tvisualSize.height === 0 ||\n\t\t\t! aspectRatio ||\n\t\t\taspectRatio <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = computeInscribedRect( aspectRatio, visualSize );\n\t\tconst current = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.height - rect.height ) < CROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tadjustCropRectForViewport( rect );\n\t}, [\n\t\tfreeformCrop,\n\t\taspectRatio,\n\t\tvisualSize,\n\t\tadjustCropRectForViewport,\n\t\tstate.cropRect,\n\t] );\n\n\t// In freeform mode, when aspectRatio changes, reshape the crop to\n\t// the largest inscribed rect of the new ratio. Bails out when the\n\t// cropRect already matches the inscribed rect \u2014 composite stores\n\t// reshape atomically inside the reducer, so this effect is a\n\t// no-op there.\n\tconst prevAspectRatioRef = useRef( aspectRatio );\n\tuseEffect( () => {\n\t\tif ( prevAspectRatioRef.current === aspectRatio ) {\n\t\t\treturn;\n\t\t}\n\t\tprevAspectRatioRef.current = aspectRatio;\n\n\t\tif (\n\t\t\t! freeformCrop ||\n\t\t\tvisualSize.width === 0 ||\n\t\t\tvisualSize.height === 0 ||\n\t\t\t! aspectRatio ||\n\t\t\taspectRatio <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = computeInscribedRect( aspectRatio, visualSize );\n\t\tconst current = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.height - rect.height ) < CROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tadjustCropRectForViewport( rect );\n\t}, [\n\t\taspectRatio,\n\t\tfreeformCrop,\n\t\tvisualSize,\n\t\tadjustCropRectForViewport,\n\t\tstate.cropRect,\n\t] );\n\n\t// Compute the crop handle bounds from the actual image footprint.\n\t// Depends on the full state object because getImageCropBounds reads\n\t// crop, zoom, rotation, flip, and image. React Compiler requires\n\t// the complete dependency; the computation is lightweight (a few\n\t// trig ops + 4 corner transforms).\n\tconst cropBounds = useMemo( () => {\n\t\tif ( ! state.image || elementSize.width === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn getImageCropBounds( state, elementSize, visualSize );\n\t}, [ state, elementSize, visualSize ] );\n\tconst effectiveMinZoom =\n\t\tminZoom !== undefined ? minZoom : getMinZoom( state );\n\tconst [ isResizing, setIsResizing ] = useState( false );\n\tconst isResizingRef = useRef( false );\n\tconst isSettlingRef = useRef( false );\n\t// Direction of the handle the user is currently resizing \u2014 pointer or\n\t// keyboard. `null` outside of an active resize. Drives the live\n\t// dimensions tooltip overlay.\n\tconst [ activeHandle, setActiveHandle ] = useState< HandlePosition | null >(\n\t\tnull\n\t);\n\n\t// Use the interaction hook for mouse, touch, and keyboard events.\n\tconst {\n\t\thandlers,\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isInteractionPlacementActive,\n\t} = useInteraction( state, controller, canvasSize, visualSize, {\n\t\tminZoom: effectiveMinZoom,\n\t\tmaxZoom,\n\t\tonGestureStart,\n\t\tonGestureEnd,\n\t} );\n\n\t// Compose focus-visibility tracking into the canvas event handlers.\n\t// Kept as a spread rather than explicit props to avoid triggering\n\t// jsx-a11y/no-noninteractive-element-interactions on role=\"group\".\n\t//\n\t// The pointer/key tracking lives in the capture phase so it runs\n\t// before any child handler \u2014 handles call stopPropagation in their\n\t// own onPointerDown / onKeyDown, which would otherwise prevent the\n\t// keyboard-active state from updating when the user interacts with\n\t// a handle directly.\n\tconst canvasHandlers = {\n\t\t...handlers,\n\t\tonPointerDownCapture: () => {\n\t\t\tsetIsFocusVisible( false );\n\t\t},\n\t\tonKeyDownCapture: ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t\t// Modifier-only keypresses precede another key rather than\n\t\t\t// indicating deliberate keyboard interaction on their own.\n\t\t\tif (\n\t\t\t\t! [ 'Shift', 'Control', 'Alt', 'Meta' ].includes( event.key )\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( true );\n\t\t\t}\n\t\t},\n\t\tonPointerDown: ( event: React.PointerEvent< HTMLDivElement > ) => {\n\t\t\thandlers.onPointerDown?.( event );\n\t\t\t// Re-assert false after handlers run \u2014 el.focus() inside the\n\t\t\t// handler fires onFocus, which may otherwise set it back to true.\n\t\t\tsetIsFocusVisible( false );\n\t\t},\n\t};\n\n\t// Register wheel handler natively with { passive: false } so\n\t// preventDefault works. React's onWheel registers as passive. Bound\n\t// to the canvas (not the root) so pointer geometry inside the handler\n\t// resolves against the canvas box.\n\tuseEffect( () => {\n\t\tconst el = canvasRef.current;\n\t\tif ( ! el ) {\n\t\t\treturn;\n\t\t}\n\t\tconst handleWheel = ( event: WheelEvent ) => {\n\t\t\t// Block wheel zoom while resizing or settling \u2014 the stage CSS\n\t\t\t// transform changes getBoundingClientRect() during this window,\n\t\t\t// so focal-point math would resolve against the wrong center.\n\t\t\tif ( isResizingRef.current || isSettlingRef.current ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tonWheelNative( event );\n\t\t};\n\t\tel.addEventListener( 'wheel', handleWheel, {\n\t\t\tpassive: false,\n\t\t} );\n\t\treturn () => {\n\t\t\tel.removeEventListener( 'wheel', handleWheel );\n\t\t};\n\t}, [ onWheelNative ] );\n\n\t// Use the transform style hook for the image CSS transform.\n\tconst transformString = useTransformStyle( state, visualSize );\n\n\t/**\n\t * Handle the image load event.\n\t */\n\tconst handleImageLoad = useCallback(\n\t\t( event: React.SyntheticEvent< HTMLImageElement > ) => {\n\t\t\tconst img = event.currentTarget;\n\t\t\tconst size: Size = {\n\t\t\t\twidth: img.naturalWidth,\n\t\t\t\theight: img.naturalHeight,\n\t\t\t};\n\n\t\t\tsetImage( {\n\t\t\t\tsrc,\n\t\t\t\tnaturalWidth: size.width,\n\t\t\t\tnaturalHeight: size.height,\n\t\t\t} );\n\n\t\t\tonImageLoaded?.( size );\n\t\t},\n\t\t[ src, setImage, onImageLoaded ]\n\t);\n\n\tconst handleCropChange = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tsetCropRect( rect );\n\t\t\t// During a resize drag, pan the viewport so the handle stays\n\t\t\t// visible even when the crop extends beyond the canvas edge.\n\t\t\tif (\n\t\t\t\tisResizingRef.current &&\n\t\t\t\tvisualSize.width > 0 &&\n\t\t\t\tvisualSize.height > 0\n\t\t\t) {\n\t\t\t\tconst offsetX = ( canvasSize.width - visualSize.width ) / 2;\n\t\t\t\tconst offsetY = ( canvasSize.height - visualSize.height ) / 2;\n\t\t\t\tconst rightOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\toffsetX +\n\t\t\t\t\t\t( rect.x + rect.width ) * visualSize.width -\n\t\t\t\t\t\tcanvasSize.width\n\t\t\t\t);\n\t\t\t\tconst leftOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\t-( offsetX + rect.x * visualSize.width )\n\t\t\t\t);\n\t\t\t\tconst bottomOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\toffsetY +\n\t\t\t\t\t\t( rect.y + rect.height ) * visualSize.height -\n\t\t\t\t\t\tcanvasSize.height\n\t\t\t\t);\n\t\t\t\tconst topOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\t-( offsetY + rect.y * visualSize.height )\n\t\t\t\t);\n\t\t\t\tsetViewportPan( {\n\t\t\t\t\tx: -rightOverflow + leftOverflow,\n\t\t\t\t\ty: -bottomOverflow + topOverflow,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ setCropRect, setViewportPan, canvasSize, visualSize ]\n\t);\n\n\t// Settling animation: brief linear transition after resize end.\n\tconst [ settling, setSettling ] = useState( false );\n\tconst settleTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\t// Clear the pending settle timer on unmount so it can't fire a\n\t// state update on an unmounted component.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( settleTimerRef.current );\n\t\t};\n\t}, [] );\n\n\tconst isInteractiveGrid = showGrid === 'interactive';\n\tconst showInteractiveGrid =\n\t\tisInteractiveGrid &&\n\t\t( isInteractionPlacementActive || isResizing || isPlacementActive );\n\n\t// Output crop size in source pixels \u2014 drives the live tooltip\n\t// overlay. Only computed during pointer drags, so the per-frame\n\t// state churn during pan/zoom doesn't pay for it.\n\tconst outputSize = useMemo( () => {\n\t\tif ( ! showDimensions || ! activeHandle || ! state.image ) {\n\t\t\treturn null;\n\t\t}\n\t\tconst region = getSourceRegion( state, {\n\t\t\twidth: state.image.naturalWidth,\n\t\t\theight: state.image.naturalHeight,\n\t\t} );\n\t\treturn { width: region.width, height: region.height };\n\t}, [ showDimensions, activeHandle, state ] );\n\n\t/**\n\t * Handle Escape on a resize handle \u2014 return focus to the canvas so\n\t * arrow keys pan the image rather than resize.\n\t */\n\tconst handleEscape = useCallback( () => {\n\t\t// Escape is always a keyboard action, so show the outline immediately\n\t\t// rather than relying on the focus handler's :focus-visible check.\n\t\tsetIsFocusVisible( true );\n\t\tcanvasRef.current?.focus( { preventScroll: true } );\n\t}, [] );\n\n\tconst handleResizeStart = useCallback(\n\t\t( handle?: HandlePosition ) => {\n\t\t\tisResizingRef.current = true;\n\t\t\tsetIsResizing( true );\n\t\t\tsetActiveHandle( handle ?? null );\n\t\t\t// Clear any in-flight settle so transitions don't apply during the\n\t\t\t// new drag (rapid successive resizes would otherwise inherit the\n\t\t\t// previous settle animation).\n\t\t\tclearTimeout( settleTimerRef.current );\n\t\t\tisSettlingRef.current = false;\n\t\t\tsetSettling( false );\n\t\t\tresetViewport();\n\t\t\tonGestureStart?.();\n\t\t},\n\t\t[ onGestureStart, resetViewport ]\n\t);\n\n\t/**\n\t * Handle resize end \u2014 settle the crop rect (re-center, fill height)\n\t * and reset the viewport pan back to neutral.\n\t */\n\tconst handleResizeEnd = useCallback( () => {\n\t\tisResizingRef.current = false;\n\t\tsetIsResizing( false );\n\t\tsetActiveHandle( null );\n\t\tisSettlingRef.current = true;\n\t\tsetSettling( true );\n\t\t// Reset viewport pan first so it transitions back to zero in sync\n\t\t// with the settle animation on the image.\n\t\tresetViewport();\n\t\tsettleCrop();\n\t\tonGestureEnd?.();\n\t\tclearTimeout( settleTimerRef.current );\n\t\tsettleTimerRef.current = setTimeout( () => {\n\t\t\tisSettlingRef.current = false;\n\t\t\tsetSettling( false );\n\t\t}, 200 );\n\t}, [ settleCrop, onGestureEnd, resetViewport ] );\n\n\tlet imageTransition: string | undefined;\n\tif ( settling ) {\n\t\timageTransition = 'transform 200ms ease-out';\n\t} else if ( isZooming ) {\n\t\timageTransition = 'transform 150ms linear';\n\t}\n\tconst settleStencilTransition = settling\n\t\t? 'left 200ms ease-out, top 200ms ease-out, width 200ms ease-out, height 200ms ease-out'\n\t\t: undefined;\n\n\t// Compute the image's CSS style.\n\tconst imageStyle = useMemo( (): React.CSSProperties => {\n\t\tif ( elementSize.width === 0 || elementSize.height === 0 ) {\n\t\t\treturn {};\n\t\t}\n\t\tconst centerX = ( canvasSize.width - elementSize.width ) / 2;\n\t\tconst centerY = ( canvasSize.height - elementSize.height ) / 2;\n\t\treturn {\n\t\t\twidth: elementSize.width,\n\t\t\theight: elementSize.height,\n\t\t\tmaxWidth: elementSize.width,\n\t\t\tmaxHeight: elementSize.height,\n\t\t\tleft: centerX,\n\t\t\ttop: centerY,\n\t\t\ttransform: transformString,\n\t\t\ttransition: imageTransition,\n\t\t};\n\t}, [ canvasSize, elementSize, transformString, imageTransition ] );\n\n\t// Viewport pan CSS transform for the stage div. Applied during resize\n\t// drags to keep handles visible when the crop extends past the canvas edge.\n\t// Transitions back to zero during the settle animation.\n\t// will-change promotes the stage to its own compositor layer while the\n\t// transform is active, keeping per-frame pan updates off the main thread.\n\tconst settleTransition = settling ? 'transform 200ms ease-out' : undefined;\n\tconst willChange = isResizing || settling ? 'transform' : undefined;\n\tlet stageStyle: React.CSSProperties | undefined;\n\tif ( viewportState.pan.x !== 0 || viewportState.pan.y !== 0 ) {\n\t\tstageStyle = {\n\t\t\ttransform: `translate(${ viewportState.pan.x }px, ${ viewportState.pan.y }px)`,\n\t\t\ttransition: settleTransition,\n\t\t\twillChange,\n\t\t};\n\t} else if ( settling ) {\n\t\tstageStyle = { transition: settleTransition, willChange };\n\t}\n\n\t// Forward the root element to the consumer's ref.\n\tconst setContainerRef = useCallback(\n\t\t( element: HTMLDivElement | null ) => {\n\t\t\tif ( typeof ref === 'function' ) {\n\t\t\t\tref( element );\n\t\t\t} else if ( ref ) {\n\t\t\t\t(\n\t\t\t\t\tref as React.MutableRefObject< HTMLDivElement | null >\n\t\t\t\t ).current = element;\n\t\t\t}\n\t\t},\n\t\t[ ref ]\n\t);\n\n\treturn (\n\t\t<div\n\t\t\tref={ setContainerRef }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wp-media-editor-image-editor',\n\t\t\t\tisDragging && 'wp-media-editor-image-editor--dragging',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t>\n\t\t\t{ /*\n\t\t\t * The canvas is the interactive, inset surface. Handles and\n\t\t\t * the ARIA role/tabIndex live here so pointer geometry\n\t\t\t * (getBoundingClientRect on e.currentTarget) resolves against\n\t\t\t * the same box that crop math uses. The root stays as the\n\t\t\t * clipping shell for the dimming overlay's box-shadow.\n\t\t\t *\n\t\t\t * Not role=\"application\" \u2014 that disables the screen reader's\n\t\t\t * normal keyboard interception, too heavy-handed for a single\n\t\t\t * widget. Screen reader users get the ARIA live region below\n\t\t\t * as the announcement channel.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tref={ canvasRef }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wp-media-editor-image-editor__canvas',\n\t\t\t\t\tisInteractiveGrid &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--grid-interactive',\n\t\t\t\t\tshowInteractiveGrid &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--show-grid',\n\t\t\t\t\tsettling &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--settling',\n\t\t\t\t\t// Marks the cropper as in keyboard-interaction mode.\n\t\t\t\t\t// CSS uses :focus on the canvas to show the stencil\n\t\t\t\t\t// outline and :focus on a handle to show its ring,\n\t\t\t\t\t// so the class applies whenever any cropper element\n\t\t\t\t\t// has keyboard focus.\n\t\t\t\t\tisFocusVisible &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--focus-visible'\n\t\t\t\t) }\n\t\t\t\ttabIndex={ 0 }\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={ __( 'Crop area' ) }\n\t\t\t\taria-describedby={\n\t\t\t\t\tisCropAreaFocused ? cropAreaDescriptionId : undefined\n\t\t\t\t}\n\t\t\t\tonFocus={ handleCropAreaFocus }\n\t\t\t\tonBlur={ handleCropAreaBlur }\n\t\t\t\t{ ...canvasHandlers }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tid={ cropAreaDescriptionId }\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ /*\n\t\t\t\t * The stage is an inner full-size div that receives the\n\t\t\t\t * viewport pan CSS transform. Keeping the transform here\n\t\t\t\t * (rather than on the canvas) means the canvas always stays\n\t\t\t\t * at its natural position, so the root div's background is\n\t\t\t\t * never exposed when the stage is panned during a resize drag.\n\t\t\t\t */ }\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"wp-media-editor-image-editor__stage\"\n\t\t\t\t\tdata-testid=\"cropper-stage\"\n\t\t\t\t\tstyle={ stageStyle }\n\t\t\t\t>\n\t\t\t\t\t{ /* The image layer */ }\n\t\t\t\t\t<img\n\t\t\t\t\t\tclassName=\"wp-media-editor-image-editor__image\"\n\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tonLoad={ handleImageLoad }\n\t\t\t\t\t\tstyle={ imageStyle }\n\t\t\t\t\t\tdraggable={ false }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ /* Dimming overlay outside the crop area */ }\n\t\t\t\t\t{ showDimming && (\n\t\t\t\t\t\t<DimmingOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ visualSize }\n\t\t\t\t\t\t\ttransition={ settleStencilTransition }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ /* The stencil (crop area with handles) */ }\n\t\t\t\t\t<StencilComponent\n\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\timageSize={ visualSize }\n\t\t\t\t\t\tonCropChange={ handleCropChange }\n\t\t\t\t\t\tonResizeStart={ handleResizeStart }\n\t\t\t\t\t\tonResizeEnd={ handleResizeEnd }\n\t\t\t\t\t\tonEscape={ handleEscape }\n\t\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\t\tfreeformCrop={ freeformCrop }\n\t\t\t\t\t\tstencilTransition={ settleStencilTransition }\n\t\t\t\t\t\tcropBounds={ cropBounds }\n\t\t\t\t\t\tminCropSize={ minCropSize }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ /* Rule-of-thirds grid */ }\n\t\t\t\t\t{ ( showGrid === true || isInteractiveGrid ) && (\n\t\t\t\t\t\t<GridOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ visualSize }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ /* Live dimensions tooltip pinned to the dragged handle. */ }\n\t\t\t\t\t{ activeHandle && outputSize && (\n\t\t\t\t\t\t<DimensionsOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ visualSize }\n\t\t\t\t\t\t\tactiveHandle={ activeHandle }\n\t\t\t\t\t\t\toutputWidth={ outputSize.width }\n\t\t\t\t\t\t\toutputHeight={ outputSize.height }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\n\t\t\t\t{ /* ARIA live region for screen reader announcements */ }\n\t\t\t\t<div\n\t\t\t\t\taria-live=\"polite\"\n\t\t\t\t\taria-atomic=\"true\"\n\t\t\t\t\tclassName=\"wp-media-editor-image-editor__aria-live\"\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ ariaMessage }\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nconst CropperInnerWithRef = forwardRef< HTMLDivElement, CropperProps >(\n\tCropperInner\n);\n\nexport const Cropper = forwardRef< HTMLDivElement, CropperProps >(\n\t( props, ref ) => (\n\t\t<ViewportProvider>\n\t\t\t<CropperInnerWithRef { ...props } ref={ ref } />\n\t\t</ViewportProvider>\n\t)\n);\n"],
|
|
5
|
-
"mappings": ";AAIA,OAAO,UAAU;AAKjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AAanB,SAAS,aAAa,sBAAsB;AAC5C,SAAS,oBAAoB,kBAAkB;AAC/C,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB,mBAAmB;AAC9C,SAAS,6BAA6B;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tuseCallback,\n\tuseMemo,\n\tuseRef,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseId,\n\tforwardRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tHandlePosition,\n\tStencilProps,\n\tSize,\n\tNormalizedRect,\n} from '../../core/types';\nimport type { CropperController } from '../hooks/use-cropper-reducer';\nimport { getImageFit, getRotatedBBox } from '../../core/camera';\nimport { getImageCropBounds, getMinZoom } from '../../core/containment';\nimport { MIN_CROP_PIXELS } from '../../core/constants';\nimport { computeInscribedRect } from '../../core/crop-rect';\nimport { useInteraction } from '../hooks/use-interaction';\nimport { useTransformStyle } from '../hooks/use-transform-style';\nimport { useAriaAnnouncer } from '../hooks/use-aria-announcer';\nimport { RectangleStencil } from './stencils/rectangle-stencil';\nimport { DimmingOverlay } from './overlays/dimming-overlay';\nimport { GridOverlay } from './overlays/grid-overlay';\nimport { DimensionsOverlay } from './overlays/dimensions-overlay';\nimport { getSourceRegion } from '../../core/source-region';\nimport { ViewportProvider, useViewport } from './viewport-provider';\nimport { VISUALLY_HIDDEN_STYLE } from '../visually-hidden-style';\n\n/** Threshold for comparing normalized crop rect values. */\nconst CROP_RECT_EPSILON = 1e-6;\n\n/**\n * Props for the Cropper component.\n */\nexport interface CropperProps {\n\t/** Image source URL. */\n\tsrc: string;\n\t/** The cropper controller from `useCropperReducer` or a composite store. */\n\tcontroller: CropperController;\n\t/** Stencil component for the crop area. Defaults to RectangleStencil. */\n\tstencil?: React.ComponentType< StencilProps >;\n\t/** Show the rule-of-thirds grid overlay, or only during interactions. */\n\tshowGrid?: boolean | 'interactive';\n\t/** Whether external placement activity should keep the grid visible. */\n\tisPlacementActive?: boolean;\n\t/** Show the dimming overlay outside the crop area. */\n\tshowDimming?: boolean;\n\t/** Show the live output dimensions tooltip during a resize. */\n\tshowDimensions?: boolean;\n\t/** Minimum zoom level override. Defaults to the coverage-aware minimum. */\n\tminZoom?: number;\n\t/** Maximum zoom level. */\n\tmaxZoom?: number;\n\t/** Fixed aspect ratio (width / height) in pixel space for the crop area. */\n\taspectRatio?: number;\n\t/**\n\t * Enable freeform crop mode with resizable handles.\n\t * When false (default), the crop area is fixed and centered.\n\t * When true, the crop area has resize handles and can be freely repositioned.\n\t */\n\tfreeformCrop?: boolean;\n\t/** Focus the crop area when the cropper mounts. */\n\tfocusOnMount?: boolean;\n\t/** Callback fired when the image is loaded. */\n\tonImageLoaded?: ( size: Size ) => void;\n\t/**\n\t * Callback fired on every state change. Fires at pointermove rate\n\t * during drags, so keep the handler light \u2014 no heavy work, no\n\t * expensive parent re-renders. For commit-style events (drag end,\n\t * settled crop), use `onGestureEnd` instead.\n\t *\n\t * Useful for lightweight syncing with external tools, analytics,\n\t * or AI agents. Receives the full state so consumers can derive\n\t * whatever they need.\n\t */\n\tonStateChange?: ( state: CropperState ) => void;\n\t/** Fires when a continuous gesture begins (pan drag, handle resize, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointerup, resize settle). */\n\tonGestureEnd?: () => void;\n\t/** Additional className for the container. */\n\tclassName?: string;\n}\n\n/**\n * The main image cropper component.\n *\n * Renders an image within a container with interactive crop overlays.\n * Creates the camera once per render via getImageFit, then passes\n * derived values to stencil, overlays, and interaction hooks.\n *\n * The component fills its parent container (100% width and height).\n * Wrap it in a sized container to control its dimensions.\n *\n * @param root0 Component props implementing CropperProps.\n * @param root0.src Image source URL.\n * @param root0.controller The cropper controller from `useCropperReducer` or a composite store.\n * @param root0.stencil Custom stencil component.\n * @param root0.showGrid Grid overlay mode: false | true | 'interactive'.\n * @param root0.isPlacementActive Keep grid visible during external placement activity.\n * @param root0.showDimming Show dimming overlay outside crop.\n * @param root0.showDimensions Show live dimensions tooltip during resize.\n * @param root0.minZoom Minimum zoom level override.\n * @param root0.maxZoom Maximum zoom level.\n * @param root0.aspectRatio Fixed aspect ratio (width/height).\n * @param root0.freeformCrop Enable resize handles.\n * @param root0.focusOnMount Focus the crop area on mount.\n * @param root0.onImageLoaded Image load callback.\n * @param root0.onStateChange Every-frame state callback.\n * @param root0.onGestureStart Gesture boundary start.\n * @param root0.onGestureEnd Gesture boundary end.\n * @param root0.className Additional CSS class.\n * @param ref Forwarded ref for the container div.\n */\nfunction CropperInner(\n\t{\n\t\tsrc,\n\t\tcontroller,\n\t\tstencil: StencilComponent = RectangleStencil,\n\t\tshowGrid = false,\n\t\tisPlacementActive = false,\n\t\tshowDimming = true,\n\t\tshowDimensions = true,\n\t\tminZoom,\n\t\tmaxZoom,\n\t\taspectRatio,\n\t\tfreeformCrop = false,\n\t\tfocusOnMount = false,\n\t\tonImageLoaded,\n\t\tonStateChange,\n\t\tonGestureStart,\n\t\tonGestureEnd,\n\t\tclassName,\n\t}: CropperProps,\n\tref: React.ForwardedRef< HTMLDivElement >\n) {\n\tconst {\n\t\tstate,\n\t\tsetImage,\n\t\tsetCropRect,\n\t\tsettleCrop,\n\t\tsetVisualSize,\n\t\tadjustCropRectForViewport,\n\t} = controller;\n\tconst {\n\t\tviewport: viewportState,\n\t\tsetViewportPan,\n\t\tresetViewport,\n\t} = useViewport();\n\t// Canvas measurement via ResizeObserver. The canvas is the inner\n\t// positioning context for image/stencil/handles \u2014 inset from the root\n\t// by the handle gutter, so crop math operates on the reduced box.\n\tconst canvasRef = useRef< HTMLDivElement >( null );\n\tconst cropAreaDescriptionId = useId();\n\tconst [ isCropAreaFocused, setIsCropAreaFocused ] =\n\t\tuseState( focusOnMount );\n\tconst [ isFocusVisible, setIsFocusVisible ] = useState( false );\n\tconst [ canvasSize, setCanvasSize ] = useState< Size >( {\n\t\twidth: 0,\n\t\theight: 0,\n\t} );\n\n\tuseLayoutEffect( () => {\n\t\tif ( focusOnMount ) {\n\t\t\tcanvasRef.current?.focus( { preventScroll: true } );\n\t\t}\n\t}, [ focusOnMount ] );\n\n\tconst handleCropAreaFocus = useCallback(\n\t\t( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t\tconst target = event.target as HTMLElement;\n\t\t\tif ( target === event.currentTarget ) {\n\t\t\t\tsetIsCropAreaFocused( true );\n\t\t\t}\n\t\t\t// Show the outline only when focus arrived via keyboard\n\t\t\t// navigation. relatedTarget is null for pointer-initiated and\n\t\t\t// cross-window focus, so it reliably excludes those cases\n\t\t\t// without needing a separate ref or flag. Applies to focus\n\t\t\t// arriving on the canvas itself or on a descendant handle.\n\t\t\tif (\n\t\t\t\tevent.relatedTarget !== null &&\n\t\t\t\ttarget.matches( ':focus-visible' )\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( true );\n\t\t\t}\n\t\t},\n\t\t[]\n\t);\n\n\tconst handleCropAreaBlur = useCallback(\n\t\t( event: React.FocusEvent< HTMLDivElement > ) => {\n\t\t\tif ( event.target === event.currentTarget ) {\n\t\t\t\tsetIsCropAreaFocused( false );\n\t\t\t}\n\t\t\t// Reset keyboard-active styling only when focus leaves the\n\t\t\t// cropper entirely. Moves between the canvas and a handle (or\n\t\t\t// between handles) keep the keyboard-active state intact.\n\t\t\tif (\n\t\t\t\t! event.currentTarget.contains(\n\t\t\t\t\tevent.relatedTarget as Node | null\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( false );\n\t\t\t}\n\t\t},\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\tconst element = canvasRef.current;\n\t\tif ( ! element ) {\n\t\t\treturn;\n\t\t}\n\t\tconst observer = new ResizeObserver( ( entries ) => {\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst { width, height } = entry.contentRect;\n\t\t\t\tsetCanvasSize( ( prev ) => {\n\t\t\t\t\tif ( prev.width === width && prev.height === height ) {\n\t\t\t\t\t\treturn prev;\n\t\t\t\t\t}\n\t\t\t\t\treturn { width, height };\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t\tobserver.observe( element );\n\t\treturn () => {\n\t\t\tobserver.disconnect();\n\t\t};\n\t}, [] );\n\n\t// Notify consumer of state changes.\n\tuseEffect( () => {\n\t\tonStateChange?.( state );\n\t}, [ state, onStateChange ] );\n\n\t// ARIA live region: announce significant state changes for screen readers.\n\tconst ariaMessage = useAriaAnnouncer( state );\n\n\t// Compute fitted image dimensions and visual bounds from camera math.\n\tconst naturalWidth = state.image?.naturalWidth ?? 0;\n\tconst naturalHeight = state.image?.naturalHeight ?? 0;\n\tconst { elementSize, visualSize } = useMemo(\n\t\t() =>\n\t\t\tgetImageFit(\n\t\t\t\tcanvasSize,\n\t\t\t\t{ width: naturalWidth, height: naturalHeight },\n\t\t\t\tstate.rotation\n\t\t\t),\n\t\t[ canvasSize, naturalWidth, naturalHeight, state.rotation ]\n\t);\n\n\t// Per-axis minimum crop size in normalized space, expressing a\n\t// pixel floor on the captured source region. cropRect is normalized\n\t// in the viewport's snap-rotation bbox; the captured source-pixel\n\t// width is `cropRect.width * bbox.width / zoom`, so the normalized\n\t// floor scales with `zoom` to keep the source-pixel floor constant.\n\t// Without this, SETTLE_CROP zooms in proportional to the shrink and\n\t// successive drags can crop arbitrarily small.\n\tconst minCropSize: Size | undefined = useMemo( () => {\n\t\tif ( naturalWidth <= 0 || naturalHeight <= 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\t\tconst bbox = getRotatedBBox(\n\t\t\tnaturalWidth,\n\t\t\tnaturalHeight,\n\t\t\tsnapRotation\n\t\t);\n\t\treturn {\n\t\t\twidth: Math.min( 1, ( MIN_CROP_PIXELS * state.zoom ) / bbox.width ),\n\t\t\theight: Math.min(\n\t\t\t\t1,\n\t\t\t\t( MIN_CROP_PIXELS * state.zoom ) / bbox.height\n\t\t\t),\n\t\t};\n\t}, [ naturalWidth, naturalHeight, state.rotation, state.zoom ] );\n\n\t// Report the rendered image size to the controller. Composite\n\t// controllers need it to compute aspect-ratio reshapes from the\n\t// reducer (the dropdown dispatches without DOM access); pure\n\t// controllers ignore it.\n\tuseEffect( () => {\n\t\tsetVisualSize( visualSize );\n\t}, [ visualSize, setVisualSize ] );\n\n\t// In fixed-crop mode, auto-size the crop rect only when a fixed\n\t// aspect ratio is selected. With \"Free\" selected, turning freeform\n\t// handles off should preserve the user's current unconstrained\n\t// crop. Uses `adjustCropRectForViewport` so window-resize-driven\n\t// reshapes don't create undo entries (composite controller); the\n\t// dedup at lines below avoids redundant dispatches when the\n\t// reducer has already updated the cropRect for an aspect change.\n\tuseEffect( () => {\n\t\tif (\n\t\t\tfreeformCrop ||\n\t\t\tvisualSize.width === 0 ||\n\t\t\tvisualSize.height === 0 ||\n\t\t\t! aspectRatio ||\n\t\t\taspectRatio <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = computeInscribedRect( aspectRatio, visualSize );\n\t\tconst current = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.height - rect.height ) < CROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tadjustCropRectForViewport( rect );\n\t}, [\n\t\tfreeformCrop,\n\t\taspectRatio,\n\t\tvisualSize,\n\t\tadjustCropRectForViewport,\n\t\tstate.cropRect,\n\t] );\n\n\t// In freeform mode, when aspectRatio changes, reshape the crop to\n\t// the largest inscribed rect of the new ratio. Bails out when the\n\t// cropRect already matches the inscribed rect \u2014 composite stores\n\t// reshape atomically inside the reducer, so this effect is a\n\t// no-op there.\n\tconst prevAspectRatioRef = useRef( aspectRatio );\n\tuseEffect( () => {\n\t\tif ( prevAspectRatioRef.current === aspectRatio ) {\n\t\t\treturn;\n\t\t}\n\t\tprevAspectRatioRef.current = aspectRatio;\n\n\t\tif (\n\t\t\t! freeformCrop ||\n\t\t\tvisualSize.width === 0 ||\n\t\t\tvisualSize.height === 0 ||\n\t\t\t! aspectRatio ||\n\t\t\taspectRatio <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = computeInscribedRect( aspectRatio, visualSize );\n\t\tconst current = state.cropRect;\n\t\tif (\n\t\t\tMath.abs( current.x - rect.x ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.y - rect.y ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.width - rect.width ) < CROP_RECT_EPSILON &&\n\t\t\tMath.abs( current.height - rect.height ) < CROP_RECT_EPSILON\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tadjustCropRectForViewport( rect );\n\t}, [\n\t\taspectRatio,\n\t\tfreeformCrop,\n\t\tvisualSize,\n\t\tadjustCropRectForViewport,\n\t\tstate.cropRect,\n\t] );\n\n\t// Compute the crop handle bounds from the actual image footprint.\n\t// Depends on the full state object because getImageCropBounds reads\n\t// crop, zoom, rotation, flip, and image. React Compiler requires\n\t// the complete dependency; the computation is lightweight (a few\n\t// trig ops + 4 corner transforms).\n\tconst cropBounds = useMemo( () => {\n\t\tif ( ! state.image || elementSize.width === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn getImageCropBounds( state, elementSize, visualSize );\n\t}, [ state, elementSize, visualSize ] );\n\tconst effectiveMinZoom =\n\t\tminZoom !== undefined ? minZoom : getMinZoom( state );\n\tconst [ isResizing, setIsResizing ] = useState( false );\n\tconst isResizingRef = useRef( false );\n\tconst isSettlingRef = useRef( false );\n\t// Direction of the handle the user is currently resizing \u2014 pointer or\n\t// keyboard. `null` outside of an active resize. Drives the live\n\t// dimensions tooltip overlay.\n\tconst [ activeHandle, setActiveHandle ] = useState< HandlePosition | null >(\n\t\tnull\n\t);\n\n\t// Use the interaction hook for mouse, touch, and keyboard events.\n\tconst {\n\t\thandlers,\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isInteractionPlacementActive,\n\t} = useInteraction( state, controller, canvasSize, visualSize, {\n\t\tminZoom: effectiveMinZoom,\n\t\tmaxZoom,\n\t\tonGestureStart,\n\t\tonGestureEnd,\n\t} );\n\n\t// Compose focus-visibility tracking into the canvas event handlers.\n\t// Kept as a spread rather than explicit props to avoid triggering\n\t// jsx-a11y/no-noninteractive-element-interactions on role=\"group\".\n\t//\n\t// The pointer/key tracking lives in the capture phase so it runs\n\t// before any child handler \u2014 handles call stopPropagation in their\n\t// own onPointerDown / onKeyDown, which would otherwise prevent the\n\t// keyboard-active state from updating when the user interacts with\n\t// a handle directly.\n\tconst canvasHandlers = {\n\t\t...handlers,\n\t\tonPointerDownCapture: () => {\n\t\t\tsetIsFocusVisible( false );\n\t\t},\n\t\tonKeyDownCapture: ( event: React.KeyboardEvent< HTMLDivElement > ) => {\n\t\t\t// Modifier-only keypresses precede another key rather than\n\t\t\t// indicating deliberate keyboard interaction on their own.\n\t\t\tif (\n\t\t\t\t! [ 'Shift', 'Control', 'Alt', 'Meta' ].includes( event.key )\n\t\t\t) {\n\t\t\t\tsetIsFocusVisible( true );\n\t\t\t}\n\t\t},\n\t\tonPointerDown: ( event: React.PointerEvent< HTMLDivElement > ) => {\n\t\t\thandlers.onPointerDown?.( event );\n\t\t\t// Re-assert false after handlers run \u2014 el.focus() inside the\n\t\t\t// handler fires onFocus, which may otherwise set it back to true.\n\t\t\tsetIsFocusVisible( false );\n\t\t},\n\t};\n\n\t// Register wheel handler natively with { passive: false } so\n\t// preventDefault works. React's onWheel registers as passive. Bound\n\t// to the canvas (not the root) so pointer geometry inside the handler\n\t// resolves against the canvas box.\n\tuseEffect( () => {\n\t\tconst el = canvasRef.current;\n\t\tif ( ! el ) {\n\t\t\treturn;\n\t\t}\n\t\tconst handleWheel = ( event: WheelEvent ) => {\n\t\t\t// Block wheel zoom while resizing or settling \u2014 the stage CSS\n\t\t\t// transform changes getBoundingClientRect() during this window,\n\t\t\t// so focal-point math would resolve against the wrong center.\n\t\t\tif ( isResizingRef.current || isSettlingRef.current ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tonWheelNative( event );\n\t\t};\n\t\tel.addEventListener( 'wheel', handleWheel, {\n\t\t\tpassive: false,\n\t\t} );\n\t\treturn () => {\n\t\t\tel.removeEventListener( 'wheel', handleWheel );\n\t\t};\n\t}, [ onWheelNative ] );\n\n\t// Use the transform style hook for the image CSS transform.\n\tconst transformString = useTransformStyle( state, visualSize );\n\n\t/**\n\t * Handle the image load event.\n\t */\n\tconst handleImageLoad = useCallback(\n\t\t( event: React.SyntheticEvent< HTMLImageElement > ) => {\n\t\t\tconst img = event.currentTarget;\n\t\t\tconst size: Size = {\n\t\t\t\twidth: img.naturalWidth,\n\t\t\t\theight: img.naturalHeight,\n\t\t\t};\n\n\t\t\tsetImage( {\n\t\t\t\tsrc,\n\t\t\t\tnaturalWidth: size.width,\n\t\t\t\tnaturalHeight: size.height,\n\t\t\t} );\n\n\t\t\tonImageLoaded?.( size );\n\t\t},\n\t\t[ src, setImage, onImageLoaded ]\n\t);\n\n\tconst handleCropChange = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tsetCropRect( rect );\n\t\t\t// During a resize drag, pan the viewport so the handle stays\n\t\t\t// visible even when the crop extends beyond the canvas edge.\n\t\t\tif (\n\t\t\t\tisResizingRef.current &&\n\t\t\t\tvisualSize.width > 0 &&\n\t\t\t\tvisualSize.height > 0\n\t\t\t) {\n\t\t\t\tconst offsetX = ( canvasSize.width - visualSize.width ) / 2;\n\t\t\t\tconst offsetY = ( canvasSize.height - visualSize.height ) / 2;\n\t\t\t\tconst rightOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\toffsetX +\n\t\t\t\t\t\t( rect.x + rect.width ) * visualSize.width -\n\t\t\t\t\t\tcanvasSize.width\n\t\t\t\t);\n\t\t\t\tconst leftOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\t-( offsetX + rect.x * visualSize.width )\n\t\t\t\t);\n\t\t\t\tconst bottomOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\toffsetY +\n\t\t\t\t\t\t( rect.y + rect.height ) * visualSize.height -\n\t\t\t\t\t\tcanvasSize.height\n\t\t\t\t);\n\t\t\t\tconst topOverflow = Math.max(\n\t\t\t\t\t0,\n\t\t\t\t\t-( offsetY + rect.y * visualSize.height )\n\t\t\t\t);\n\t\t\t\tsetViewportPan( {\n\t\t\t\t\tx: -rightOverflow + leftOverflow,\n\t\t\t\t\ty: -bottomOverflow + topOverflow,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ setCropRect, setViewportPan, canvasSize, visualSize ]\n\t);\n\n\t// Settling animation: brief linear transition after resize end.\n\tconst [ settling, setSettling ] = useState( false );\n\tconst settleTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\n\t// Clear the pending settle timer on unmount so it can't fire a\n\t// state update on an unmounted component.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( settleTimerRef.current );\n\t\t};\n\t}, [] );\n\n\tconst isInteractiveGrid = showGrid === 'interactive';\n\tconst showInteractiveGrid =\n\t\tisInteractiveGrid &&\n\t\t( isInteractionPlacementActive || isResizing || isPlacementActive );\n\n\t// Output crop size in source pixels \u2014 drives the live tooltip\n\t// overlay. Only computed during pointer drags, so the per-frame\n\t// state churn during pan/zoom doesn't pay for it.\n\tconst outputSize = useMemo( () => {\n\t\tif ( ! showDimensions || ! activeHandle || ! state.image ) {\n\t\t\treturn null;\n\t\t}\n\t\tconst region = getSourceRegion( state, {\n\t\t\twidth: state.image.naturalWidth,\n\t\t\theight: state.image.naturalHeight,\n\t\t} );\n\t\treturn { width: region.width, height: region.height };\n\t}, [ showDimensions, activeHandle, state ] );\n\n\t/**\n\t * Handle Escape on a resize handle \u2014 return focus to the canvas so\n\t * arrow keys pan the image rather than resize.\n\t */\n\tconst handleEscape = useCallback( () => {\n\t\t// Escape is always a keyboard action, so show the outline immediately\n\t\t// rather than relying on the focus handler's :focus-visible check.\n\t\tsetIsFocusVisible( true );\n\t\tcanvasRef.current?.focus( { preventScroll: true } );\n\t}, [] );\n\n\tconst handleResizeStart = useCallback(\n\t\t( handle?: HandlePosition ) => {\n\t\t\tisResizingRef.current = true;\n\t\t\tsetIsResizing( true );\n\t\t\tsetActiveHandle( handle ?? null );\n\t\t\t// Clear any in-flight settle so transitions don't apply during the\n\t\t\t// new drag (rapid successive resizes would otherwise inherit the\n\t\t\t// previous settle animation).\n\t\t\tclearTimeout( settleTimerRef.current );\n\t\t\tisSettlingRef.current = false;\n\t\t\tsetSettling( false );\n\t\t\tresetViewport();\n\t\t\tonGestureStart?.();\n\t\t},\n\t\t[ onGestureStart, resetViewport ]\n\t);\n\n\t/**\n\t * Handle resize end \u2014 settle the crop rect (re-center, fill height)\n\t * and reset the viewport pan back to neutral.\n\t */\n\tconst handleResizeEnd = useCallback( () => {\n\t\tisResizingRef.current = false;\n\t\tsetIsResizing( false );\n\t\tsetActiveHandle( null );\n\t\tisSettlingRef.current = true;\n\t\tsetSettling( true );\n\t\t// Reset viewport pan first so it transitions back to zero in sync\n\t\t// with the settle animation on the image.\n\t\tresetViewport();\n\t\tsettleCrop();\n\t\tonGestureEnd?.();\n\t\tclearTimeout( settleTimerRef.current );\n\t\tsettleTimerRef.current = setTimeout( () => {\n\t\t\tisSettlingRef.current = false;\n\t\t\tsetSettling( false );\n\t\t}, 200 );\n\t}, [ settleCrop, onGestureEnd, resetViewport ] );\n\n\tlet imageTransition: string | undefined;\n\tif ( settling ) {\n\t\timageTransition = 'transform 200ms ease-out';\n\t} else if ( isZooming ) {\n\t\timageTransition = 'transform 150ms linear';\n\t}\n\tconst settleStencilTransition = settling\n\t\t? 'left 200ms ease-out, top 200ms ease-out, width 200ms ease-out, height 200ms ease-out'\n\t\t: undefined;\n\n\t// Compute the image's CSS style.\n\tconst imageStyle = useMemo( (): React.CSSProperties => {\n\t\tif ( elementSize.width === 0 || elementSize.height === 0 ) {\n\t\t\treturn {};\n\t\t}\n\t\tconst centerX = ( canvasSize.width - elementSize.width ) / 2;\n\t\tconst centerY = ( canvasSize.height - elementSize.height ) / 2;\n\t\treturn {\n\t\t\twidth: elementSize.width,\n\t\t\theight: elementSize.height,\n\t\t\tmaxWidth: elementSize.width,\n\t\t\tmaxHeight: elementSize.height,\n\t\t\tleft: centerX,\n\t\t\ttop: centerY,\n\t\t\ttransform: transformString,\n\t\t\ttransition: imageTransition,\n\t\t};\n\t}, [ canvasSize, elementSize, transformString, imageTransition ] );\n\n\t// Viewport pan CSS transform for the stage div. Applied during resize\n\t// drags to keep handles visible when the crop extends past the canvas edge.\n\t// Transitions back to zero during the settle animation.\n\t// will-change promotes the stage to its own compositor layer while the\n\t// transform is active, keeping per-frame pan updates off the main thread.\n\tconst settleTransition = settling ? 'transform 200ms ease-out' : undefined;\n\tconst willChange = isResizing || settling ? 'transform' : undefined;\n\tlet stageStyle: React.CSSProperties | undefined;\n\tif ( viewportState.pan.x !== 0 || viewportState.pan.y !== 0 ) {\n\t\tstageStyle = {\n\t\t\ttransform: `translate(${ viewportState.pan.x }px, ${ viewportState.pan.y }px)`,\n\t\t\ttransition: settleTransition,\n\t\t\twillChange,\n\t\t};\n\t} else if ( settling ) {\n\t\tstageStyle = { transition: settleTransition, willChange };\n\t}\n\n\t// Forward the root element to the consumer's ref.\n\tconst setContainerRef = useCallback(\n\t\t( element: HTMLDivElement | null ) => {\n\t\t\tif ( typeof ref === 'function' ) {\n\t\t\t\tref( element );\n\t\t\t} else if ( ref ) {\n\t\t\t\t(\n\t\t\t\t\tref as React.MutableRefObject< HTMLDivElement | null >\n\t\t\t\t ).current = element;\n\t\t\t}\n\t\t},\n\t\t[ ref ]\n\t);\n\n\treturn (\n\t\t<div\n\t\t\tref={ setContainerRef }\n\t\t\tclassName={ clsx(\n\t\t\t\t'wp-media-editor-image-editor',\n\t\t\t\tisDragging && 'wp-media-editor-image-editor--dragging',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t>\n\t\t\t{ /*\n\t\t\t * The canvas is the interactive, inset surface. Handles and\n\t\t\t * the ARIA role/tabIndex live here so pointer geometry\n\t\t\t * (getBoundingClientRect on e.currentTarget) resolves against\n\t\t\t * the same box that crop math uses. The root stays as the\n\t\t\t * clipping shell for the dimming overlay's box-shadow.\n\t\t\t *\n\t\t\t * Not role=\"application\" \u2014 that disables the screen reader's\n\t\t\t * normal keyboard interception, too heavy-handed for a single\n\t\t\t * widget. Screen reader users get the ARIA live region below\n\t\t\t * as the announcement channel.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tref={ canvasRef }\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'wp-media-editor-image-editor__canvas',\n\t\t\t\t\tisInteractiveGrid &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--grid-interactive',\n\t\t\t\t\tshowInteractiveGrid &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--show-grid',\n\t\t\t\t\tsettling &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--settling',\n\t\t\t\t\t// Marks the cropper as in keyboard-interaction mode.\n\t\t\t\t\t// CSS uses :focus on the canvas to show the stencil\n\t\t\t\t\t// outline and :focus on a handle to show its ring,\n\t\t\t\t\t// so the class applies whenever any cropper element\n\t\t\t\t\t// has keyboard focus.\n\t\t\t\t\tisFocusVisible &&\n\t\t\t\t\t\t'wp-media-editor-image-editor__canvas--focus-visible'\n\t\t\t\t) }\n\t\t\t\ttabIndex={ 0 }\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={ __( 'Crop area' ) }\n\t\t\t\taria-describedby={\n\t\t\t\t\tisCropAreaFocused ? cropAreaDescriptionId : undefined\n\t\t\t\t}\n\t\t\t\tonFocus={ handleCropAreaFocus }\n\t\t\t\tonBlur={ handleCropAreaBlur }\n\t\t\t\t{ ...canvasHandlers }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tid={ cropAreaDescriptionId }\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'When this area is focused, use arrow keys to move the image and plus or minus to zoom. Tab to resize handles and controls.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ /*\n\t\t\t\t * The stage is an inner full-size div that receives the\n\t\t\t\t * viewport pan CSS transform. Keeping the transform here\n\t\t\t\t * (rather than on the canvas) means the canvas always stays\n\t\t\t\t * at its natural position, so the root div's background is\n\t\t\t\t * never exposed when the stage is panned during a resize drag.\n\t\t\t\t */ }\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"wp-media-editor-image-editor__stage\"\n\t\t\t\t\tdata-testid=\"cropper-stage\"\n\t\t\t\t\tstyle={ stageStyle }\n\t\t\t\t>\n\t\t\t\t\t{ /* The image layer */ }\n\t\t\t\t\t<img\n\t\t\t\t\t\tclassName=\"wp-media-editor-image-editor__image\"\n\t\t\t\t\t\tsrc={ src }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tonLoad={ handleImageLoad }\n\t\t\t\t\t\tstyle={ imageStyle }\n\t\t\t\t\t\tdraggable={ false }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ /* Dimming overlay outside the crop area */ }\n\t\t\t\t\t{ showDimming && (\n\t\t\t\t\t\t<DimmingOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ visualSize }\n\t\t\t\t\t\t\ttransition={ settleStencilTransition }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ /* The stencil (crop area with handles) */ }\n\t\t\t\t\t<StencilComponent\n\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\timageSize={ visualSize }\n\t\t\t\t\t\tonCropChange={ handleCropChange }\n\t\t\t\t\t\tonResizeStart={ handleResizeStart }\n\t\t\t\t\t\tonResizeEnd={ handleResizeEnd }\n\t\t\t\t\t\tonEscape={ handleEscape }\n\t\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\t\tfreeformCrop={ freeformCrop }\n\t\t\t\t\t\tstencilTransition={ settleStencilTransition }\n\t\t\t\t\t\tcropBounds={ cropBounds }\n\t\t\t\t\t\tminCropSize={ minCropSize }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ /* Rule-of-thirds grid */ }\n\t\t\t\t\t{ ( showGrid === true || isInteractiveGrid ) && (\n\t\t\t\t\t\t<GridOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ visualSize }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ /* Live dimensions tooltip pinned to the dragged handle. */ }\n\t\t\t\t\t{ activeHandle && outputSize && (\n\t\t\t\t\t\t<DimensionsOverlay\n\t\t\t\t\t\t\tcropRect={ state.cropRect }\n\t\t\t\t\t\t\tcontainerSize={ canvasSize }\n\t\t\t\t\t\t\timageSize={ visualSize }\n\t\t\t\t\t\t\tactiveHandle={ activeHandle }\n\t\t\t\t\t\t\toutputWidth={ outputSize.width }\n\t\t\t\t\t\t\toutputHeight={ outputSize.height }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\n\t\t\t\t{ /* ARIA live region for screen reader announcements */ }\n\t\t\t\t<div\n\t\t\t\t\taria-live=\"polite\"\n\t\t\t\t\taria-atomic=\"true\"\n\t\t\t\t\tclassName=\"wp-media-editor-image-editor__aria-live\"\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ ariaMessage }\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nconst CropperInnerWithRef = forwardRef< HTMLDivElement, CropperProps >(\n\tCropperInner\n);\n\nexport const Cropper = forwardRef< HTMLDivElement, CropperProps >(\n\t( props, ref ) => (\n\t\t<ViewportProvider>\n\t\t\t<CropperInnerWithRef { ...props } ref={ ref } />\n\t\t</ViewportProvider>\n\t)\n);\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO,UAAU;AAKjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AAanB,SAAS,aAAa,sBAAsB;AAC5C,SAAS,oBAAoB,kBAAkB;AAC/C,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB,mBAAmB;AAC9C,SAAS,6BAA6B;AA+qBlC,cAeA,YAfA;AA5qBJ,IAAM,oBAAoB;AAqF1B,SAAS,aACR;AAAA,EACC;AAAA,EACA;AAAA,EACA,SAAS,mBAAmB;AAAA,EAC5B,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,eAAe;AAAA,EACf;AAAA,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,sBACjB,eAAgB;AAAA,sBAChB,WAAY;AAAA;AAAA,kBACb;AAAA,kBAIC,gBAAgB,cACjB;AAAA,oBAAC;AAAA;AAAA,sBACA,UAAW,MAAM;AAAA,sBACjB,eAAgB;AAAA,sBAChB,WAAY;AAAA,sBACZ;AAAA,sBACA,aAAc,WAAW;AAAA,sBACzB,cAAe,WAAW;AAAA;AAAA,kBAC3B;AAAA;AAAA;AAAA,YAEF;AAAA,YAGA;AAAA,cAAC;AAAA;AAAA,gBACA,aAAU;AAAA,gBACV,eAAY;AAAA,gBACZ,WAAU;AAAA,gBACV,OAAQ;AAAA,gBAEN;AAAA;AAAA,YACH;AAAA;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;AAEA,IAAM,sBAAsB;AAAA,EAC3B;AACD;AAEO,IAAM,UAAU;AAAA,EACtB,CAAE,OAAO,QACR,oBAAC,oBACA,8BAAC,uBAAsB,GAAG,OAAQ,KAAY,GAC/C;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -77,7 +77,7 @@ function RectangleStencil({
|
|
|
77
77
|
}),
|
|
78
78
|
[boundsMinX, boundsMinY, boundsMaxX, boundsMaxY]
|
|
79
79
|
);
|
|
80
|
-
const keyboardSettleTimerRef = useRef(
|
|
80
|
+
const keyboardSettleTimerRef = useRef();
|
|
81
81
|
const keyboardResizeActiveRef = useRef(false);
|
|
82
82
|
const resizeHandleDescriptionId = useId();
|
|
83
83
|
const hasLockedRatio = !!(aspectRatio && aspectRatio > 0);
|
|
@@ -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} from '../../../core/stencil-math';\nimport { VISUALLY_HIDDEN_STYLE } from '../../visually-hidden-style';\n\n/**\n * Corner handle positions only \u2014 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 top edge' );\n\t\tcase 's':\n\t\t\treturn __( 'Resize bottom edge' );\n\t\tcase 'e':\n\t\t\treturn __( 'Resize right edge' );\n\t\tcase 'w':\n\t\t\treturn __( 'Resize left edge' );\n\t\tcase 'nw':\n\t\t\treturn __( 'Resize top-left corner' );\n\t\tcase 'ne':\n\t\t\treturn __( 'Resize top-right corner' );\n\t\tcase 'sw':\n\t\t\treturn __( 'Resize bottom-left corner' );\n\t\tcase 'se':\n\t\t\treturn __( 'Resize 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.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 * @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\tstencilTransition,\n\tcropBounds,\n\tonEscape,\n\tminCropSize,\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<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\tconst keyboardResizeActiveRef = useRef( false );\n\tconst resizeHandleDescriptionId = useId();\n\tconst hasLockedRatio = !! ( aspectRatio && aspectRatio > 0 );\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};\n\t}, [] );\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) => 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} | 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 ( 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}\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 onEnd = () => {\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\tlatestHandlersRef.current?.onResizeEnd?.();\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\tel.focus( { preventScroll: true } );\n\t\t\t};\n\n\t\t\tel.addEventListener( 'pointermove', onMove );\n\t\t\tel.addEventListener( 'pointerup', onEnd );\n\t\t\tel.addEventListener( 'lostpointercapture', onEnd );\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, 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): 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),\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 \u2014 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};\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 ( 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 step = event.shiftKey\n\t\t\t\t? DEFAULT_KEYBOARD_STEP * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t\t: DEFAULT_KEYBOARD_STEP;\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 = -step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowRight' ) {\n\t\t\t\tdx = step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowUp' ) {\n\t\t\t\tdy = -step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowDown' ) {\n\t\t\t\tdy = step;\n\t\t\t}\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( syntheticDrag, clientX, clientY )\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\tonCropChange(\n\t\t\t\t\tcomputeFreeRect( syntheticDrag, clientX, clientY )\n\t\t\t\t);\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]\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\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 \u2014 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 ) => event.stopPropagation() }\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": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AAMnB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAIM;AACP,SAAS,6BAA6B;
|
|
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} from '../../../core/stencil-math';\nimport { VISUALLY_HIDDEN_STYLE } from '../../visually-hidden-style';\n\n/**\n * Corner handle positions only \u2014 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 top edge' );\n\t\tcase 's':\n\t\t\treturn __( 'Resize bottom edge' );\n\t\tcase 'e':\n\t\t\treturn __( 'Resize right edge' );\n\t\tcase 'w':\n\t\t\treturn __( 'Resize left edge' );\n\t\tcase 'nw':\n\t\t\treturn __( 'Resize top-left corner' );\n\t\tcase 'ne':\n\t\t\treturn __( 'Resize top-right corner' );\n\t\tcase 'sw':\n\t\t\treturn __( 'Resize bottom-left corner' );\n\t\tcase 'se':\n\t\t\treturn __( 'Resize 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.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 * @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\tstencilTransition,\n\tcropBounds,\n\tonEscape,\n\tminCropSize,\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\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};\n\t}, [] );\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) => 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} | 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 ( 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}\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 onEnd = () => {\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\tlatestHandlersRef.current?.onResizeEnd?.();\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\tel.focus( { preventScroll: true } );\n\t\t\t};\n\n\t\t\tel.addEventListener( 'pointermove', onMove );\n\t\t\tel.addEventListener( 'pointerup', onEnd );\n\t\t\tel.addEventListener( 'lostpointercapture', onEnd );\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, 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): 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),\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 \u2014 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};\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 ( 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 step = event.shiftKey\n\t\t\t\t? DEFAULT_KEYBOARD_STEP * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t\t: DEFAULT_KEYBOARD_STEP;\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 = -step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowRight' ) {\n\t\t\t\tdx = step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowUp' ) {\n\t\t\t\tdy = -step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowDown' ) {\n\t\t\t\tdy = step;\n\t\t\t}\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( syntheticDrag, clientX, clientY )\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\tonCropChange(\n\t\t\t\t\tcomputeFreeRect( syntheticDrag, clientX, clientY )\n\t\t\t\t);\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]\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\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 \u2014 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 ) => event.stopPropagation() }\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": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU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;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ;AAAA,cACP,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,KAAK;AAAA,cACL,MAAM;AAAA,YACP;AAAA;AAAA,QACD;AAAA,QAOE,gBACD,QAAQ,IAAK,CAAE,QACd;AAAA,UAAC;AAAA;AAAA,YAEA,MAAK;AAAA,YACL,WAAY,8EAA+E,GAAI;AAAA,YAC/F,eAAgB,CAAE,UACjB,kBAAmB,KAAK,KAAM;AAAA,YAE/B,cAAe,CAAE,UAAW,MAAM,gBAAgB;AAAA,YAClD,WAAY,CAAE,UAAW,cAAe,KAAK,KAAM;AAAA,YACnD,cAAa,eAAgB,GAAI;AAAA,YACjC,oBAAmB;AAAA;AAAA,UATb;AAAA,QAUP,CACC;AAAA;AAAA;AAAA,EACJ;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -58,9 +58,7 @@ function buildAnnouncement(state, previousState) {
|
|
|
58
58
|
}
|
|
59
59
|
function useAriaAnnouncer(state) {
|
|
60
60
|
const [ariaMessage, setAriaMessage] = useState("");
|
|
61
|
-
const timerRef = useRef(
|
|
62
|
-
void 0
|
|
63
|
-
);
|
|
61
|
+
const timerRef = useRef();
|
|
64
62
|
const prevMessageRef = useRef("");
|
|
65
63
|
const prevStateRef = useRef(null);
|
|
66
64
|
const latestStateRef = useRef(state);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-aria-announcer.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState } from '../../core/types';\n\n/** Debounce delay for ARIA live announcements (ms). */\nconst ARIA_DEBOUNCE_MS = 300;\n\nfunction buildFlipAnnouncement( state: CropperState ): string {\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\n// Build a human-readable announcement string from cropper state.\nfunction buildAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string {\n\tif (\n\t\tpreviousState &&\n\t\t( previousState.flip.horizontal !== state.flip.horizontal ||\n\t\t\tpreviousState.flip.vertical !== state.flip.vertical )\n\t) {\n\t\treturn buildFlipAnnouncement( state );\n\t}\n\n\tconst parts: string[] = [];\n\tparts.push(\n\t\tsprintf(\n\t\t\t/* translators: %d: zoom level as a percentage. */\n\t\t\t__( 'Zoom %d%%' ),\n\t\t\tMath.round( state.zoom * 100 )\n\t\t)\n\t);\n\tif ( state.rotation !== 0 ) {\n\t\tparts.push(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %d: rotation angle in degrees. */\n\t\t\t\t__( 'Rotation %d degrees' ),\n\t\t\t\tMath.round( state.rotation )\n\t\t\t)\n\t\t);\n\t}\n\tconst cropW = Math.round( state.cropRect.width * 100 );\n\tconst cropH = Math.round( state.cropRect.height * 100 );\n\tparts.push(\n\t\tsprintf(\n\t\t\t/* translators: 1: crop width as a percentage, 2: crop height as a percentage. */\n\t\t\t__( 'Crop %1$d%% by %2$d%%' ),\n\t\t\tcropW,\n\t\t\tcropH\n\t\t)\n\t);\n\tif ( state.flip.horizontal || state.flip.vertical ) {\n\t\tparts.push( buildFlipAnnouncement( state ) );\n\t}\n\treturn parts.join( ', ' );\n}\n\n/**\n * Debounce and dedupe ARIA-live announcements for screen readers as the\n * cropper state changes. Returns the current announcement message to render\n * inside an `aria-live=\"polite\"` region.\n *\n * Debouncing avoids flooding the live region 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 ): string {\n\tconst [ ariaMessage, setAriaMessage ] = useState( '' );\n\tconst timerRef = useRef< ReturnType< typeof setTimeout >
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,IAAI,eAAe;AAQ5B,IAAM,mBAAmB;AAEzB,SAAS,sBAAuB,OAA8B;AAC7D,QAAM,EAAE,YAAY,SAAS,IAAI,MAAM;AACvC,MAAK,cAAc,UAAW;AAC7B,WAAO,GAAI,qCAAsC;AAAA,EAClD;AACA,MAAK,YAAa;AACjB,WAAO,GAAI,sBAAuB;AAAA,EACnC;AACA,MAAK,UAAW;AACf,WAAO,GAAI,oBAAqB;AAAA,EACjC;AACA,SAAO,GAAI,cAAe;AAC3B;AAGA,SAAS,kBACR,OACA,eACS;AACT,MACC,kBACE,cAAc,KAAK,eAAe,MAAM,KAAK,cAC9C,cAAc,KAAK,aAAa,MAAM,KAAK,WAC3C;AACD,WAAO,sBAAuB,KAAM;AAAA,EACrC;AAEA,QAAM,QAAkB,CAAC;AACzB,QAAM;AAAA,IACL;AAAA;AAAA,MAEC,GAAI,WAAY;AAAA,MAChB,KAAK,MAAO,MAAM,OAAO,GAAI;AAAA,IAC9B;AAAA,EACD;AACA,MAAK,MAAM,aAAa,GAAI;AAC3B,UAAM;AAAA,MACL;AAAA;AAAA,QAEC,GAAI,qBAAsB;AAAA,QAC1B,KAAK,MAAO,MAAM,QAAS;AAAA,MAC5B;AAAA,IACD;AAAA,EACD;AACA,QAAM,QAAQ,KAAK,MAAO,MAAM,SAAS,QAAQ,GAAI;AACrD,QAAM,QAAQ,KAAK,MAAO,MAAM,SAAS,SAAS,GAAI;AACtD,QAAM;AAAA,IACL;AAAA;AAAA,MAEC,GAAI,uBAAwB;AAAA,MAC5B;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,MAAK,MAAM,KAAK,cAAc,MAAM,KAAK,UAAW;AACnD,UAAM,KAAM,sBAAuB,KAAM,CAAE;AAAA,EAC5C;AACA,SAAO,MAAM,KAAM,IAAK;AACzB;AAYO,SAAS,iBAAkB,OAA8B;AAC/D,QAAM,CAAE,aAAa,cAAe,IAAI,SAAU,EAAG;AACrD,QAAM,WAAW
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseRef,\n} from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState } from '../../core/types';\n\n/** Debounce delay for ARIA live announcements (ms). */\nconst ARIA_DEBOUNCE_MS = 300;\n\nfunction buildFlipAnnouncement( state: CropperState ): string {\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\n// Build a human-readable announcement string from cropper state.\nfunction buildAnnouncement(\n\tstate: CropperState,\n\tpreviousState: CropperState | null\n): string {\n\tif (\n\t\tpreviousState &&\n\t\t( previousState.flip.horizontal !== state.flip.horizontal ||\n\t\t\tpreviousState.flip.vertical !== state.flip.vertical )\n\t) {\n\t\treturn buildFlipAnnouncement( state );\n\t}\n\n\tconst parts: string[] = [];\n\tparts.push(\n\t\tsprintf(\n\t\t\t/* translators: %d: zoom level as a percentage. */\n\t\t\t__( 'Zoom %d%%' ),\n\t\t\tMath.round( state.zoom * 100 )\n\t\t)\n\t);\n\tif ( state.rotation !== 0 ) {\n\t\tparts.push(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %d: rotation angle in degrees. */\n\t\t\t\t__( 'Rotation %d degrees' ),\n\t\t\t\tMath.round( state.rotation )\n\t\t\t)\n\t\t);\n\t}\n\tconst cropW = Math.round( state.cropRect.width * 100 );\n\tconst cropH = Math.round( state.cropRect.height * 100 );\n\tparts.push(\n\t\tsprintf(\n\t\t\t/* translators: 1: crop width as a percentage, 2: crop height as a percentage. */\n\t\t\t__( 'Crop %1$d%% by %2$d%%' ),\n\t\t\tcropW,\n\t\t\tcropH\n\t\t)\n\t);\n\tif ( state.flip.horizontal || state.flip.vertical ) {\n\t\tparts.push( buildFlipAnnouncement( state ) );\n\t}\n\treturn parts.join( ', ' );\n}\n\n/**\n * Debounce and dedupe ARIA-live announcements for screen readers as the\n * cropper state changes. Returns the current announcement message to render\n * inside an `aria-live=\"polite\"` region.\n *\n * Debouncing avoids flooding the live region 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 ): string {\n\tconst [ ariaMessage, setAriaMessage ] = useState( '' );\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\tsetAriaMessage( 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\treturn ariaMessage;\n}\n"],
|
|
5
|
+
"mappings": ";A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Aa,cAAe,IAAI,SAAU,EAAG;AACrD,QAAM,WAAW,OAA0C;AAC3D,QAAM,iBAAiB,OAAQ,EAAG;AAClC,QAAM,eAAe,OAA+B,IAAK;AACzD,QAAM,iBAAiB,OAAQ,KAAM;AACrC,kBAAiB,MAAM;AACtB,mBAAe,UAAU;AAAA,EAC1B,GAAG,CAAE,KAAM,CAAE;AAEb,YAAW,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,uBAAgB,GAAI;AAAA,MACrB;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;AAEF,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -31,7 +31,7 @@ function useInteraction(state, actions, containerSize, imageSize, options) {
|
|
|
31
31
|
const [isZooming, setIsZooming] = useState(false);
|
|
32
32
|
const [isGestureActive, setIsGestureActive] = useState(false);
|
|
33
33
|
const [isKeyboardPanning, setIsKeyboardPanning] = useState(false);
|
|
34
|
-
const keyboardInteractionTimerRef = useRef(
|
|
34
|
+
const keyboardInteractionTimerRef = useRef();
|
|
35
35
|
const isKeyboardGestureActiveRef = useRef(false);
|
|
36
36
|
const stateRef = useRef(state);
|
|
37
37
|
stateRef.current = state;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-interaction.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\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 \u2014 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
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAMzD;AAAA,EACC;AAAA,OAEM;AA8CP,IAAM,+BAA+B;AAErC,SAAS,qBAAsB,OAAgC;AAC9D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAEA,SAAS,sBAAuB,OAAgC;AAC/D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAiBO,SAAS,eACf,OACA,SACA,eACA,WACA,SACuB;AACvB,QAAM,CAAE,YAAY,aAAc,IAAI,SAAU,KAAM;AACtD,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AACpD,QAAM,CAAE,iBAAiB,kBAAmB,IAAI,SAAU,KAAM;AAChE,QAAM,CAAE,mBAAmB,oBAAqB,IAAI,SAAU,KAAM;AACpE,QAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\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 \u2014 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": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAMzD;AAAA,EACC;AAAA,OAEM;AA8CP,IAAM,+BAA+B;AAErC,SAAS,qBAAsB,OAAgC;AAC9D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAEA,SAAS,sBAAuB,OAAgC;AAC/D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAiBO,SAAS,eACf,OACA,SACA,eACA,WACA,SACuB;AACvB,QAAM,CAAE,YAAY,aAAc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