@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.
Files changed (75) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/build/image-editor/react/components/cropper.cjs +1 -11
  3. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  4. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +8 -8
  5. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  6. package/build/image-editor/react/hooks/use-aria-announcer.cjs +75 -32
  7. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
  8. package/build-module/image-editor/react/components/cropper.mjs +1 -11
  9. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  10. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +8 -8
  11. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  12. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +76 -38
  13. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
  14. package/build-style/style-rtl.css +5 -5
  15. package/build-style/style.css +5 -5
  16. package/build-types/components/media-editor/use-crop-options.d.ts +1 -1
  17. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  18. package/build-types/components/media-editor/use-save-media-editor.d.ts +1 -1
  19. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  20. package/build-types/components/media-editor-canvas/index.d.ts +1 -1
  21. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  22. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  23. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  24. package/build-types/components/media-editor-fine-rotation/index.d.ts +1 -1
  25. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  26. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  27. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  28. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +1 -1
  29. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  30. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  31. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  32. package/build-types/components/media-editor-provider/index.d.ts +1 -1
  33. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  34. package/build-types/components/media-editor-toolbar/index.d.ts +24 -0
  35. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
  36. package/build-types/components/media-editor-transform-controls/index.d.ts +21 -0
  37. package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
  38. package/build-types/components/media-form/index.d.ts +1 -1
  39. package/build-types/components/media-form/index.d.ts.map +1 -1
  40. package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
  41. package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
  42. package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
  43. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  44. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  45. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +1 -1
  46. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -1
  47. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +1 -1
  48. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  49. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
  50. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
  51. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
  52. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  53. package/build-types/image-editor/react/components/viewport-provider.d.ts +1 -1
  54. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -1
  55. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +5 -4
  56. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
  57. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +108 -0
  58. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
  59. package/build-types/state/media-editor-state-provider.d.ts +1 -1
  60. package/build-types/state/media-editor-state-provider.d.ts.map +1 -1
  61. package/build-types/store/actions.d.ts +1 -1
  62. package/build-types/store/actions.d.ts.map +1 -1
  63. package/package.json +22 -21
  64. package/src/components/media-editor-image-controls/style.scss +1 -1
  65. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  66. package/src/components/media-preview/style.scss +1 -1
  67. package/src/components/rotation-ruler/style.scss +2 -2
  68. package/src/image-editor/react/components/cropper.tsx +3 -12
  69. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +8 -8
  70. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +17 -15
  71. package/src/image-editor/react/components/test/cropper.tsx +17 -17
  72. package/src/image-editor/react/hooks/test/use-aria-announcer.ts +413 -5
  73. package/src/image-editor/react/hooks/use-aria-announcer.ts +120 -47
  74. package/tsconfig.json +1 -0
  75. package/tsconfig.tsbuildinfo +1 -1
@@ -165,7 +165,7 @@ describe( 'Cropper', () => {
165
165
 
166
166
  const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
167
167
  const handle = await screen.findByRole( 'button', {
168
- name: 'Resize top-left corner',
168
+ name: 'Resize from top-left corner',
169
169
  } );
170
170
 
171
171
  fireEvent.blur( canvas, { relatedTarget: handle } );
@@ -192,7 +192,7 @@ describe( 'Cropper', () => {
192
192
 
193
193
  const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
194
194
  const handle = await screen.findByRole( 'button', {
195
- name: 'Resize top-left corner',
195
+ name: 'Resize from top-left corner',
196
196
  } );
197
197
  const focusVisibleClass =
198
198
  'wp-media-editor-image-editor__canvas--focus-visible';
@@ -232,7 +232,7 @@ describe( 'Cropper', () => {
232
232
 
233
233
  const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
234
234
  const handle = await screen.findByRole( 'button', {
235
- name: 'Resize top-left corner',
235
+ name: 'Resize from top-left corner',
236
236
  } );
237
237
 
238
238
  act( () => {
@@ -294,7 +294,7 @@ describe( 'Cropper', () => {
294
294
  );
295
295
 
296
296
  await screen.findByRole( 'button', {
297
- name: 'Resize top-left corner',
297
+ name: 'Resize from top-left corner',
298
298
  } );
299
299
  ( controller.setCropRect as jest.Mock ).mockClear();
300
300
  ( controller.adjustCropRectForViewport as jest.Mock ).mockClear();
@@ -310,7 +310,7 @@ describe( 'Cropper', () => {
310
310
 
311
311
  expect(
312
312
  screen.queryByRole( 'button', {
313
- name: 'Resize top-left corner',
313
+ name: 'Resize from top-left corner',
314
314
  } )
315
315
  ).not.toBeInTheDocument();
316
316
  expect( controller.setCropRect ).not.toHaveBeenCalled();
@@ -358,7 +358,7 @@ describe( 'Cropper', () => {
358
358
  );
359
359
 
360
360
  const handle = await screen.findByRole( 'button', {
361
- name: 'Resize top-left corner',
361
+ name: 'Resize from top-left corner',
362
362
  } );
363
363
  // The settle transition and viewport pan live on the stage, not the
364
364
  // canvas (which stays fixed so the root background is never exposed).
@@ -414,7 +414,7 @@ describe( 'Cropper', () => {
414
414
  );
415
415
 
416
416
  const handle = await screen.findByRole( 'button', {
417
- name: 'Resize top-left corner',
417
+ name: 'Resize from top-left corner',
418
418
  } );
419
419
  const stage = screen.getByTestId( 'cropper-stage' );
420
420
 
@@ -462,7 +462,7 @@ describe( 'Cropper', () => {
462
462
  );
463
463
 
464
464
  const handle = await screen.findByRole( 'button', {
465
- name: 'Resize top-left corner',
465
+ name: 'Resize from top-left corner',
466
466
  } );
467
467
  const stage = screen.getByTestId( 'cropper-stage' );
468
468
 
@@ -502,7 +502,7 @@ describe( 'Cropper', () => {
502
502
  );
503
503
 
504
504
  const handle = await screen.findByRole( 'button', {
505
- name: 'Resize top-left corner',
505
+ name: 'Resize from top-left corner',
506
506
  } );
507
507
  const stage = screen.getByTestId( 'cropper-stage' );
508
508
 
@@ -549,7 +549,7 @@ describe( 'Cropper', () => {
549
549
 
550
550
  // East handle (4th button clockwise: nw, n, ne, e).
551
551
  const eHandle = await screen.findByRole( 'button', {
552
- name: 'Resize right edge',
552
+ name: 'Resize from right edge',
553
553
  } );
554
554
  const stage = screen.getByTestId( 'cropper-stage' );
555
555
 
@@ -582,7 +582,7 @@ describe( 'Cropper', () => {
582
582
  );
583
583
 
584
584
  const resizeHandle = await screen.findByRole( 'button', {
585
- name: 'Resize top-left corner',
585
+ name: 'Resize from top-left corner',
586
586
  } );
587
587
  const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
588
588
 
@@ -622,7 +622,7 @@ describe( 'Cropper', () => {
622
622
  );
623
623
 
624
624
  await screen.findByRole( 'button', {
625
- name: 'Resize top-left corner',
625
+ name: 'Resize from top-left corner',
626
626
  } );
627
627
  const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
628
628
 
@@ -670,7 +670,7 @@ describe( 'Cropper', () => {
670
670
  );
671
671
 
672
672
  const resizeHandle = await screen.findByRole( 'button', {
673
- name: 'Resize top-left corner',
673
+ name: 'Resize from top-left corner',
674
674
  } );
675
675
  const canvas = screen.getByRole( 'group', {
676
676
  name: 'Crop area',
@@ -892,7 +892,7 @@ describe( 'Cropper', () => {
892
892
  expect( imageScale() ).toBeCloseTo( 2.4, 2 );
893
893
 
894
894
  const handle = await screen.findByRole( 'button', {
895
- name: 'Resize top-left corner',
895
+ name: 'Resize from top-left corner',
896
896
  } );
897
897
  fireEvent.pointerDown( handle, {
898
898
  button: 0,
@@ -926,7 +926,7 @@ describe( 'Cropper', () => {
926
926
  );
927
927
 
928
928
  const handle = await screen.findByRole( 'button', {
929
- name: 'Resize right edge',
929
+ name: 'Resize from right edge',
930
930
  } );
931
931
  fireEvent.keyDown( handle, { key: 'ArrowRight' } );
932
932
 
@@ -968,7 +968,7 @@ describe( 'Cropper', () => {
968
968
  );
969
969
 
970
970
  const handle = await screen.findByRole( 'button', {
971
- name: 'Resize right edge',
971
+ name: 'Resize from right edge',
972
972
  } );
973
973
  ( controller.setCropRect as jest.Mock ).mockClear();
974
974
  fireEvent.keyDown( handle, { key: 'ArrowRight' } );
@@ -1003,7 +1003,7 @@ describe( 'Cropper', () => {
1003
1003
  );
1004
1004
 
1005
1005
  const handle = await screen.findByRole( 'button', {
1006
- name: 'Resize right edge',
1006
+ name: 'Resize from right edge',
1007
1007
  } );
1008
1008
  fireEvent.keyDown( handle, { key: 'ArrowRight' } );
1009
1009
 
@@ -3,6 +3,11 @@
3
3
  */
4
4
  import { act, renderHook } from '@testing-library/react';
5
5
 
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { speak } from '@wordpress/a11y';
10
+
6
11
  /**
7
12
  * Internal dependencies
8
13
  */
@@ -10,6 +15,10 @@ import { useAriaAnnouncer } from '../use-aria-announcer';
10
15
  import { DEFAULT_STATE } from '../../../core/constants';
11
16
  import type { CropperState } from '../../../core/types';
12
17
 
18
+ jest.mock( '@wordpress/a11y', () => ( {
19
+ speak: jest.fn(),
20
+ } ) );
21
+
13
22
  function makeState( overrides: Partial< CropperState > = {} ): CropperState {
14
23
  return {
15
24
  ...DEFAULT_STATE,
@@ -28,6 +37,7 @@ function makeState( overrides: Partial< CropperState > = {} ): CropperState {
28
37
  describe( 'useAriaAnnouncer', () => {
29
38
  beforeEach( () => {
30
39
  jest.useFakeTimers();
40
+ ( speak as jest.Mock ).mockClear();
31
41
  } );
32
42
 
33
43
  afterEach( () => {
@@ -35,7 +45,7 @@ describe( 'useAriaAnnouncer', () => {
35
45
  } );
36
46
 
37
47
  it( 'announces horizontal flip changes', () => {
38
- const { result, rerender } = renderHook(
48
+ const { rerender } = renderHook(
39
49
  ( { state } ) => useAriaAnnouncer( state ),
40
50
  { initialProps: { state: makeState() } }
41
51
  );
@@ -49,7 +59,7 @@ describe( 'useAriaAnnouncer', () => {
49
59
  } );
50
60
  act( () => jest.advanceTimersByTime( 300 ) );
51
61
 
52
- expect( result.current ).toBe( 'Flipped horizontally' );
62
+ expect( speak ).toHaveBeenCalledWith( 'Flipped horizontally' );
53
63
 
54
64
  rerender( {
55
65
  state: makeState( {
@@ -58,24 +68,422 @@ describe( 'useAriaAnnouncer', () => {
58
68
  } );
59
69
  act( () => jest.advanceTimersByTime( 300 ) );
60
70
 
61
- expect( result.current ).toBe( 'Flip removed' );
71
+ expect( speak ).toHaveBeenCalledWith( 'Flip removed' );
62
72
  } );
63
73
 
64
74
  it( 'announces combined flip state when both axes are active', () => {
65
- const { result, rerender } = renderHook(
75
+ const { rerender } = renderHook(
76
+ ( { state } ) => useAriaAnnouncer( state ),
77
+ { initialProps: { state: makeState() } }
78
+ );
79
+
80
+ act( () => jest.advanceTimersByTime( 300 ) );
81
+
82
+ rerender( {
83
+ state: makeState( {
84
+ flip: { horizontal: true, vertical: true },
85
+ } ),
86
+ } );
87
+ act( () => jest.advanceTimersByTime( 300 ) );
88
+
89
+ expect( speak ).toHaveBeenCalledWith(
90
+ 'Flipped horizontally and vertically'
91
+ );
92
+ } );
93
+
94
+ it( 'announces crop in pixels when image dimensions are available', () => {
95
+ const image = {
96
+ src: 'test.jpg',
97
+ naturalWidth: 1000,
98
+ naturalHeight: 800,
99
+ };
100
+ const { rerender } = renderHook(
101
+ ( { state } ) => useAriaAnnouncer( state ),
102
+ { initialProps: { state: makeState( { image } ) } }
103
+ );
104
+
105
+ act( () => jest.advanceTimersByTime( 300 ) );
106
+
107
+ rerender( {
108
+ state: makeState( {
109
+ image,
110
+ cropRect: { x: 0, y: 0, width: 0.8, height: 0.5 },
111
+ } ),
112
+ } );
113
+ act( () => jest.advanceTimersByTime( 300 ) );
114
+
115
+ expect( speak ).toHaveBeenCalledWith( 'Crop 800 by 400 pixels' );
116
+ } );
117
+
118
+ it( 'announces a single-pixel crop change', () => {
119
+ const image = {
120
+ src: 'test.jpg',
121
+ naturalWidth: 2000,
122
+ naturalHeight: 1000,
123
+ };
124
+ const { rerender } = renderHook(
125
+ ( { state } ) => useAriaAnnouncer( state ),
126
+ {
127
+ initialProps: {
128
+ state: makeState( {
129
+ image,
130
+ cropRect: { x: 0, y: 0, width: 0.5, height: 0.5 },
131
+ } ),
132
+ },
133
+ }
134
+ );
135
+
136
+ act( () => jest.advanceTimersByTime( 300 ) );
137
+
138
+ // 0.5 → 0.5005 of a 2000px-wide image is a one-pixel change (1000 →
139
+ // 1001), well under the old ~0.5% percentage threshold.
140
+ rerender( {
141
+ state: makeState( {
142
+ image,
143
+ cropRect: { x: 0, y: 0, width: 0.5005, height: 0.5 },
144
+ } ),
145
+ } );
146
+ act( () => jest.advanceTimersByTime( 300 ) );
147
+
148
+ expect( speak ).toHaveBeenCalledWith( 'Crop 1001 by 500 pixels' );
149
+ } );
150
+
151
+ it( 'does not announce the crop when only zoom changes', () => {
152
+ const image = {
153
+ src: 'test.jpg',
154
+ naturalWidth: 2000,
155
+ naturalHeight: 1000,
156
+ };
157
+ const { rerender } = renderHook(
158
+ ( { state } ) => useAriaAnnouncer( state ),
159
+ {
160
+ initialProps: {
161
+ state: makeState( {
162
+ image,
163
+ cropRect: { x: 0, y: 0, width: 0.5, height: 0.5 },
164
+ } ),
165
+ },
166
+ }
167
+ );
168
+
169
+ act( () => jest.advanceTimersByTime( 300 ) );
170
+
171
+ rerender( {
172
+ state: makeState( {
173
+ image,
174
+ cropRect: { x: 0, y: 0, width: 0.5, height: 0.5 },
175
+ zoom: 1.5,
176
+ } ),
177
+ } );
178
+ act( () => jest.advanceTimersByTime( 300 ) );
179
+
180
+ expect( speak ).toHaveBeenCalledWith( 'Zoom 150%' );
181
+ } );
182
+
183
+ it( 'announces a single-pixel crop change on a rotated non-square image', () => {
184
+ // Portrait image rotated 90°: the announced width scales by the
185
+ // snap-rotation bbox (2000), not naturalWidth (800), so a one-pixel
186
+ // change is 0.0005 of the crop rect — below a naturalWidth-based guard.
187
+ const image = {
188
+ src: 'test.jpg',
189
+ naturalWidth: 800,
190
+ naturalHeight: 2000,
191
+ };
192
+ const { rerender } = renderHook(
193
+ ( { state } ) => useAriaAnnouncer( state ),
194
+ {
195
+ initialProps: {
196
+ state: makeState( {
197
+ image,
198
+ rotation: 90,
199
+ cropRect: { x: 0, y: 0, width: 0.5, height: 0.5 },
200
+ } ),
201
+ },
202
+ }
203
+ );
204
+
205
+ act( () => jest.advanceTimersByTime( 300 ) );
206
+
207
+ rerender( {
208
+ state: makeState( {
209
+ image,
210
+ rotation: 90,
211
+ cropRect: { x: 0, y: 0, width: 0.5005, height: 0.5 },
212
+ } ),
213
+ } );
214
+ act( () => jest.advanceTimersByTime( 300 ) );
215
+
216
+ expect( speak ).toHaveBeenCalledWith( 'Crop 1001 by 400 pixels' );
217
+ } );
218
+
219
+ it( 'announces clockwise rotation with direction', () => {
220
+ const { rerender } = renderHook(
66
221
  ( { state } ) => useAriaAnnouncer( state ),
67
222
  { initialProps: { state: makeState() } }
68
223
  );
69
224
 
70
225
  act( () => jest.advanceTimersByTime( 300 ) );
71
226
 
227
+ rerender( {
228
+ state: makeState( { rotation: 15 } ),
229
+ } );
230
+ act( () => jest.advanceTimersByTime( 300 ) );
231
+
232
+ expect( speak ).toHaveBeenCalledWith( 'Rotated 15 degrees clockwise' );
233
+ } );
234
+
235
+ it( 'announces counterclockwise when flip inverts visual direction', () => {
236
+ const { rerender } = renderHook(
237
+ ( { state } ) => useAriaAnnouncer( state ),
238
+ {
239
+ initialProps: {
240
+ state: makeState( {
241
+ flip: { horizontal: true, vertical: false },
242
+ } ),
243
+ },
244
+ }
245
+ );
246
+
247
+ act( () => jest.advanceTimersByTime( 300 ) );
248
+
249
+ // With a single-axis flip, rotation 10 appears as -10 visually.
250
+ rerender( {
251
+ state: makeState( {
252
+ rotation: 10,
253
+ flip: { horizontal: true, vertical: false },
254
+ } ),
255
+ } );
256
+ act( () => jest.advanceTimersByTime( 300 ) );
257
+
258
+ expect( speak ).toHaveBeenCalledWith(
259
+ 'Rotated 10 degrees counterclockwise'
260
+ );
261
+ } );
262
+
263
+ it( 'announces a 90° snap under a single flip in visual terms', () => {
264
+ const { rerender } = renderHook(
265
+ ( { state } ) => useAriaAnnouncer( state ),
266
+ {
267
+ initialProps: {
268
+ state: makeState( {
269
+ flip: { horizontal: true, vertical: false },
270
+ } ),
271
+ },
272
+ }
273
+ );
274
+
275
+ act( () => jest.advanceTimersByTime( 300 ) );
276
+
277
+ // Flip horizontal, then rotate 90° clockwise: the reducer negates the
278
+ // visual direction for the field, so it stores 270 (normalized -90).
279
+ // Visually the user rotated 90° clockwise, so that's what we announce.
280
+ rerender( {
281
+ state: makeState( {
282
+ rotation: 270,
283
+ flip: { horizontal: true, vertical: false },
284
+ } ),
285
+ } );
286
+ act( () => jest.advanceTimersByTime( 300 ) );
287
+
288
+ expect( speak ).toHaveBeenCalledWith( 'Rotated 90 degrees clockwise' );
289
+ } );
290
+
291
+ it( 'announces a 90° snap under a vertical flip in visual terms', () => {
292
+ const { rerender } = renderHook(
293
+ ( { state } ) => useAriaAnnouncer( state ),
294
+ {
295
+ initialProps: {
296
+ state: makeState( {
297
+ flip: { horizontal: false, vertical: true },
298
+ } ),
299
+ },
300
+ }
301
+ );
302
+
303
+ act( () => jest.advanceTimersByTime( 300 ) );
304
+
72
305
  rerender( {
73
306
  state: makeState( {
307
+ rotation: 270,
308
+ flip: { horizontal: false, vertical: true },
309
+ } ),
310
+ } );
311
+ act( () => jest.advanceTimersByTime( 300 ) );
312
+
313
+ expect( speak ).toHaveBeenCalledWith( 'Rotated 90 degrees clockwise' );
314
+ } );
315
+
316
+ it( 'announces non-inverted rotation when both axes are flipped', () => {
317
+ // Two mirrors restore handedness (equivalent to a 180° rotation), so
318
+ // the visual direction matches the unflipped case, not the single-flip.
319
+ const { rerender } = renderHook(
320
+ ( { state } ) => useAriaAnnouncer( state ),
321
+ {
322
+ initialProps: {
323
+ state: makeState( {
324
+ flip: { horizontal: true, vertical: true },
325
+ } ),
326
+ },
327
+ }
328
+ );
329
+
330
+ act( () => jest.advanceTimersByTime( 300 ) );
331
+
332
+ rerender( {
333
+ state: makeState( {
334
+ rotation: 270,
74
335
  flip: { horizontal: true, vertical: true },
75
336
  } ),
76
337
  } );
77
338
  act( () => jest.advanceTimersByTime( 300 ) );
78
339
 
79
- expect( result.current ).toBe( 'Flipped horizontally and vertically' );
340
+ expect( speak ).toHaveBeenCalledWith(
341
+ 'Rotated 90 degrees counterclockwise'
342
+ );
343
+ } );
344
+
345
+ it( 'announces multiple changes with rotation first', () => {
346
+ const { rerender } = renderHook(
347
+ ( { state } ) => useAriaAnnouncer( state ),
348
+ { initialProps: { state: makeState() } }
349
+ );
350
+
351
+ act( () => jest.advanceTimersByTime( 300 ) );
352
+
353
+ rerender( {
354
+ state: makeState( { rotation: 90, zoom: 1.5 } ),
355
+ } );
356
+ act( () => jest.advanceTimersByTime( 300 ) );
357
+
358
+ expect( speak ).toHaveBeenCalledWith(
359
+ 'Rotated 90 degrees clockwise, Zoom 150%'
360
+ );
361
+ } );
362
+
363
+ it( 'announces rotation back to zero', () => {
364
+ const { rerender } = renderHook(
365
+ ( { state } ) => useAriaAnnouncer( state ),
366
+ { initialProps: { state: makeState( { rotation: 15 } ) } }
367
+ );
368
+
369
+ act( () => jest.advanceTimersByTime( 300 ) );
370
+
371
+ rerender( {
372
+ state: makeState( { rotation: 0 } ),
373
+ } );
374
+ act( () => jest.advanceTimersByTime( 300 ) );
375
+
376
+ expect( speak ).toHaveBeenCalledWith( 'Rotation 0 degrees' );
377
+ } );
378
+
379
+ it( 'announces rotation after 90° snap plus fine adjustment', () => {
380
+ const { rerender } = renderHook(
381
+ ( { state } ) => useAriaAnnouncer( state ),
382
+ { initialProps: { state: makeState() } }
383
+ );
384
+
385
+ act( () => jest.advanceTimersByTime( 300 ) );
386
+
387
+ // 90° CW snap + 15° fine = 105° stored.
388
+ rerender( {
389
+ state: makeState( { rotation: 105 } ),
390
+ } );
391
+ act( () => jest.advanceTimersByTime( 300 ) );
392
+
393
+ expect( speak ).toHaveBeenCalledWith( 'Rotated 105 degrees clockwise' );
394
+ } );
395
+
396
+ it( 'announces CCW for 90° snap CCW plus fine CCW adjustment', () => {
397
+ const { rerender } = renderHook(
398
+ ( { state } ) => useAriaAnnouncer( state ),
399
+ { initialProps: { state: makeState() } }
400
+ );
401
+
402
+ act( () => jest.advanceTimersByTime( 300 ) );
403
+
404
+ // 90° CCW snap (270°) + 15° CCW fine (255° stored).
405
+ // visualRotation = 255 → normalized to -105.
406
+ rerender( {
407
+ state: makeState( { rotation: 255 } ),
408
+ } );
409
+ act( () => jest.advanceTimersByTime( 300 ) );
410
+
411
+ expect( speak ).toHaveBeenCalledWith(
412
+ 'Rotated 105 degrees counterclockwise'
413
+ );
414
+ } );
415
+
416
+ it( 'announces CCW fine rotation from 0° (stored as 350°)', () => {
417
+ const { rerender } = renderHook(
418
+ ( { state } ) => useAriaAnnouncer( state ),
419
+ { initialProps: { state: makeState() } }
420
+ );
421
+
422
+ act( () => jest.advanceTimersByTime( 300 ) );
423
+
424
+ // -10° from 0° is stored as 350° after normalization.
425
+ // visualRotation = -10 → counterclockwise.
426
+ rerender( {
427
+ state: makeState( { rotation: 350 } ),
428
+ } );
429
+ act( () => jest.advanceTimersByTime( 300 ) );
430
+
431
+ expect( speak ).toHaveBeenCalledWith(
432
+ 'Rotated 10 degrees counterclockwise'
433
+ );
434
+ } );
435
+
436
+ it( 'suppresses unchanged values in combined announcements', () => {
437
+ const image = {
438
+ src: 'test.jpg',
439
+ naturalWidth: 1000,
440
+ naturalHeight: 800,
441
+ };
442
+ const { rerender } = renderHook(
443
+ ( { state } ) => useAriaAnnouncer( state ),
444
+ {
445
+ initialProps: {
446
+ state: makeState( { image, rotation: 15 } ),
447
+ },
448
+ }
449
+ );
450
+
451
+ act( () => jest.advanceTimersByTime( 300 ) );
452
+
453
+ ( speak as jest.Mock ).mockClear();
454
+
455
+ // Only change crop — zoom and rotation should be suppressed.
456
+ rerender( {
457
+ state: makeState( {
458
+ image,
459
+ rotation: 15,
460
+ cropRect: { x: 0, y: 0, width: 0.5, height: 0.5 },
461
+ } ),
462
+ } );
463
+ act( () => jest.advanceTimersByTime( 300 ) );
464
+
465
+ expect( speak ).toHaveBeenCalledWith( 'Crop 500 by 400 pixels' );
466
+ expect( speak ).not.toHaveBeenCalledWith(
467
+ expect.stringContaining( 'Zoom' )
468
+ );
469
+ expect( speak ).not.toHaveBeenCalledWith(
470
+ expect.stringContaining( 'Rotated' )
471
+ );
472
+ } );
473
+
474
+ it( 'announces only zoom when only zoom changes', () => {
475
+ const { rerender } = renderHook(
476
+ ( { state } ) => useAriaAnnouncer( state ),
477
+ { initialProps: { state: makeState() } }
478
+ );
479
+
480
+ act( () => jest.advanceTimersByTime( 300 ) );
481
+
482
+ rerender( {
483
+ state: makeState( { zoom: 1.5 } ),
484
+ } );
485
+ act( () => jest.advanceTimersByTime( 300 ) );
486
+
487
+ expect( speak ).toHaveBeenCalledWith( 'Zoom 150%' );
80
488
  } );
81
489
  } );