@wordpress/media-editor 0.13.1-next.v.202607070741.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/build/image-editor/react/components/cropper.cjs +1 -11
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +8 -8
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +75 -32
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +1 -11
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +8 -8
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +76 -38
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-style/style-rtl.css +5 -5
- package/build-style/style.css +5 -5
- package/build-types/components/media-editor/use-crop-options.d.ts +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +1 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts +24 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts +21 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +1 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +1 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +5 -4
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +108 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/build-types/state/media-editor-state-provider.d.ts +1 -1
- package/build-types/state/media-editor-state-provider.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +1 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/package.json +22 -21
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-preview/style.scss +1 -1
- package/src/components/rotation-ruler/style.scss +2 -2
- package/src/image-editor/react/components/cropper.tsx +3 -12
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +8 -8
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +17 -15
- package/src/image-editor/react/components/test/cropper.tsx +17 -17
- package/src/image-editor/react/hooks/test/use-aria-announcer.ts +413 -5
- package/src/image-editor/react/hooks/use-aria-announcer.ts +120 -47
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
useEffect,
|
|
7
|
-
useLayoutEffect,
|
|
8
|
-
useRef,
|
|
9
|
-
} from '@wordpress/element';
|
|
4
|
+
import { speak } from '@wordpress/a11y';
|
|
5
|
+
import { useEffect, useLayoutEffect, useRef } from '@wordpress/element';
|
|
10
6
|
import { __, sprintf } from '@wordpress/i18n';
|
|
11
7
|
|
|
12
8
|
/**
|
|
13
9
|
* Internal dependencies
|
|
14
10
|
*/
|
|
15
11
|
import type { CropperState } from '../../core/types';
|
|
12
|
+
import { getSourceRegion } from '../../core/source-region';
|
|
16
13
|
|
|
17
14
|
/** Debounce delay for ARIA live announcements (ms). */
|
|
18
15
|
const ARIA_DEBOUNCE_MS = 300;
|
|
19
16
|
|
|
20
|
-
function
|
|
17
|
+
function getFlipAnnouncement(
|
|
18
|
+
state: CropperState,
|
|
19
|
+
previousState: CropperState | null
|
|
20
|
+
): string | undefined {
|
|
21
|
+
if (
|
|
22
|
+
! previousState ||
|
|
23
|
+
( previousState.flip.horizontal === state.flip.horizontal &&
|
|
24
|
+
previousState.flip.vertical === state.flip.vertical )
|
|
25
|
+
) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
21
28
|
const { horizontal, vertical } = state.flip;
|
|
22
29
|
if ( horizontal && vertical ) {
|
|
23
30
|
return __( 'Flipped horizontally and vertically' );
|
|
@@ -31,64 +38,132 @@ function buildFlipAnnouncement( state: CropperState ): string {
|
|
|
31
38
|
return __( 'Flip removed' );
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
function buildAnnouncement(
|
|
41
|
+
function getRotationAnnouncement(
|
|
36
42
|
state: CropperState,
|
|
37
43
|
previousState: CropperState | null
|
|
38
|
-
): string {
|
|
44
|
+
): string | undefined {
|
|
39
45
|
if (
|
|
40
46
|
previousState &&
|
|
41
|
-
( previousState.
|
|
42
|
-
previousState.flip.vertical !== state.flip.vertical )
|
|
47
|
+
Math.round( previousState.rotation ) === Math.round( state.rotation )
|
|
43
48
|
) {
|
|
44
|
-
return
|
|
49
|
+
return undefined;
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// Announce the visual rotation — what the user perceives on screen. A
|
|
52
|
+
// single-axis flip mirrors the image, reversing the entire on-screen
|
|
53
|
+
// rotation relative to the stored field (the same S·R·S inversion the
|
|
54
|
+
// reducer applies), so negate the whole angle in that case.
|
|
55
|
+
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
56
|
+
const visualDir = singleFlip ? -1 : 1;
|
|
57
|
+
// Normalize to (-180, 180] so the sign indicates direction.
|
|
58
|
+
let visualRotation = ( Math.round( state.rotation ) * visualDir ) % 360;
|
|
59
|
+
if ( visualRotation > 180 ) {
|
|
60
|
+
visualRotation -= 360;
|
|
61
|
+
}
|
|
62
|
+
if ( visualRotation <= -180 ) {
|
|
63
|
+
visualRotation += 360;
|
|
64
|
+
}
|
|
65
|
+
if ( visualRotation === 0 ) {
|
|
66
|
+
return previousState ? __( 'Rotation 0 degrees' ) : undefined;
|
|
67
|
+
}
|
|
68
|
+
if ( visualRotation > 0 ) {
|
|
69
|
+
return sprintf(
|
|
70
|
+
/* translators: %d: rotation angle in degrees. */
|
|
71
|
+
__( 'Rotated %d degrees clockwise' ),
|
|
72
|
+
visualRotation
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return sprintf(
|
|
76
|
+
/* translators: %d: rotation angle in degrees. */
|
|
77
|
+
__( 'Rotated %d degrees counterclockwise' ),
|
|
78
|
+
Math.abs( visualRotation )
|
|
54
79
|
);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getCropAnnouncement(
|
|
83
|
+
state: CropperState,
|
|
84
|
+
previousState: CropperState | null
|
|
85
|
+
): string | undefined {
|
|
86
|
+
if ( ! state.image ) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const imageSize = {
|
|
90
|
+
width: state.image.naturalWidth,
|
|
91
|
+
height: state.image.naturalHeight,
|
|
92
|
+
};
|
|
93
|
+
const region = getSourceRegion( state, imageSize );
|
|
94
|
+
// Announce only when the crop's pixel dimensions change. Measuring both the
|
|
95
|
+
// previous and current crop rects under the current rotation and zoom keeps
|
|
96
|
+
// the comparison in the same pixel units we announce, and leaves a zoom-only
|
|
97
|
+
// change — which doesn't move the crop rect — silent.
|
|
98
|
+
if ( previousState?.image ) {
|
|
99
|
+
const previousRegion = getSourceRegion(
|
|
100
|
+
{ ...state, cropRect: previousState.cropRect },
|
|
101
|
+
imageSize
|
|
62
102
|
);
|
|
103
|
+
if (
|
|
104
|
+
Math.round( previousRegion.width ) === Math.round( region.width ) &&
|
|
105
|
+
Math.round( previousRegion.height ) === Math.round( region.height )
|
|
106
|
+
) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
63
109
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
__( 'Crop %1$d%% by %2$d%%' ),
|
|
70
|
-
cropW,
|
|
71
|
-
cropH
|
|
72
|
-
)
|
|
110
|
+
return sprintf(
|
|
111
|
+
/* translators: 1: crop width in pixels, 2: crop height in pixels. */
|
|
112
|
+
__( 'Crop %1$d by %2$d pixels' ),
|
|
113
|
+
Math.round( region.width ),
|
|
114
|
+
Math.round( region.height )
|
|
73
115
|
);
|
|
74
|
-
|
|
75
|
-
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getZoomAnnouncement(
|
|
119
|
+
state: CropperState,
|
|
120
|
+
previousState: CropperState | null
|
|
121
|
+
): string | undefined {
|
|
122
|
+
if (
|
|
123
|
+
previousState &&
|
|
124
|
+
Math.round( previousState.zoom * 100 ) ===
|
|
125
|
+
Math.round( state.zoom * 100 )
|
|
126
|
+
) {
|
|
127
|
+
return undefined;
|
|
76
128
|
}
|
|
129
|
+
return sprintf(
|
|
130
|
+
/* translators: %d: zoom level as a percentage. */
|
|
131
|
+
__( 'Zoom %d%%' ),
|
|
132
|
+
Math.round( state.zoom * 100 )
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function buildAnnouncement(
|
|
137
|
+
state: CropperState,
|
|
138
|
+
previousState: CropperState | null
|
|
139
|
+
): string {
|
|
140
|
+
// Flip changes are announced alone.
|
|
141
|
+
const flip = getFlipAnnouncement( state, previousState );
|
|
142
|
+
if ( flip ) {
|
|
143
|
+
return flip;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const parts = [
|
|
147
|
+
getRotationAnnouncement( state, previousState ),
|
|
148
|
+
getZoomAnnouncement( state, previousState ),
|
|
149
|
+
getCropAnnouncement( state, previousState ),
|
|
150
|
+
].filter( ( part ): part is string => part !== undefined );
|
|
151
|
+
|
|
77
152
|
return parts.join( ', ' );
|
|
78
153
|
}
|
|
79
154
|
|
|
80
155
|
/**
|
|
81
156
|
* Debounce and dedupe ARIA-live announcements for screen readers as the
|
|
82
|
-
* cropper state changes.
|
|
83
|
-
*
|
|
157
|
+
* cropper state changes. Calls `speak()` from `@wordpress/a11y` to use the
|
|
158
|
+
* centralized, persistent live region instead of a local one that may be
|
|
159
|
+
* dynamically mounted.
|
|
84
160
|
*
|
|
85
|
-
* Debouncing avoids flooding
|
|
161
|
+
* Debouncing avoids flooding announcements during drag/pointermove bursts;
|
|
86
162
|
* deduping avoids re-announcing the same state.
|
|
87
163
|
*
|
|
88
164
|
* @param state The current cropper state to announce.
|
|
89
165
|
*/
|
|
90
|
-
export function useAriaAnnouncer( state: CropperState ):
|
|
91
|
-
const [ ariaMessage, setAriaMessage ] = useState( '' );
|
|
166
|
+
export function useAriaAnnouncer( state: CropperState ): void {
|
|
92
167
|
const timerRef = useRef< ReturnType< typeof setTimeout > >();
|
|
93
168
|
const prevMessageRef = useRef( '' );
|
|
94
169
|
const prevStateRef = useRef< CropperState | null >( null );
|
|
@@ -105,7 +180,7 @@ export function useAriaAnnouncer( state: CropperState ): string {
|
|
|
105
180
|
prevStateRef.current = current;
|
|
106
181
|
if ( msg !== prevMessageRef.current ) {
|
|
107
182
|
prevMessageRef.current = msg;
|
|
108
|
-
|
|
183
|
+
speak( msg );
|
|
109
184
|
}
|
|
110
185
|
}, ARIA_DEBOUNCE_MS );
|
|
111
186
|
|
|
@@ -120,6 +195,4 @@ export function useAriaAnnouncer( state: CropperState ): string {
|
|
|
120
195
|
state.flip.horizontal,
|
|
121
196
|
state.flip.vertical,
|
|
122
197
|
] );
|
|
123
|
-
|
|
124
|
-
return ariaMessage;
|
|
125
198
|
}
|