@wordpress/media-editor 0.7.1-next.v.202604201441.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/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/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/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 -7
- 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/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,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render, screen, fireEvent, act } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { RectangleStencil } from '../rectangle-stencil';
|
|
10
|
+
import type { NormalizedRect, Size } from '../../../../core/types';
|
|
11
|
+
|
|
12
|
+
const DEFAULT_CROP_RECT: NormalizedRect = {
|
|
13
|
+
x: 0.1,
|
|
14
|
+
y: 0.1,
|
|
15
|
+
width: 0.8,
|
|
16
|
+
height: 0.8,
|
|
17
|
+
};
|
|
18
|
+
const CONTAINER_SIZE: Size = { width: 600, height: 400 };
|
|
19
|
+
const IMAGE_SIZE: Size = { width: 500, height: 300 };
|
|
20
|
+
const CROP_BOUNDS = { minX: 0, minY: 0, maxX: 1, maxY: 1 };
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Render a RectangleStencil in freeform mode with sensible defaults.
|
|
24
|
+
* Returns the mock callbacks; use `screen` for DOM queries.
|
|
25
|
+
*
|
|
26
|
+
* @param overrides Props to override on the rendered stencil.
|
|
27
|
+
*/
|
|
28
|
+
function renderStencil(
|
|
29
|
+
overrides: Partial< React.ComponentProps< typeof RectangleStencil > > = {}
|
|
30
|
+
) {
|
|
31
|
+
const onCropChange = jest.fn();
|
|
32
|
+
const onResizeStart = jest.fn();
|
|
33
|
+
const onResizeEnd = jest.fn();
|
|
34
|
+
const onEscape = jest.fn();
|
|
35
|
+
|
|
36
|
+
render(
|
|
37
|
+
<RectangleStencil
|
|
38
|
+
cropRect={ DEFAULT_CROP_RECT }
|
|
39
|
+
containerSize={ CONTAINER_SIZE }
|
|
40
|
+
imageSize={ IMAGE_SIZE }
|
|
41
|
+
onCropChange={ onCropChange }
|
|
42
|
+
onResizeStart={ onResizeStart }
|
|
43
|
+
onResizeEnd={ onResizeEnd }
|
|
44
|
+
onEscape={ onEscape }
|
|
45
|
+
freeformCrop
|
|
46
|
+
cropBounds={ CROP_BOUNDS }
|
|
47
|
+
{ ...overrides }
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return { onCropChange, onResizeStart, onResizeEnd, onEscape };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe( 'RectangleStencil', () => {
|
|
55
|
+
// jsdom does not implement PointerEvent or pointer capture — stub both so
|
|
56
|
+
// handle drag tests work. Same pattern as core/test/interaction-controller.ts.
|
|
57
|
+
beforeAll( () => {
|
|
58
|
+
if ( ! HTMLElement.prototype.setPointerCapture ) {
|
|
59
|
+
HTMLElement.prototype.setPointerCapture = jest.fn();
|
|
60
|
+
}
|
|
61
|
+
if ( ! HTMLElement.prototype.releasePointerCapture ) {
|
|
62
|
+
HTMLElement.prototype.releasePointerCapture = jest.fn();
|
|
63
|
+
}
|
|
64
|
+
// Without a PointerEvent constructor, fireEvent.pointerDown falls back to
|
|
65
|
+
// the base Event class which has no `button` property. The stencil's
|
|
66
|
+
// handler guards on `event.button !== 0` and returns early, so no native
|
|
67
|
+
// listeners are ever registered. Providing a minimal stub (extending
|
|
68
|
+
// MouseEvent so `button` comes from MouseEventInit) fixes this.
|
|
69
|
+
if ( typeof ( globalThis as any ).PointerEvent === 'undefined' ) {
|
|
70
|
+
( globalThis as any ).PointerEvent = class PointerEvent extends (
|
|
71
|
+
MouseEvent
|
|
72
|
+
) {
|
|
73
|
+
pointerId: number;
|
|
74
|
+
constructor( type: string, init: PointerEventInit = {} ) {
|
|
75
|
+
super( type, init );
|
|
76
|
+
this.pointerId = init.pointerId ?? 0;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
} );
|
|
81
|
+
|
|
82
|
+
describe( 'tab order', () => {
|
|
83
|
+
it( 'renders handles clockwise from top-left in freeform mode', () => {
|
|
84
|
+
renderStencil();
|
|
85
|
+
const labels = screen
|
|
86
|
+
.getAllByRole( 'button' )
|
|
87
|
+
.map( ( b ) => b.getAttribute( 'aria-label' ) );
|
|
88
|
+
|
|
89
|
+
expect( labels ).toEqual( [
|
|
90
|
+
'Resize top-left corner',
|
|
91
|
+
'Resize top edge',
|
|
92
|
+
'Resize top-right corner',
|
|
93
|
+
'Resize right edge',
|
|
94
|
+
'Resize bottom-right corner',
|
|
95
|
+
'Resize bottom edge',
|
|
96
|
+
'Resize bottom-left corner',
|
|
97
|
+
'Resize left edge',
|
|
98
|
+
] );
|
|
99
|
+
} );
|
|
100
|
+
|
|
101
|
+
it( 'renders corner handles clockwise from top-left when aspect ratio is locked', () => {
|
|
102
|
+
renderStencil( { aspectRatio: 16 / 9 } );
|
|
103
|
+
const labels = screen
|
|
104
|
+
.getAllByRole( 'button' )
|
|
105
|
+
.map( ( b ) => b.getAttribute( 'aria-label' ) );
|
|
106
|
+
|
|
107
|
+
expect( labels ).toEqual( [
|
|
108
|
+
'Resize top-left corner',
|
|
109
|
+
'Resize top-right corner',
|
|
110
|
+
'Resize bottom-right corner',
|
|
111
|
+
'Resize bottom-left corner',
|
|
112
|
+
] );
|
|
113
|
+
} );
|
|
114
|
+
} );
|
|
115
|
+
|
|
116
|
+
describe( 'keyboard — Escape', () => {
|
|
117
|
+
it( 'calls onEscape when Escape is pressed on a handle', () => {
|
|
118
|
+
const { onEscape } = renderStencil();
|
|
119
|
+
const [ firstHandle ] = screen.getAllByRole( 'button' );
|
|
120
|
+
|
|
121
|
+
fireEvent.keyDown( firstHandle, { key: 'Escape' } );
|
|
122
|
+
|
|
123
|
+
expect( onEscape ).toHaveBeenCalledTimes( 1 );
|
|
124
|
+
} );
|
|
125
|
+
|
|
126
|
+
it( 'does not call onCropChange when Escape is pressed', () => {
|
|
127
|
+
const { onCropChange } = renderStencil();
|
|
128
|
+
const [ firstHandle ] = screen.getAllByRole( 'button' );
|
|
129
|
+
|
|
130
|
+
fireEvent.keyDown( firstHandle, { key: 'Escape' } );
|
|
131
|
+
|
|
132
|
+
expect( onCropChange ).not.toHaveBeenCalled();
|
|
133
|
+
} );
|
|
134
|
+
} );
|
|
135
|
+
|
|
136
|
+
describe( 'keyboard — arrow keys (fine step)', () => {
|
|
137
|
+
it( 'calls onResizeStart once and onResizeEnd after keyboard resize settles', () => {
|
|
138
|
+
jest.useFakeTimers();
|
|
139
|
+
const { onResizeStart, onResizeEnd } = renderStencil();
|
|
140
|
+
const eHandle = screen.getAllByRole( 'button' )[ 3 ];
|
|
141
|
+
|
|
142
|
+
fireEvent.keyDown( eHandle, { key: 'ArrowRight' } );
|
|
143
|
+
fireEvent.keyDown( eHandle, { key: 'ArrowRight' } );
|
|
144
|
+
|
|
145
|
+
expect( onResizeStart ).toHaveBeenCalledTimes( 1 );
|
|
146
|
+
expect( onResizeEnd ).not.toHaveBeenCalled();
|
|
147
|
+
|
|
148
|
+
act( () => {
|
|
149
|
+
jest.advanceTimersByTime( 500 );
|
|
150
|
+
} );
|
|
151
|
+
|
|
152
|
+
expect( onResizeEnd ).toHaveBeenCalledTimes( 1 );
|
|
153
|
+
jest.useRealTimers();
|
|
154
|
+
} );
|
|
155
|
+
|
|
156
|
+
it( 'moves the right edge right by KEYBOARD_STEP on ArrowRight (no Shift)', () => {
|
|
157
|
+
const { onCropChange } = renderStencil();
|
|
158
|
+
// 'e' handle is the 4th button in clockwise order (nw, n, ne, e).
|
|
159
|
+
const eHandle = screen.getAllByRole( 'button' )[ 3 ];
|
|
160
|
+
|
|
161
|
+
fireEvent.keyDown( eHandle, {
|
|
162
|
+
key: 'ArrowRight',
|
|
163
|
+
shiftKey: false,
|
|
164
|
+
} );
|
|
165
|
+
|
|
166
|
+
expect( onCropChange ).toHaveBeenCalledTimes( 1 );
|
|
167
|
+
const newRect: NormalizedRect = onCropChange.mock.calls[ 0 ][ 0 ];
|
|
168
|
+
// dx = 0.01, edgeRight = 0.1 + 0.8 + 0.01 = 0.91, width = 0.81.
|
|
169
|
+
expect( newRect.width ).toBeCloseTo( 0.81, 5 );
|
|
170
|
+
expect( newRect.x ).toBeCloseTo( 0.1, 5 );
|
|
171
|
+
} );
|
|
172
|
+
|
|
173
|
+
it( 'moves the bottom edge down by KEYBOARD_STEP on ArrowDown (no Shift)', () => {
|
|
174
|
+
const { onCropChange } = renderStencil();
|
|
175
|
+
// 's' handle is the 6th button (nw, n, ne, e, se, s).
|
|
176
|
+
const sHandle = screen.getAllByRole( 'button' )[ 5 ];
|
|
177
|
+
|
|
178
|
+
fireEvent.keyDown( sHandle, {
|
|
179
|
+
key: 'ArrowDown',
|
|
180
|
+
shiftKey: false,
|
|
181
|
+
} );
|
|
182
|
+
|
|
183
|
+
expect( onCropChange ).toHaveBeenCalledTimes( 1 );
|
|
184
|
+
const newRect: NormalizedRect = onCropChange.mock.calls[ 0 ][ 0 ];
|
|
185
|
+
// dy = 0.01, edgeBottom = 0.1 + 0.8 + 0.01 = 0.91, height = 0.81.
|
|
186
|
+
expect( newRect.height ).toBeCloseTo( 0.81, 5 );
|
|
187
|
+
expect( newRect.y ).toBeCloseTo( 0.1, 5 );
|
|
188
|
+
} );
|
|
189
|
+
} );
|
|
190
|
+
|
|
191
|
+
describe( 'keyboard — arrow keys (coarse step with Shift)', () => {
|
|
192
|
+
it( 'moves the right edge right by KEYBOARD_STEP_SHIFT on Shift+ArrowRight', () => {
|
|
193
|
+
const { onCropChange } = renderStencil();
|
|
194
|
+
const eHandle = screen.getAllByRole( 'button' )[ 3 ];
|
|
195
|
+
|
|
196
|
+
fireEvent.keyDown( eHandle, { key: 'ArrowRight', shiftKey: true } );
|
|
197
|
+
|
|
198
|
+
expect( onCropChange ).toHaveBeenCalledTimes( 1 );
|
|
199
|
+
const newRect: NormalizedRect = onCropChange.mock.calls[ 0 ][ 0 ];
|
|
200
|
+
// dx = 0.1, edgeRight = 0.1 + 0.8 + 0.1 = 1.0 (clamped to boundsMaxX=1), width = 0.9.
|
|
201
|
+
expect( newRect.width ).toBeCloseTo( 0.9, 5 );
|
|
202
|
+
} );
|
|
203
|
+
|
|
204
|
+
it( 'step is 10x larger with Shift than without', () => {
|
|
205
|
+
const { onCropChange } = renderStencil();
|
|
206
|
+
const eHandle = screen.getAllByRole( 'button' )[ 3 ];
|
|
207
|
+
|
|
208
|
+
fireEvent.keyDown( eHandle, {
|
|
209
|
+
key: 'ArrowRight',
|
|
210
|
+
shiftKey: false,
|
|
211
|
+
} );
|
|
212
|
+
const fineRect: NormalizedRect = onCropChange.mock.calls[ 0 ][ 0 ];
|
|
213
|
+
const fineDelta = fineRect.width - DEFAULT_CROP_RECT.width;
|
|
214
|
+
|
|
215
|
+
onCropChange.mockClear();
|
|
216
|
+
|
|
217
|
+
fireEvent.keyDown( eHandle, { key: 'ArrowRight', shiftKey: true } );
|
|
218
|
+
const coarseRect: NormalizedRect =
|
|
219
|
+
onCropChange.mock.calls[ 0 ][ 0 ];
|
|
220
|
+
const coarseDelta = coarseRect.width - DEFAULT_CROP_RECT.width;
|
|
221
|
+
|
|
222
|
+
expect( coarseDelta / fineDelta ).toBeCloseTo( 10, 0 );
|
|
223
|
+
} );
|
|
224
|
+
} );
|
|
225
|
+
|
|
226
|
+
describe( 'pointer drag — focus after release', () => {
|
|
227
|
+
it( 'calls onResizeStart on pointerdown and onResizeEnd on pointerup', () => {
|
|
228
|
+
const { onResizeStart, onResizeEnd } = renderStencil();
|
|
229
|
+
const [ firstHandle ] = screen.getAllByRole( 'button' );
|
|
230
|
+
|
|
231
|
+
fireEvent.pointerDown( firstHandle, {
|
|
232
|
+
button: 0,
|
|
233
|
+
clientX: 100,
|
|
234
|
+
clientY: 100,
|
|
235
|
+
pointerId: 1,
|
|
236
|
+
} );
|
|
237
|
+
|
|
238
|
+
expect( onResizeStart ).toHaveBeenCalledTimes( 1 );
|
|
239
|
+
expect( onResizeEnd ).not.toHaveBeenCalled();
|
|
240
|
+
|
|
241
|
+
fireEvent.pointerUp( firstHandle, { pointerId: 1 } );
|
|
242
|
+
|
|
243
|
+
expect( onResizeEnd ).toHaveBeenCalledTimes( 1 );
|
|
244
|
+
} );
|
|
245
|
+
|
|
246
|
+
it( 'focuses the handle button after a pointer drag ends', () => {
|
|
247
|
+
renderStencil();
|
|
248
|
+
const [ firstHandle ] = screen.getAllByRole( 'button' );
|
|
249
|
+
|
|
250
|
+
jest.spyOn( firstHandle, 'focus' );
|
|
251
|
+
|
|
252
|
+
fireEvent.pointerDown( firstHandle, {
|
|
253
|
+
button: 0,
|
|
254
|
+
clientX: 100,
|
|
255
|
+
clientY: 100,
|
|
256
|
+
pointerId: 1,
|
|
257
|
+
} );
|
|
258
|
+
fireEvent.pointerUp( firstHandle, {
|
|
259
|
+
pointerId: 1,
|
|
260
|
+
} );
|
|
261
|
+
|
|
262
|
+
expect( firstHandle.focus ).toHaveBeenCalled();
|
|
263
|
+
} );
|
|
264
|
+
} );
|
|
265
|
+
} );
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { Cropper } from '../cropper';
|
|
10
|
+
import type { UseCropperStateReturn } from '../../hooks/use-cropper-state';
|
|
11
|
+
import { DEFAULT_STATE } from '../../../core/constants';
|
|
12
|
+
|
|
13
|
+
const GRID_TEST_ID = 'cropper-grid';
|
|
14
|
+
const GRID_INTERACTIVE_CLASS =
|
|
15
|
+
'wp-media-editor-image-editor__canvas--grid-interactive';
|
|
16
|
+
const SHOW_GRID_CLASS = 'wp-media-editor-image-editor__canvas--show-grid';
|
|
17
|
+
|
|
18
|
+
function createController(): UseCropperStateReturn {
|
|
19
|
+
return {
|
|
20
|
+
state: {
|
|
21
|
+
...DEFAULT_STATE,
|
|
22
|
+
image: {
|
|
23
|
+
src: 'test.jpg',
|
|
24
|
+
naturalWidth: 600,
|
|
25
|
+
naturalHeight: 400,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
setImage: jest.fn(),
|
|
29
|
+
setPan: jest.fn(),
|
|
30
|
+
setZoom: jest.fn(),
|
|
31
|
+
setZoomAtPoint: jest.fn(),
|
|
32
|
+
setRotation: jest.fn(),
|
|
33
|
+
setFlip: jest.fn(),
|
|
34
|
+
snapRotate90: jest.fn(),
|
|
35
|
+
setCropRect: jest.fn(),
|
|
36
|
+
settleCrop: jest.fn(),
|
|
37
|
+
applyOperation: jest.fn(),
|
|
38
|
+
reset: jest.fn(),
|
|
39
|
+
isDirty: false,
|
|
40
|
+
getCroppedImage: jest.fn(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe( 'Cropper grid visibility classes', () => {
|
|
45
|
+
const originalResizeObserver = globalThis.ResizeObserver;
|
|
46
|
+
|
|
47
|
+
beforeAll( () => {
|
|
48
|
+
globalThis.ResizeObserver = class ResizeObserver {
|
|
49
|
+
private callback: ResizeObserverCallback;
|
|
50
|
+
|
|
51
|
+
constructor( callback: ResizeObserverCallback ) {
|
|
52
|
+
this.callback = callback;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
observe() {
|
|
56
|
+
this.callback(
|
|
57
|
+
[
|
|
58
|
+
{
|
|
59
|
+
contentRect: { width: 600, height: 400 },
|
|
60
|
+
} as ResizeObserverEntry,
|
|
61
|
+
],
|
|
62
|
+
this
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
unobserve() {}
|
|
67
|
+
|
|
68
|
+
disconnect() {}
|
|
69
|
+
} as typeof ResizeObserver;
|
|
70
|
+
} );
|
|
71
|
+
|
|
72
|
+
afterAll( () => {
|
|
73
|
+
globalThis.ResizeObserver = originalResizeObserver;
|
|
74
|
+
} );
|
|
75
|
+
|
|
76
|
+
it( 'does not render the grid when showGrid is false', () => {
|
|
77
|
+
render(
|
|
78
|
+
<Cropper
|
|
79
|
+
src="test.jpg"
|
|
80
|
+
controller={ createController() }
|
|
81
|
+
showGrid={ false }
|
|
82
|
+
showDimming={ false }
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect( screen.queryByTestId( GRID_TEST_ID ) ).not.toBeInTheDocument();
|
|
87
|
+
} );
|
|
88
|
+
|
|
89
|
+
it( 'renders the grid always visible when showGrid is true', async () => {
|
|
90
|
+
render(
|
|
91
|
+
<Cropper
|
|
92
|
+
src="test.jpg"
|
|
93
|
+
controller={ createController() }
|
|
94
|
+
showGrid
|
|
95
|
+
showDimming={ false }
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
await screen.findByTestId( GRID_TEST_ID );
|
|
100
|
+
|
|
101
|
+
const canvas = screen.getByRole( 'group', { name: 'Image editor' } );
|
|
102
|
+
expect( canvas ).not.toHaveClass( GRID_INTERACTIVE_CLASS );
|
|
103
|
+
expect( canvas ).not.toHaveClass( SHOW_GRID_CLASS );
|
|
104
|
+
} );
|
|
105
|
+
|
|
106
|
+
it( 'renders the grid hidden by default in interactive mode', async () => {
|
|
107
|
+
render(
|
|
108
|
+
<Cropper
|
|
109
|
+
src="test.jpg"
|
|
110
|
+
controller={ createController() }
|
|
111
|
+
showGrid="interactive"
|
|
112
|
+
showDimming={ false }
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
await screen.findByTestId( GRID_TEST_ID );
|
|
117
|
+
|
|
118
|
+
const canvas = screen.getByRole( 'group', { name: 'Image editor' } );
|
|
119
|
+
expect( canvas ).toHaveClass( GRID_INTERACTIVE_CLASS );
|
|
120
|
+
expect( canvas ).not.toHaveClass( SHOW_GRID_CLASS );
|
|
121
|
+
} );
|
|
122
|
+
|
|
123
|
+
it( 'shows the interactive grid when a placement control is active', async () => {
|
|
124
|
+
render(
|
|
125
|
+
<Cropper
|
|
126
|
+
src="test.jpg"
|
|
127
|
+
controller={ createController() }
|
|
128
|
+
showGrid="interactive"
|
|
129
|
+
showDimming={ false }
|
|
130
|
+
isPlacementActive
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
await screen.findByTestId( GRID_TEST_ID );
|
|
135
|
+
|
|
136
|
+
const canvas = screen.getByRole( 'group', { name: 'Image editor' } );
|
|
137
|
+
expect( canvas ).toHaveClass( GRID_INTERACTIVE_CLASS );
|
|
138
|
+
expect( canvas ).toHaveClass( SHOW_GRID_CLASS );
|
|
139
|
+
} );
|
|
140
|
+
} );
|