@wordpress/media-editor 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/media-editor-canvas/index.cjs +54 -0
- package/build/components/media-editor-canvas/index.cjs.map +7 -0
- package/build/components/media-editor-crop-panel/index.cjs +116 -0
- package/build/components/media-editor-crop-panel/index.cjs.map +7 -0
- package/build/components/media-editor-modal/build-modifiers.cjs +91 -0
- package/build/components/media-editor-modal/build-modifiers.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +497 -0
- package/build/components/media-editor-modal/index.cjs.map +7 -0
- package/build/components/media-editor-toolbar/index.cjs +146 -0
- package/build/components/media-editor-toolbar/index.cjs.map +7 -0
- package/build/components/media-preview/index.cjs +1 -1
- package/build/components/media-preview/index.cjs.map +2 -2
- package/build/image-editor/core/camera.cjs +194 -0
- package/build/image-editor/core/camera.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +81 -0
- package/build/image-editor/core/constants.cjs.map +7 -0
- package/build/image-editor/core/containment.cjs +245 -0
- package/build/image-editor/core/containment.cjs.map +7 -0
- package/build/image-editor/core/export/canvas-renderer.cjs +151 -0
- package/build/image-editor/core/export/canvas-renderer.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +50 -0
- package/build/image-editor/core/index.cjs.map +7 -0
- package/build/image-editor/core/interaction-controller.cjs +608 -0
- package/build/image-editor/core/interaction-controller.cjs.map +7 -0
- package/build/image-editor/core/math/rotation.cjs +41 -0
- package/build/image-editor/core/math/rotation.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +95 -0
- package/build/image-editor/core/source-region.cjs.map +7 -0
- package/build/image-editor/core/state.cjs +269 -0
- package/build/image-editor/core/state.cjs.map +7 -0
- package/build/image-editor/core/stencil-math.cjs +197 -0
- package/build/image-editor/core/stencil-math.cjs.map +7 -0
- package/build/image-editor/core/transform-style.cjs +46 -0
- package/build/image-editor/core/transform-style.cjs.map +7 -0
- package/build/image-editor/core/transforms/pipeline.cjs +43 -0
- package/build/image-editor/core/transforms/pipeline.cjs.map +7 -0
- package/build/image-editor/core/types.cjs +19 -0
- package/build/image-editor/core/types.cjs.map +7 -0
- package/build/image-editor/index.cjs +57 -0
- package/build/image-editor/index.cjs.map +7 -0
- package/build/image-editor/react/components/cropper-provider.cjs +50 -0
- package/build/image-editor/react/components/cropper-provider.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +365 -0
- package/build/image-editor/react/components/cropper.cjs.map +7 -0
- package/build/image-editor/react/components/index.cjs +36 -0
- package/build/image-editor/react/components/index.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +58 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +91 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +351 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +31 -0
- package/build/image-editor/react/hooks/index.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +68 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs +158 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +161 -0
- package/build/image-editor/react/hooks/use-interaction.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs +38 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +7 -0
- package/build/index.cjs +5 -2
- package/build/index.cjs.map +2 -2
- package/build/lock-unlock.cjs +37 -0
- package/build/lock-unlock.cjs.map +7 -0
- package/build/private-apis.cjs +38 -0
- package/build/private-apis.cjs.map +7 -0
- package/build/store/actions.cjs +45 -0
- package/build/store/actions.cjs.map +7 -0
- package/build/store/constants.cjs +31 -0
- package/build/store/constants.cjs.map +7 -0
- package/build/store/index.cjs +51 -0
- package/build/store/index.cjs.map +7 -0
- package/build/store/reducer.cjs +51 -0
- package/build/store/reducer.cjs.map +7 -0
- package/build/store/selectors.cjs +43 -0
- package/build/store/selectors.cjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +33 -0
- package/build-module/components/media-editor-canvas/index.mjs.map +7 -0
- package/build-module/components/media-editor-crop-panel/index.mjs +100 -0
- package/build-module/components/media-editor-crop-panel/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs +66 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +483 -0
- package/build-module/components/media-editor-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-toolbar/index.mjs +130 -0
- package/build-module/components/media-editor-toolbar/index.mjs.map +7 -0
- package/build-module/components/media-preview/index.mjs +1 -1
- package/build-module/components/media-preview/index.mjs.map +2 -2
- package/build-module/image-editor/core/camera.mjs +163 -0
- package/build-module/image-editor/core/camera.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +51 -0
- package/build-module/image-editor/core/constants.mjs.map +7 -0
- package/build-module/image-editor/core/containment.mjs +218 -0
- package/build-module/image-editor/core/containment.mjs.map +7 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs +120 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +24 -0
- package/build-module/image-editor/core/index.mjs.map +7 -0
- package/build-module/image-editor/core/interaction-controller.mjs +583 -0
- package/build-module/image-editor/core/interaction-controller.mjs.map +7 -0
- package/build-module/image-editor/core/math/rotation.mjs +15 -0
- package/build-module/image-editor/core/math/rotation.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +69 -0
- package/build-module/image-editor/core/source-region.mjs.map +7 -0
- package/build-module/image-editor/core/state.mjs +242 -0
- package/build-module/image-editor/core/state.mjs.map +7 -0
- package/build-module/image-editor/core/stencil-math.mjs +169 -0
- package/build-module/image-editor/core/stencil-math.mjs.map +7 -0
- package/build-module/image-editor/core/transform-style.mjs +21 -0
- package/build-module/image-editor/core/transform-style.mjs.map +7 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs +17 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +7 -0
- package/build-module/image-editor/core/types.mjs +1 -0
- package/build-module/image-editor/core/types.mjs.map +7 -0
- package/build-module/image-editor/index.mjs +30 -0
- package/build-module/image-editor/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs +26 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +337 -0
- package/build-module/image-editor/react/components/cropper.mjs.map +7 -0
- package/build-module/image-editor/react/components/index.mjs +9 -0
- package/build-module/image-editor/react/components/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +33 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +66 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +330 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +6 -0
- package/build-module/image-editor/react/hooks/index.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +43 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +137 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +138 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +13 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +7 -0
- package/build-module/index.mjs +3 -1
- package/build-module/index.mjs.map +2 -2
- package/build-module/lock-unlock.mjs +11 -0
- package/build-module/lock-unlock.mjs.map +7 -0
- package/build-module/private-apis.mjs +13 -0
- package/build-module/private-apis.mjs.map +7 -0
- package/build-module/store/actions.mjs +19 -0
- package/build-module/store/actions.mjs.map +7 -0
- package/build-module/store/constants.mjs +6 -0
- package/build-module/store/constants.mjs.map +7 -0
- package/build-module/store/index.mjs +16 -0
- package/build-module/store/index.mjs.map +7 -0
- package/build-module/store/reducer.mjs +26 -0
- package/build-module/store/reducer.mjs.map +7 -0
- package/build-module/store/selectors.mjs +16 -0
- package/build-module/store/selectors.mjs.map +7 -0
- package/build-style/style-rtl.css +315 -0
- package/build-style/style.css +315 -0
- package/build-types/components/media-editor-canvas/index.d.ts +22 -0
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts +45 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +20 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-toolbar/index.d.ts +21 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts +107 -0
- package/build-types/image-editor/core/camera.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +46 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -0
- package/build-types/image-editor/core/containment.d.ts +61 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +106 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +8 -0
- package/build-types/image-editor/core/index.d.ts.map +1 -0
- package/build-types/image-editor/core/interaction-controller.d.ts +178 -0
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
- package/build-types/image-editor/core/math/rotation.d.ts +18 -0
- package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts +75 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -0
- package/build-types/image-editor/core/state.d.ts +42 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -0
- package/build-types/image-editor/core/stencil-math.d.ts +79 -0
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
- package/build-types/image-editor/core/transform-style.d.ts +23 -0
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
- package/build-types/image-editor/core/types.d.ts +211 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -0
- package/build-types/image-editor/index.d.ts +16 -0
- package/build-types/image-editor/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +37 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper.d.ts +59 -0
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
- package/build-types/image-editor/react/components/index.d.ts +4 -0
- package/build-types/image-editor/react/components/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +32 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +3 -0
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +68 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +60 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +2 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +27 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +2 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +4 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +23 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +8 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/package.json +21 -8
- package/src/components/media-editor-canvas/index.tsx +56 -0
- package/src/components/media-editor-canvas/style.scss +9 -0
- package/src/components/media-editor-crop-panel/index.tsx +143 -0
- package/src/components/media-editor-modal/build-modifiers.ts +164 -0
- package/src/components/media-editor-modal/index.tsx +639 -0
- package/src/components/media-editor-modal/style.scss +139 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +343 -0
- package/src/components/media-editor-toolbar/index.tsx +150 -0
- package/src/components/media-editor-toolbar/style.scss +21 -0
- package/src/components/media-preview/index.tsx +2 -1
- package/src/image-editor/README.md +162 -0
- package/src/image-editor/core/camera.ts +352 -0
- package/src/image-editor/core/constants.ts +93 -0
- package/src/image-editor/core/containment.ts +435 -0
- package/src/image-editor/core/export/canvas-renderer.ts +253 -0
- package/src/image-editor/core/export/test/canvas-renderer.ts +813 -0
- package/src/image-editor/core/index.ts +35 -0
- package/src/image-editor/core/interaction-controller.ts +889 -0
- package/src/image-editor/core/math/rotation.ts +26 -0
- package/src/image-editor/core/source-region.ts +166 -0
- package/src/image-editor/core/state.ts +428 -0
- package/src/image-editor/core/stencil-math.ts +330 -0
- package/src/image-editor/core/test/camera.ts +593 -0
- package/src/image-editor/core/test/interaction-controller.ts +996 -0
- package/src/image-editor/core/test/preview-export-parity.ts +242 -0
- package/src/image-editor/core/test/render-camera-bridge.ts +348 -0
- package/src/image-editor/core/test/state.ts +762 -0
- package/src/image-editor/core/test/stencil-math.ts +321 -0
- package/src/image-editor/core/transform-style.ts +44 -0
- package/src/image-editor/core/transforms/pipeline.ts +43 -0
- package/src/image-editor/core/transforms/test/pipeline.ts +269 -0
- package/src/image-editor/core/types.ts +177 -0
- package/src/image-editor/docs/architecture.md +96 -0
- package/src/image-editor/docs/recipes.md +720 -0
- package/src/image-editor/docs/roadmap.md +66 -0
- package/src/image-editor/index.ts +43 -0
- package/src/image-editor/react/components/cropper-provider.tsx +73 -0
- package/src/image-editor/react/components/cropper.scss +195 -0
- package/src/image-editor/react/components/cropper.tsx +534 -0
- package/src/image-editor/react/components/index.ts +3 -0
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +57 -0
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +80 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +513 -0
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +265 -0
- package/src/image-editor/react/components/test/cropper.tsx +140 -0
- package/src/image-editor/react/hooks/index.ts +2 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +913 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +218 -0
- package/src/image-editor/react/hooks/test/use-transform-style.ts +146 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +64 -0
- package/src/image-editor/react/hooks/use-cropper-state.ts +238 -0
- package/src/image-editor/react/hooks/use-interaction.ts +223 -0
- package/src/image-editor/react/hooks/use-transform-style.ts +30 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +1085 -0
- package/src/image-editor/stories/style.css +94 -0
- package/src/image-editor/style.scss +1 -0
- package/src/index.ts +3 -0
- package/src/lock-unlock.ts +10 -0
- package/src/private-apis.ts +12 -0
- package/src/store/actions.ts +33 -0
- package/src/store/constants.ts +1 -0
- package/src/store/index.ts +20 -0
- package/src/store/reducer.ts +48 -0
- package/src/store/selectors.ts +16 -0
- package/src/store/test/reducer.ts +57 -0
- package/src/style.scss +4 -0
- package/tsconfig.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/react/components/overlays/grid-overlay.tsx
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
function GridOverlay({
|
|
4
|
+
cropRect,
|
|
5
|
+
containerSize,
|
|
6
|
+
imageSize
|
|
7
|
+
}) {
|
|
8
|
+
if (containerSize.width === 0 || containerSize.height === 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const offsetX = (containerSize.width - imageSize.width) / 2;
|
|
12
|
+
const offsetY = (containerSize.height - imageSize.height) / 2;
|
|
13
|
+
const left = offsetX + cropRect.x * imageSize.width;
|
|
14
|
+
const top = offsetY + cropRect.y * imageSize.height;
|
|
15
|
+
const width = cropRect.width * imageSize.width;
|
|
16
|
+
const height = cropRect.height * imageSize.height;
|
|
17
|
+
const thirdW = width / 3;
|
|
18
|
+
const thirdH = height / 3;
|
|
19
|
+
return /* @__PURE__ */ jsxs(
|
|
20
|
+
"div",
|
|
21
|
+
{
|
|
22
|
+
className: "wp-media-editor-image-editor__grid",
|
|
23
|
+
"data-testid": "cropper-grid",
|
|
24
|
+
style: {
|
|
25
|
+
left,
|
|
26
|
+
top,
|
|
27
|
+
width,
|
|
28
|
+
height
|
|
29
|
+
},
|
|
30
|
+
children: [
|
|
31
|
+
/* @__PURE__ */ jsx(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
className: "wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--horizontal",
|
|
35
|
+
style: { top: thirdH }
|
|
36
|
+
}
|
|
37
|
+
),
|
|
38
|
+
/* @__PURE__ */ jsx(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
className: "wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--horizontal",
|
|
42
|
+
style: { top: thirdH * 2 }
|
|
43
|
+
}
|
|
44
|
+
),
|
|
45
|
+
/* @__PURE__ */ jsx(
|
|
46
|
+
"div",
|
|
47
|
+
{
|
|
48
|
+
className: "wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--vertical",
|
|
49
|
+
style: { left: thirdW }
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
/* @__PURE__ */ jsx(
|
|
53
|
+
"div",
|
|
54
|
+
{
|
|
55
|
+
className: "wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--vertical",
|
|
56
|
+
style: { left: thirdW * 2 }
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
GridOverlay
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=grid-overlay.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/image-editor/react/components/overlays/grid-overlay.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Size } from '../../../core/types';\n\n/**\n * Props for the GridOverlay component.\n */\ninterface GridOverlayProps {\n\t/** The crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** The container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** The rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n}\n\n/**\n * Renders a rule-of-thirds grid inside the crop rectangle.\n *\n * Displays 2 horizontal and 2 vertical lines at 1/3 and 2/3\n * positions within the crop area.\n *\n * @param props Component props.\n * @param props.cropRect The crop rectangle in normalized coordinates.\n * @param props.containerSize The container element dimensions in pixels.\n * @param props.imageSize The rendered image dimensions in pixels.\n * @return The grid overlay element.\n */\nexport function GridOverlay( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n}: GridOverlayProps ) {\n\tif ( containerSize.width === 0 || containerSize.height === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst offsetX = ( containerSize.width - imageSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - imageSize.height ) / 2;\n\tconst left = offsetX + cropRect.x * imageSize.width;\n\tconst top = offsetY + cropRect.y * imageSize.height;\n\tconst width = cropRect.width * imageSize.width;\n\tconst height = cropRect.height * imageSize.height;\n\n\tconst thirdW = width / 3;\n\tconst thirdH = height / 3;\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-media-editor-image-editor__grid\"\n\t\t\tdata-testid=\"cropper-grid\"\n\t\t\tstyle={ {\n\t\t\t\tleft,\n\t\t\t\ttop,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t} }\n\t\t>\n\t\t\t{ /* Horizontal lines at 1/3 and 2/3 */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--horizontal\"\n\t\t\t\tstyle={ { top: thirdH } }\n\t\t\t/>\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--horizontal\"\n\t\t\t\tstyle={ { top: thirdH * 2 } }\n\t\t\t/>\n\t\t\t{ /* Vertical lines at 1/3 and 2/3 */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--vertical\"\n\t\t\t\tstyle={ { left: thirdW } }\n\t\t\t/>\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__grid-line wp-media-editor-image-editor__grid-line--vertical\"\n\t\t\t\tstyle={ { left: thirdW * 2 } }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAiDE,SAWC,KAXD;AApBK,SAAS,YAAa;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AACD,GAAsB;AACrB,MAAK,cAAc,UAAU,KAAK,cAAc,WAAW,GAAI;AAC9D,WAAO;AAAA,EACR;AAEA,QAAM,WAAY,cAAc,QAAQ,UAAU,SAAU;AAC5D,QAAM,WAAY,cAAc,SAAS,UAAU,UAAW;AAC9D,QAAM,OAAO,UAAU,SAAS,IAAI,UAAU;AAC9C,QAAM,MAAM,UAAU,SAAS,IAAI,UAAU;AAC7C,QAAM,QAAQ,SAAS,QAAQ,UAAU;AACzC,QAAM,SAAS,SAAS,SAAS,UAAU;AAE3C,QAAM,SAAS,QAAQ;AACvB,QAAM,SAAS,SAAS;AAExB,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,eAAY;AAAA,MACZ,OAAQ;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,MAGA;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ,EAAE,KAAK,OAAO;AAAA;AAAA,QACvB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ,EAAE,KAAK,SAAS,EAAE;AAAA;AAAA,QAC3B;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ,EAAE,MAAM,OAAO;AAAA;AAAA,QACxB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,OAAQ,EAAE,MAAM,SAAS,EAAE;AAAA;AAAA,QAC5B;AAAA;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/react/components/stencils/rectangle-stencil.tsx
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef } from "@wordpress/element";
|
|
3
|
+
import { __ } from "@wordpress/i18n";
|
|
4
|
+
import {
|
|
5
|
+
computeFreeResizeRect,
|
|
6
|
+
computeLockedResizeRect,
|
|
7
|
+
computeShiftLockedResizeRect
|
|
8
|
+
} from "../../../core/stencil-math.mjs";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var CORNER_POSITIONS = ["nw", "ne", "se", "sw"];
|
|
11
|
+
var ALL_POSITIONS = [
|
|
12
|
+
"nw",
|
|
13
|
+
"n",
|
|
14
|
+
"ne",
|
|
15
|
+
"e",
|
|
16
|
+
"se",
|
|
17
|
+
"s",
|
|
18
|
+
"sw",
|
|
19
|
+
"w"
|
|
20
|
+
];
|
|
21
|
+
function getHandleLabel(pos) {
|
|
22
|
+
switch (pos) {
|
|
23
|
+
case "n":
|
|
24
|
+
return __("Resize top edge");
|
|
25
|
+
case "s":
|
|
26
|
+
return __("Resize bottom edge");
|
|
27
|
+
case "e":
|
|
28
|
+
return __("Resize right edge");
|
|
29
|
+
case "w":
|
|
30
|
+
return __("Resize left edge");
|
|
31
|
+
case "nw":
|
|
32
|
+
return __("Resize top-left corner");
|
|
33
|
+
case "ne":
|
|
34
|
+
return __("Resize top-right corner");
|
|
35
|
+
case "sw":
|
|
36
|
+
return __("Resize bottom-left corner");
|
|
37
|
+
case "se":
|
|
38
|
+
return __("Resize bottom-right corner");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
var KEYBOARD_STEP = 0.01;
|
|
42
|
+
var KEYBOARD_STEP_SHIFT = 0.1;
|
|
43
|
+
var KEYBOARD_SETTLE_DELAY = 500;
|
|
44
|
+
function RectangleStencil({
|
|
45
|
+
cropRect,
|
|
46
|
+
containerSize,
|
|
47
|
+
imageSize,
|
|
48
|
+
onCropChange,
|
|
49
|
+
onResizeStart,
|
|
50
|
+
onResizeEnd,
|
|
51
|
+
aspectRatio,
|
|
52
|
+
freeformCrop = false,
|
|
53
|
+
stencilTransition,
|
|
54
|
+
cropBounds,
|
|
55
|
+
onEscape
|
|
56
|
+
}) {
|
|
57
|
+
const boundsMinX = cropBounds?.minX ?? 0;
|
|
58
|
+
const boundsMinY = cropBounds?.minY ?? 0;
|
|
59
|
+
const boundsMaxX = cropBounds?.maxX ?? 1;
|
|
60
|
+
const boundsMaxY = cropBounds?.maxY ?? 1;
|
|
61
|
+
const bounds = useMemo(
|
|
62
|
+
() => ({
|
|
63
|
+
minX: boundsMinX,
|
|
64
|
+
minY: boundsMinY,
|
|
65
|
+
maxX: boundsMaxX,
|
|
66
|
+
maxY: boundsMaxY
|
|
67
|
+
}),
|
|
68
|
+
[boundsMinX, boundsMinY, boundsMaxX, boundsMaxY]
|
|
69
|
+
);
|
|
70
|
+
const keyboardSettleTimerRef = useRef();
|
|
71
|
+
const keyboardResizeActiveRef = useRef(false);
|
|
72
|
+
const hasLockedRatio = !!(aspectRatio && aspectRatio > 0);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
return () => {
|
|
75
|
+
clearTimeout(keyboardSettleTimerRef.current);
|
|
76
|
+
keyboardResizeActiveRef.current = false;
|
|
77
|
+
};
|
|
78
|
+
}, []);
|
|
79
|
+
const latestHandlersRef = useRef(null);
|
|
80
|
+
const normalizedRatio = useMemo(() => {
|
|
81
|
+
if (!hasLockedRatio || imageSize.width === 0) {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
return aspectRatio * imageSize.height / imageSize.width;
|
|
85
|
+
}, [aspectRatio, hasLockedRatio, imageSize.width, imageSize.height]);
|
|
86
|
+
const offsetX = (containerSize.width - imageSize.width) / 2;
|
|
87
|
+
const offsetY = (containerSize.height - imageSize.height) / 2;
|
|
88
|
+
const left = offsetX + cropRect.x * imageSize.width;
|
|
89
|
+
const top = offsetY + cropRect.y * imageSize.height;
|
|
90
|
+
const width = cropRect.width * imageSize.width;
|
|
91
|
+
const height = cropRect.height * imageSize.height;
|
|
92
|
+
const handlePointerDown = useCallback(
|
|
93
|
+
(handle, event) => {
|
|
94
|
+
if (event.button !== 0) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
const ownerDoc = event.currentTarget.ownerDocument;
|
|
100
|
+
if (ownerDoc.activeElement instanceof HTMLElement) {
|
|
101
|
+
ownerDoc.activeElement.blur();
|
|
102
|
+
}
|
|
103
|
+
const el = event.currentTarget;
|
|
104
|
+
el.setPointerCapture(event.pointerId);
|
|
105
|
+
const drag = {
|
|
106
|
+
handle,
|
|
107
|
+
startX: event.clientX,
|
|
108
|
+
startY: event.clientY,
|
|
109
|
+
startRect: { ...cropRect }
|
|
110
|
+
};
|
|
111
|
+
let rafId = 0;
|
|
112
|
+
let latestX = event.clientX;
|
|
113
|
+
let latestY = event.clientY;
|
|
114
|
+
let latestShift = event.shiftKey;
|
|
115
|
+
const onMove = (e) => {
|
|
116
|
+
const pe = e;
|
|
117
|
+
latestX = pe.clientX;
|
|
118
|
+
latestY = pe.clientY;
|
|
119
|
+
latestShift = pe.shiftKey;
|
|
120
|
+
if (rafId) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
rafId = requestAnimationFrame(() => {
|
|
124
|
+
rafId = 0;
|
|
125
|
+
const h = latestHandlersRef.current;
|
|
126
|
+
if (!h) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
let newRect;
|
|
130
|
+
if (h.hasLockedRatio) {
|
|
131
|
+
newRect = h.computeLockedRect(drag, latestX, latestY);
|
|
132
|
+
} else if (latestShift) {
|
|
133
|
+
newRect = h.computeShiftLockedRect(
|
|
134
|
+
drag,
|
|
135
|
+
latestX,
|
|
136
|
+
latestY
|
|
137
|
+
);
|
|
138
|
+
} else {
|
|
139
|
+
newRect = h.computeFreeRect(drag, latestX, latestY);
|
|
140
|
+
}
|
|
141
|
+
h.onCropChange(newRect);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
let ended = false;
|
|
145
|
+
const onEnd = () => {
|
|
146
|
+
if (ended) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
ended = true;
|
|
150
|
+
if (rafId) {
|
|
151
|
+
cancelAnimationFrame(rafId);
|
|
152
|
+
rafId = 0;
|
|
153
|
+
}
|
|
154
|
+
el.removeEventListener("pointermove", onMove);
|
|
155
|
+
el.removeEventListener("pointerup", onEnd);
|
|
156
|
+
el.removeEventListener("lostpointercapture", onEnd);
|
|
157
|
+
latestHandlersRef.current?.onResizeEnd?.();
|
|
158
|
+
el.focus({ preventScroll: true });
|
|
159
|
+
};
|
|
160
|
+
el.addEventListener("pointermove", onMove);
|
|
161
|
+
el.addEventListener("pointerup", onEnd);
|
|
162
|
+
el.addEventListener("lostpointercapture", onEnd);
|
|
163
|
+
onResizeStart?.();
|
|
164
|
+
clearTimeout(keyboardSettleTimerRef.current);
|
|
165
|
+
keyboardResizeActiveRef.current = false;
|
|
166
|
+
},
|
|
167
|
+
[cropRect, onResizeStart]
|
|
168
|
+
);
|
|
169
|
+
const computeFreeRect = useCallback(
|
|
170
|
+
(drag, clientX, clientY) => computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds),
|
|
171
|
+
[imageSize, bounds]
|
|
172
|
+
);
|
|
173
|
+
const computeLockedRect = useCallback(
|
|
174
|
+
(drag, clientX, clientY) => computeLockedResizeRect(
|
|
175
|
+
drag,
|
|
176
|
+
clientX,
|
|
177
|
+
clientY,
|
|
178
|
+
imageSize,
|
|
179
|
+
bounds,
|
|
180
|
+
normalizedRatio
|
|
181
|
+
),
|
|
182
|
+
[imageSize, bounds, normalizedRatio]
|
|
183
|
+
);
|
|
184
|
+
const computeShiftLockedRect = useCallback(
|
|
185
|
+
(drag, clientX, clientY) => computeShiftLockedResizeRect(
|
|
186
|
+
drag,
|
|
187
|
+
clientX,
|
|
188
|
+
clientY,
|
|
189
|
+
imageSize,
|
|
190
|
+
bounds
|
|
191
|
+
),
|
|
192
|
+
[imageSize, bounds]
|
|
193
|
+
);
|
|
194
|
+
latestHandlersRef.current = {
|
|
195
|
+
hasLockedRatio,
|
|
196
|
+
computeLockedRect,
|
|
197
|
+
computeFreeRect,
|
|
198
|
+
computeShiftLockedRect,
|
|
199
|
+
onCropChange,
|
|
200
|
+
onResizeEnd
|
|
201
|
+
};
|
|
202
|
+
const handleKeyDown = useCallback(
|
|
203
|
+
(handle, event) => {
|
|
204
|
+
const key = event.key;
|
|
205
|
+
if (key === "Escape") {
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
event.stopPropagation();
|
|
208
|
+
onEscape?.();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (key !== "ArrowUp" && key !== "ArrowDown" && key !== "ArrowLeft" && key !== "ArrowRight") {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
event.stopPropagation();
|
|
216
|
+
if (!keyboardResizeActiveRef.current) {
|
|
217
|
+
keyboardResizeActiveRef.current = true;
|
|
218
|
+
onResizeStart?.();
|
|
219
|
+
}
|
|
220
|
+
const scheduleKeyboardResizeEnd = () => {
|
|
221
|
+
clearTimeout(keyboardSettleTimerRef.current);
|
|
222
|
+
keyboardSettleTimerRef.current = setTimeout(() => {
|
|
223
|
+
keyboardResizeActiveRef.current = false;
|
|
224
|
+
onResizeEnd?.();
|
|
225
|
+
}, KEYBOARD_SETTLE_DELAY);
|
|
226
|
+
};
|
|
227
|
+
const step = event.shiftKey ? KEYBOARD_STEP_SHIFT : KEYBOARD_STEP;
|
|
228
|
+
let dx = 0;
|
|
229
|
+
let dy = 0;
|
|
230
|
+
if (key === "ArrowLeft") {
|
|
231
|
+
dx = -step;
|
|
232
|
+
}
|
|
233
|
+
if (key === "ArrowRight") {
|
|
234
|
+
dx = step;
|
|
235
|
+
}
|
|
236
|
+
if (key === "ArrowUp") {
|
|
237
|
+
dy = -step;
|
|
238
|
+
}
|
|
239
|
+
if (key === "ArrowDown") {
|
|
240
|
+
dy = step;
|
|
241
|
+
}
|
|
242
|
+
if (hasLockedRatio) {
|
|
243
|
+
const syntheticDrag = {
|
|
244
|
+
handle,
|
|
245
|
+
startX: 0,
|
|
246
|
+
startY: 0,
|
|
247
|
+
startRect: { ...cropRect }
|
|
248
|
+
};
|
|
249
|
+
const clientX = dx * imageSize.width;
|
|
250
|
+
const clientY = dy * imageSize.height;
|
|
251
|
+
onCropChange(
|
|
252
|
+
computeLockedRect(syntheticDrag, clientX, clientY)
|
|
253
|
+
);
|
|
254
|
+
scheduleKeyboardResizeEnd();
|
|
255
|
+
} else {
|
|
256
|
+
const syntheticDrag = {
|
|
257
|
+
handle,
|
|
258
|
+
startX: 0,
|
|
259
|
+
startY: 0,
|
|
260
|
+
startRect: { ...cropRect }
|
|
261
|
+
};
|
|
262
|
+
const clientX = dx * imageSize.width;
|
|
263
|
+
const clientY = dy * imageSize.height;
|
|
264
|
+
onCropChange(
|
|
265
|
+
computeFreeRect(syntheticDrag, clientX, clientY)
|
|
266
|
+
);
|
|
267
|
+
scheduleKeyboardResizeEnd();
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
[
|
|
271
|
+
cropRect,
|
|
272
|
+
hasLockedRatio,
|
|
273
|
+
imageSize.width,
|
|
274
|
+
imageSize.height,
|
|
275
|
+
computeLockedRect,
|
|
276
|
+
computeFreeRect,
|
|
277
|
+
onCropChange,
|
|
278
|
+
onResizeStart,
|
|
279
|
+
onResizeEnd,
|
|
280
|
+
onEscape
|
|
281
|
+
]
|
|
282
|
+
);
|
|
283
|
+
if (containerSize.width === 0 || containerSize.height === 0) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;
|
|
287
|
+
return /* @__PURE__ */ jsxs(
|
|
288
|
+
"div",
|
|
289
|
+
{
|
|
290
|
+
className: "wp-media-editor-image-editor__stencil",
|
|
291
|
+
style: {
|
|
292
|
+
left,
|
|
293
|
+
top,
|
|
294
|
+
width,
|
|
295
|
+
height,
|
|
296
|
+
transition: stencilTransition
|
|
297
|
+
},
|
|
298
|
+
children: [
|
|
299
|
+
/* @__PURE__ */ jsx(
|
|
300
|
+
"div",
|
|
301
|
+
{
|
|
302
|
+
className: "wp-media-editor-image-editor__stencil-rect",
|
|
303
|
+
style: {
|
|
304
|
+
width: "100%",
|
|
305
|
+
height: "100%",
|
|
306
|
+
top: 0,
|
|
307
|
+
left: 0
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
),
|
|
311
|
+
freeformCrop && handles.map((pos) => /* @__PURE__ */ jsx(
|
|
312
|
+
"button",
|
|
313
|
+
{
|
|
314
|
+
type: "button",
|
|
315
|
+
className: `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${pos}`,
|
|
316
|
+
onPointerDown: (event) => handlePointerDown(pos, event),
|
|
317
|
+
onTouchStart: (event) => event.stopPropagation(),
|
|
318
|
+
onKeyDown: (event) => handleKeyDown(pos, event),
|
|
319
|
+
"aria-label": getHandleLabel(pos)
|
|
320
|
+
},
|
|
321
|
+
pos
|
|
322
|
+
))
|
|
323
|
+
]
|
|
324
|
+
}
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
export {
|
|
328
|
+
RectangleStencil
|
|
329
|
+
};
|
|
330
|
+
//# sourceMappingURL=rectangle-stencil.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../src/image-editor/react/components/stencils/rectangle-stencil.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useMemo, useRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { StencilProps, NormalizedRect } from '../../../core/types';\nimport {\n\tcomputeFreeResizeRect,\n\tcomputeLockedResizeRect,\n\tcomputeShiftLockedResizeRect,\n\ttype HandlePosition,\n\ttype CropBounds,\n\ttype ResizeDragState,\n} from '../../../core/stencil-math';\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/** Fine step for keyboard-driven handle resize, in normalized coordinates. */\nconst KEYBOARD_STEP = 0.01;\n\n/** Coarse step when Shift is held \u2014 10\u00D7 the fine step. */\nconst KEYBOARD_STEP_SHIFT = 0.1;\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 * @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}: 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 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?.();\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( drag, clientX, clientY, imageSize, bounds ),\n\t\t[ imageSize, bounds ]\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),\n\t\t[ imageSize, bounds, normalizedRatio ]\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),\n\t\t[ imageSize, bounds ]\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?.();\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 ? KEYBOARD_STEP_SHIFT : 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{ /* 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/>\n\t\t\t\t) ) }\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa,WAAW,SAAS,cAAc;AACxD,SAA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AgB,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;AAAA,UAR3B;AAAA,QASP,CACC;AAAA;AAAA;AAAA,EACJ;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/image-editor/react/hooks/index.ts"],
|
|
4
|
+
"sourcesContent": ["export { useCropperState } from './use-cropper-state';\nexport type { UseCropperStateReturn } from './use-cropper-state';\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,uBAAuB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/react/hooks/use-aria-announcer.ts
|
|
2
|
+
import { useState, useEffect, useRef } from "@wordpress/element";
|
|
3
|
+
var ARIA_DEBOUNCE_MS = 300;
|
|
4
|
+
function buildAnnouncement(state) {
|
|
5
|
+
const parts = [];
|
|
6
|
+
parts.push(`Zoom ${Math.round(state.zoom * 100)}%`);
|
|
7
|
+
if (state.rotation !== 0) {
|
|
8
|
+
parts.push(`Rotation ${Math.round(state.rotation)} degrees`);
|
|
9
|
+
}
|
|
10
|
+
const cropW = Math.round(state.cropRect.width * 100);
|
|
11
|
+
const cropH = Math.round(state.cropRect.height * 100);
|
|
12
|
+
parts.push(`Crop ${cropW}% by ${cropH}%`);
|
|
13
|
+
return parts.join(", ");
|
|
14
|
+
}
|
|
15
|
+
function useAriaAnnouncer(state) {
|
|
16
|
+
const [ariaMessage, setAriaMessage] = useState("");
|
|
17
|
+
const timerRef = useRef();
|
|
18
|
+
const prevMessageRef = useRef("");
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
clearTimeout(timerRef.current);
|
|
21
|
+
timerRef.current = setTimeout(() => {
|
|
22
|
+
const msg = buildAnnouncement(state);
|
|
23
|
+
if (msg !== prevMessageRef.current) {
|
|
24
|
+
prevMessageRef.current = msg;
|
|
25
|
+
setAriaMessage(msg);
|
|
26
|
+
}
|
|
27
|
+
}, ARIA_DEBOUNCE_MS);
|
|
28
|
+
return () => {
|
|
29
|
+
clearTimeout(timerRef.current);
|
|
30
|
+
};
|
|
31
|
+
}, [
|
|
32
|
+
state.zoom,
|
|
33
|
+
state.rotation,
|
|
34
|
+
state.cropRect.width,
|
|
35
|
+
state.cropRect.height,
|
|
36
|
+
state
|
|
37
|
+
]);
|
|
38
|
+
return ariaMessage;
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
useAriaAnnouncer
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=use-aria-announcer.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/image-editor/react/hooks/use-aria-announcer.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useEffect, useRef } from '@wordpress/element';\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\n// Build a human-readable announcement string from cropper state.\nfunction buildAnnouncement( state: CropperState ): string {\n\tconst parts: string[] = [];\n\tparts.push( `Zoom ${ Math.round( state.zoom * 100 ) }%` );\n\tif ( state.rotation !== 0 ) {\n\t\tparts.push( `Rotation ${ Math.round( state.rotation ) } degrees` );\n\t}\n\tconst cropW = Math.round( state.cropRect.width * 100 );\n\tconst cropH = Math.round( state.cropRect.height * 100 );\n\tparts.push( `Crop ${ cropW }% by ${ cropH }%` );\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\n\tuseEffect( () => {\n\t\tclearTimeout( timerRef.current );\n\t\ttimerRef.current = setTimeout( () => {\n\t\t\tconst msg = buildAnnouncement( state );\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,\n\t] );\n\n\treturn ariaMessage;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU,WAAW,cAAc;AAQ5C,IAAM,mBAAmB;AAGzB,SAAS,kBAAmB,OAA8B;AACzD,QAAM,QAAkB,CAAC;AACzB,QAAM,KAAM,QAAS,KAAK,MAAO,MAAM,OAAO,GAAI,CAAE,GAAI;AACxD,MAAK,MAAM,aAAa,GAAI;AAC3B,UAAM,KAAM,YAAa,KAAK,MAAO,MAAM,QAAS,CAAE,UAAW;AAAA,EAClE;AACA,QAAM,QAAQ,KAAK,MAAO,MAAM,SAAS,QAAQ,GAAI;AACrD,QAAM,QAAQ,KAAK,MAAO,MAAM,SAAS,SAAS,GAAI;AACtD,QAAM,KAAM,QAAS,KAAM,QAAS,KAAM,GAAI;AAC9C,SAAO,MAAM,KAAM,IAAK;AACzB;AAYO,SAAS,iBAAkB,OAA8B;AAC/D,QAAM,CAAE,aAAa,cAAe,IAAI,SAAU,EAAG;AACrD,QAAM,WAAW,OAA0C;AAC3D,QAAM,iBAAiB,OAAQ,EAAG;AAElC,YAAW,MAAM;AAChB,iBAAc,SAAS,OAAQ;AAC/B,aAAS,UAAU,WAAY,MAAM;AACpC,YAAM,MAAM,kBAAmB,KAAM;AACrC,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;AAAA,EACD,CAAE;AAEF,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// packages/media-editor/src/image-editor/react/hooks/use-cropper-state.ts
|
|
2
|
+
import { useReducer, useCallback, useRef } from "@wordpress/element";
|
|
3
|
+
import { DEFAULT_STATE } from "../../core/constants.mjs";
|
|
4
|
+
import { exportCroppedImage } from "../../core/export/canvas-renderer.mjs";
|
|
5
|
+
import {
|
|
6
|
+
cropperReducer,
|
|
7
|
+
enforceContainment,
|
|
8
|
+
isStateDirty
|
|
9
|
+
} from "../../core/state.mjs";
|
|
10
|
+
function useCropperState(initialState) {
|
|
11
|
+
const [state, dispatch] = useReducer(
|
|
12
|
+
cropperReducer,
|
|
13
|
+
initialState,
|
|
14
|
+
(init) => enforceContainment({ ...DEFAULT_STATE, ...init })
|
|
15
|
+
);
|
|
16
|
+
const initialRef = useRef(
|
|
17
|
+
enforceContainment({ ...DEFAULT_STATE, ...initialState })
|
|
18
|
+
);
|
|
19
|
+
const stateRef = useRef(state);
|
|
20
|
+
stateRef.current = state;
|
|
21
|
+
const setImage = useCallback(
|
|
22
|
+
(image) => {
|
|
23
|
+
dispatch({ type: "SET_IMAGE", payload: image });
|
|
24
|
+
initialRef.current = enforceContainment({
|
|
25
|
+
...initialRef.current,
|
|
26
|
+
image
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
[dispatch]
|
|
30
|
+
);
|
|
31
|
+
const setPan = useCallback(
|
|
32
|
+
(pan) => {
|
|
33
|
+
dispatch({ type: "SET_PAN", payload: pan });
|
|
34
|
+
},
|
|
35
|
+
[dispatch]
|
|
36
|
+
);
|
|
37
|
+
const setZoom = useCallback(
|
|
38
|
+
(zoom) => {
|
|
39
|
+
dispatch({ type: "SET_ZOOM", payload: zoom });
|
|
40
|
+
},
|
|
41
|
+
[dispatch]
|
|
42
|
+
);
|
|
43
|
+
const setZoomAtPoint = useCallback(
|
|
44
|
+
(zoom, pan) => {
|
|
45
|
+
dispatch({
|
|
46
|
+
type: "SET_ZOOM_AT_POINT",
|
|
47
|
+
payload: { zoom, pan }
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
[dispatch]
|
|
51
|
+
);
|
|
52
|
+
const setRotation = useCallback(
|
|
53
|
+
(rotation) => {
|
|
54
|
+
dispatch({ type: "SET_ROTATION", payload: rotation });
|
|
55
|
+
},
|
|
56
|
+
[dispatch]
|
|
57
|
+
);
|
|
58
|
+
const setFlip = useCallback(
|
|
59
|
+
(flip) => {
|
|
60
|
+
dispatch({ type: "SET_FLIP", payload: flip });
|
|
61
|
+
},
|
|
62
|
+
[dispatch]
|
|
63
|
+
);
|
|
64
|
+
const snapRotate90 = useCallback(
|
|
65
|
+
(direction) => {
|
|
66
|
+
dispatch({
|
|
67
|
+
type: "SNAP_ROTATE_90",
|
|
68
|
+
payload: { direction }
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
[dispatch]
|
|
72
|
+
);
|
|
73
|
+
const setCropRect = useCallback(
|
|
74
|
+
(rect) => {
|
|
75
|
+
dispatch({ type: "SET_CROP_RECT", payload: rect });
|
|
76
|
+
},
|
|
77
|
+
[dispatch]
|
|
78
|
+
);
|
|
79
|
+
const settleCrop = useCallback(() => {
|
|
80
|
+
dispatch({ type: "SETTLE_CROP" });
|
|
81
|
+
}, [dispatch]);
|
|
82
|
+
const applyOperation = useCallback(
|
|
83
|
+
(op) => {
|
|
84
|
+
dispatch({ type: "APPLY_OPERATION", payload: op });
|
|
85
|
+
},
|
|
86
|
+
[dispatch]
|
|
87
|
+
);
|
|
88
|
+
const reset = useCallback(
|
|
89
|
+
(resetState) => {
|
|
90
|
+
dispatch({ type: "RESET", payload: resetState });
|
|
91
|
+
initialRef.current = enforceContainment({
|
|
92
|
+
...DEFAULT_STATE,
|
|
93
|
+
image: stateRef.current.image,
|
|
94
|
+
...resetState
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
[dispatch]
|
|
98
|
+
);
|
|
99
|
+
const isDirty = isStateDirty(state, initialRef.current);
|
|
100
|
+
const getCroppedImage = useCallback(
|
|
101
|
+
(mimeType, quality) => {
|
|
102
|
+
if (!state.image) {
|
|
103
|
+
return Promise.reject(
|
|
104
|
+
new Error("No image loaded \u2014 call setImage first.")
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return exportCroppedImage(
|
|
108
|
+
state.image.src,
|
|
109
|
+
state,
|
|
110
|
+
mimeType,
|
|
111
|
+
quality
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
[state]
|
|
115
|
+
);
|
|
116
|
+
const controller = {
|
|
117
|
+
state,
|
|
118
|
+
setImage,
|
|
119
|
+
setPan,
|
|
120
|
+
setZoom,
|
|
121
|
+
setZoomAtPoint,
|
|
122
|
+
setRotation,
|
|
123
|
+
setFlip,
|
|
124
|
+
snapRotate90,
|
|
125
|
+
setCropRect,
|
|
126
|
+
settleCrop,
|
|
127
|
+
applyOperation,
|
|
128
|
+
reset,
|
|
129
|
+
isDirty,
|
|
130
|
+
getCroppedImage
|
|
131
|
+
};
|
|
132
|
+
return controller;
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
useCropperState
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=use-cropper-state.mjs.map
|