@wordpress/media-editor 0.8.0 → 0.8.1-next.v.202605131032.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 (217) hide show
  1. package/build/components/media-editor/index.cjs +560 -0
  2. package/build/components/media-editor/index.cjs.map +7 -0
  3. package/build/components/media-editor-canvas/index.cjs +14 -2
  4. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  5. package/build/components/media-editor-crop-panel/index.cjs +34 -27
  6. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  7. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
  8. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
  9. package/build/components/media-editor-modal/index.cjs +42 -430
  10. package/build/components/media-editor-modal/index.cjs.map +3 -3
  11. package/build/components/media-editor-toolbar/index.cjs +143 -75
  12. package/build/components/media-editor-toolbar/index.cjs.map +3 -3
  13. package/build/components/media-form/index.cjs +3 -0
  14. package/build/components/media-form/index.cjs.map +2 -2
  15. package/build/components/rotation-ruler/index.cjs +197 -0
  16. package/build/components/rotation-ruler/index.cjs.map +7 -0
  17. package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
  18. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
  19. package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
  20. package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
  21. package/build/image-editor/core/constants.cjs +9 -0
  22. package/build/image-editor/core/constants.cjs.map +2 -2
  23. package/build/image-editor/core/containment.cjs +7 -13
  24. package/build/image-editor/core/containment.cjs.map +2 -2
  25. package/build/image-editor/core/interaction-controller.cjs +43 -7
  26. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  27. package/build/image-editor/core/state.cjs +5 -1
  28. package/build/image-editor/core/state.cjs.map +2 -2
  29. package/build/image-editor/core/transform-style.cjs.map +1 -1
  30. package/build/image-editor/core/types.cjs.map +1 -1
  31. package/build/image-editor/core/viewport-state.cjs +50 -0
  32. package/build/image-editor/core/viewport-state.cjs.map +7 -0
  33. package/build/image-editor/react/components/cropper.cjs +192 -72
  34. package/build/image-editor/react/components/cropper.cjs.map +3 -3
  35. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
  36. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
  37. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +16 -4
  38. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  39. package/build/image-editor/react/components/viewport-provider.cjs +51 -0
  40. package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
  41. package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
  42. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
  43. package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
  44. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
  45. package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
  46. package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
  47. package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
  48. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
  49. package/build/image-editor/react/visually-hidden-style.cjs +41 -0
  50. package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
  51. package/build/private-apis.cjs +2 -0
  52. package/build/private-apis.cjs.map +2 -2
  53. package/build-module/components/media-editor/index.mjs +545 -0
  54. package/build-module/components/media-editor/index.mjs.map +7 -0
  55. package/build-module/components/media-editor-canvas/index.mjs +14 -2
  56. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  57. package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
  58. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  59. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
  60. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
  61. package/build-module/components/media-editor-modal/index.mjs +46 -455
  62. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  63. package/build-module/components/media-editor-toolbar/index.mjs +137 -77
  64. package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
  65. package/build-module/components/media-form/index.mjs +3 -0
  66. package/build-module/components/media-form/index.mjs.map +2 -2
  67. package/build-module/components/rotation-ruler/index.mjs +166 -0
  68. package/build-module/components/rotation-ruler/index.mjs.map +7 -0
  69. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
  70. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
  71. package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
  72. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
  73. package/build-module/image-editor/core/constants.mjs +6 -0
  74. package/build-module/image-editor/core/constants.mjs.map +2 -2
  75. package/build-module/image-editor/core/containment.mjs +6 -12
  76. package/build-module/image-editor/core/containment.mjs.map +2 -2
  77. package/build-module/image-editor/core/interaction-controller.mjs +50 -8
  78. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  79. package/build-module/image-editor/core/state.mjs +5 -1
  80. package/build-module/image-editor/core/state.mjs.map +2 -2
  81. package/build-module/image-editor/core/transform-style.mjs.map +1 -1
  82. package/build-module/image-editor/core/viewport-state.mjs +24 -0
  83. package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
  84. package/build-module/image-editor/react/components/cropper.mjs +195 -73
  85. package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
  86. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
  87. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
  88. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +26 -5
  89. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  90. package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
  91. package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
  92. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
  93. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
  94. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
  95. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
  96. package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
  97. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
  98. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
  99. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
  100. package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
  101. package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
  102. package/build-module/private-apis.mjs +2 -0
  103. package/build-module/private-apis.mjs.map +2 -2
  104. package/build-style/style-rtl.css +254 -29
  105. package/build-style/style.css +254 -29
  106. package/build-types/components/media-editor/index.d.ts +34 -0
  107. package/build-types/components/media-editor/index.d.ts.map +1 -0
  108. package/build-types/components/media-editor-canvas/index.d.ts +10 -1
  109. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  110. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  111. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  112. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
  113. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
  114. package/build-types/components/media-editor-modal/index.d.ts +2 -2
  115. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  116. package/build-types/components/media-editor-provider/index.d.ts +1 -1
  117. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  118. package/build-types/components/media-editor-toolbar/index.d.ts +4 -1
  119. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
  120. package/build-types/components/media-form/index.d.ts +1 -1
  121. package/build-types/components/media-form/index.d.ts.map +1 -1
  122. package/build-types/components/rotation-ruler/index.d.ts +46 -0
  123. package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
  124. package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
  125. package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
  126. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
  127. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
  128. package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
  129. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
  130. package/build-types/image-editor/core/constants.d.ts +9 -0
  131. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  132. package/build-types/image-editor/core/containment.d.ts +11 -7
  133. package/build-types/image-editor/core/containment.d.ts.map +1 -1
  134. package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
  135. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  136. package/build-types/image-editor/core/state.d.ts.map +1 -1
  137. package/build-types/image-editor/core/transform-style.d.ts +1 -1
  138. package/build-types/image-editor/core/types.d.ts +25 -0
  139. package/build-types/image-editor/core/types.d.ts.map +1 -1
  140. package/build-types/image-editor/core/viewport-state.d.ts +7 -0
  141. package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
  142. package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
  143. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  144. package/build-types/image-editor/react/components/cropper.d.ts +2 -1
  145. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  146. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +3 -13
  147. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
  148. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
  149. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
  150. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
  151. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  152. package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
  153. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
  154. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
  155. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +29 -0
  156. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
  157. package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
  158. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
  159. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
  160. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
  161. package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
  162. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
  163. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
  164. package/build-types/private-apis.d.ts.map +1 -1
  165. package/build-types/store/actions.d.ts +3 -3
  166. package/build-types/store/actions.d.ts.map +1 -1
  167. package/package.json +16 -15
  168. package/src/components/media-editor/index.tsx +709 -0
  169. package/src/components/media-editor/style.scss +89 -0
  170. package/src/components/media-editor-canvas/index.tsx +24 -0
  171. package/src/components/media-editor-crop-panel/index.tsx +39 -27
  172. package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
  173. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
  174. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
  175. package/src/components/media-editor-modal/index.tsx +49 -589
  176. package/src/components/media-editor-modal/style.scss +13 -112
  177. package/src/components/media-editor-toolbar/index.tsx +122 -63
  178. package/src/components/media-editor-toolbar/style.scss +39 -11
  179. package/src/components/media-form/index.tsx +5 -0
  180. package/src/components/rotation-ruler/README.md +37 -0
  181. package/src/components/rotation-ruler/index.tsx +266 -0
  182. package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
  183. package/src/components/rotation-ruler/style.scss +147 -0
  184. package/src/components/rotation-ruler/test/index.tsx +109 -0
  185. package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
  186. package/src/hooks/use-crop-gesture-handlers.ts +54 -0
  187. package/src/image-editor/core/constants.ts +12 -0
  188. package/src/image-editor/core/containment.ts +16 -28
  189. package/src/image-editor/core/interaction-controller.ts +66 -10
  190. package/src/image-editor/core/state.ts +15 -8
  191. package/src/image-editor/core/test/camera.ts +15 -26
  192. package/src/image-editor/core/test/interaction-controller.ts +158 -7
  193. package/src/image-editor/core/test/state.ts +21 -1
  194. package/src/image-editor/core/transform-style.ts +1 -1
  195. package/src/image-editor/core/types.ts +16 -0
  196. package/src/image-editor/core/viewport-state.ts +33 -0
  197. package/src/image-editor/docs/architecture.md +1 -1
  198. package/src/image-editor/docs/recipes.md +2 -2
  199. package/src/image-editor/react/components/cropper.scss +28 -0
  200. package/src/image-editor/react/components/cropper.tsx +268 -72
  201. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
  202. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
  203. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
  204. package/src/image-editor/react/components/test/cropper.tsx +294 -5
  205. package/src/image-editor/react/components/viewport-provider.tsx +39 -0
  206. package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
  207. package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
  208. package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
  209. package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
  210. package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
  211. package/src/image-editor/react/hooks/use-interaction.ts +36 -6
  212. package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
  213. package/src/image-editor/react/visually-hidden-style.ts +15 -0
  214. package/src/private-apis.ts +2 -0
  215. package/src/style.scss +3 -0
  216. package/tsconfig.json +1 -0
  217. package/tsconfig.tsbuildinfo +1 -1
@@ -6,7 +6,12 @@ import {
6
6
  type CropperInteractionActions,
7
7
  } from '../interaction-controller';
8
8
  import type { CropperState, Size } from '../types';
9
- import { DEFAULT_STATE, MIN_ZOOM, MAX_ZOOM } from '../constants';
9
+ import {
10
+ DEFAULT_STATE,
11
+ DEFAULT_WHEEL_ZOOM_SPEED,
12
+ MIN_ZOOM,
13
+ MAX_ZOOM,
14
+ } from '../constants';
10
15
 
11
16
  // The test environment is Node (not jsdom), so DOM globals like HTMLElement
12
17
  // and Element are not available. Provide minimal stubs so that `instanceof`
@@ -232,6 +237,7 @@ describe( 'InteractionController', () => {
232
237
  setZoom: jest.fn(),
233
238
  setZoomAtPoint: jest.fn(),
234
239
  snapRotate90: jest.fn(),
240
+ toggleFlip: jest.fn(),
235
241
  };
236
242
  } );
237
243
 
@@ -379,8 +385,10 @@ describe( 'InteractionController', () => {
379
385
  expect( actionMocks.setZoom ).toHaveBeenCalled();
380
386
 
381
387
  const setZoomCall = actionMocks.setZoom.mock.calls[ 0 ];
382
- // deltaY=-100, zoomSpeed=0.01, delta = 1, newZoom = 2+1 = 3.
383
- expect( setZoomCall![ 0 ] ).toBe( 3 );
388
+ // deltaY=-100, default zoomSpeed = 0.0025, delta = 0.25.
389
+ expect( setZoomCall![ 0 ] ).toBeCloseTo(
390
+ 2 + 100 * DEFAULT_WHEEL_ZOOM_SPEED
391
+ );
384
392
  } );
385
393
 
386
394
  it( 'calls setZoomAtPoint on wheel with currentTarget element', () => {
@@ -409,7 +417,9 @@ describe( 'InteractionController', () => {
409
417
  );
410
418
 
411
419
  expect( actionMocks.setZoomAtPoint ).toHaveBeenCalled();
412
- expect( actionMocks.setZoomAtPoint.mock.calls[ 0 ][ 0 ] ).toBe( 3 );
420
+ expect(
421
+ actionMocks.setZoomAtPoint.mock.calls[ 0 ][ 0 ]
422
+ ).toBeCloseTo( 2 + 100 * DEFAULT_WHEEL_ZOOM_SPEED );
413
423
  } );
414
424
 
415
425
  it( 'clamps to maxZoom on large positive wheel', () => {
@@ -421,7 +431,7 @@ describe( 'InteractionController', () => {
421
431
  );
422
432
 
423
433
  const setZoomCall = actionMocks.setZoom.mock.calls[ 0 ];
424
- // 9 + 5 = 14, clamped to MAX_ZOOM (10).
434
+ // 9 + 1.25 = 10.25, clamped to MAX_ZOOM (10).
425
435
  expect( setZoomCall![ 0 ] ).toBe( MAX_ZOOM );
426
436
  } );
427
437
 
@@ -434,7 +444,7 @@ describe( 'InteractionController', () => {
434
444
  );
435
445
 
436
446
  const setZoomCall = actionMocks.setZoom.mock.calls[ 0 ];
437
- // 2 + (-5) = -3, clamped to MIN_ZOOM (1).
447
+ // 2 + (-1.25) = 0.75, clamped to MIN_ZOOM (1).
438
448
  expect( setZoomCall![ 0 ] ).toBe( MIN_ZOOM );
439
449
  } );
440
450
 
@@ -456,6 +466,31 @@ describe( 'InteractionController', () => {
456
466
  expect( setZoomCall![ 0 ] ).toBe( 4 );
457
467
  } );
458
468
 
469
+ it( 'does not zoom while pointer pan is active', () => {
470
+ const state = makeState( { zoom: 2 } );
471
+ const { controller } = createController( state );
472
+ const el = createMockElement();
473
+
474
+ controller.handlePointerDown(
475
+ createPointerEvent( { clientX: 100, clientY: 100 } ),
476
+ el
477
+ );
478
+
479
+ jest.clearAllMocks();
480
+
481
+ const wheelEvent = createWheelEvent( {
482
+ deltaY: -100,
483
+ currentTarget: null,
484
+ } );
485
+ controller.handleWheel( wheelEvent );
486
+
487
+ expect( wheelEvent.preventDefault ).toHaveBeenCalled();
488
+ expect( actionMocks.setZoom ).not.toHaveBeenCalled();
489
+ expect( actionMocks.setZoomAtPoint ).not.toHaveBeenCalled();
490
+
491
+ el._fire( 'pointerup', createPointerEvent() );
492
+ } );
493
+
459
494
  it( 'calls onGestureStart on first wheel, onGestureEnd after debounce', () => {
460
495
  jest.useFakeTimers( {
461
496
  doNotFake: [ 'requestAnimationFrame', 'cancelAnimationFrame' ],
@@ -577,7 +612,18 @@ describe( 'InteractionController', () => {
577
612
  expect( actionMocks.snapRotate90 ).toHaveBeenCalledWith( 1 );
578
613
  } );
579
614
 
580
- it.each( [ 'metaKey', 'ctrlKey', 'altKey', 'shiftKey' ] )(
615
+ it( 'calls snapRotate90 counter-clockwise on shift+r', () => {
616
+ const state = makeState( { rotation: 0 } );
617
+ const { controller } = createController( state );
618
+
619
+ controller.handleKeyDown(
620
+ createKeyboardEvent( 'r', { shiftKey: true } )
621
+ );
622
+
623
+ expect( actionMocks.snapRotate90 ).toHaveBeenCalledWith( -1 );
624
+ } );
625
+
626
+ it.each( [ 'metaKey', 'ctrlKey', 'altKey' ] )(
581
627
  'does not rotate when %s is held with r',
582
628
  ( modifier ) => {
583
629
  const state = makeState( { rotation: 0 } );
@@ -594,6 +640,74 @@ describe( 'InteractionController', () => {
594
640
  }
595
641
  );
596
642
 
643
+ it( 'calls flip horizontal on h key', () => {
644
+ const state = makeState();
645
+ const { controller } = createController( state );
646
+
647
+ controller.handleKeyDown( createKeyboardEvent( 'h' ) );
648
+
649
+ expect( actionMocks.toggleFlip ).toHaveBeenCalledWith(
650
+ 'horizontal'
651
+ );
652
+ } );
653
+
654
+ it( 'calls flip horizontal on H key', () => {
655
+ const state = makeState();
656
+ const { controller } = createController( state );
657
+
658
+ controller.handleKeyDown( createKeyboardEvent( 'H' ) );
659
+
660
+ expect( actionMocks.toggleFlip ).toHaveBeenCalledWith(
661
+ 'horizontal'
662
+ );
663
+ } );
664
+
665
+ it( 'calls flip vertical on v key', () => {
666
+ const state = makeState();
667
+ const { controller } = createController( state );
668
+
669
+ controller.handleKeyDown( createKeyboardEvent( 'v' ) );
670
+
671
+ expect( actionMocks.toggleFlip ).toHaveBeenCalledWith( 'vertical' );
672
+ } );
673
+
674
+ it( 'calls flip vertical on V key', () => {
675
+ const state = makeState();
676
+ const { controller } = createController( state );
677
+
678
+ controller.handleKeyDown( createKeyboardEvent( 'V' ) );
679
+
680
+ expect( actionMocks.toggleFlip ).toHaveBeenCalledWith( 'vertical' );
681
+ } );
682
+
683
+ it.each( [ 'metaKey', 'ctrlKey', 'altKey', 'shiftKey' ] )(
684
+ 'does not flip when %s is held with h',
685
+ ( modifier ) => {
686
+ const state = makeState();
687
+ const { controller } = createController( state );
688
+
689
+ controller.handleKeyDown(
690
+ createKeyboardEvent( 'h', { [ modifier ]: true } )
691
+ );
692
+
693
+ expect( actionMocks.toggleFlip ).not.toHaveBeenCalled();
694
+ }
695
+ );
696
+
697
+ it.each( [ 'metaKey', 'ctrlKey', 'altKey', 'shiftKey' ] )(
698
+ 'does not flip when %s is held with v',
699
+ ( modifier ) => {
700
+ const state = makeState();
701
+ const { controller } = createController( state );
702
+
703
+ controller.handleKeyDown(
704
+ createKeyboardEvent( 'v', { [ modifier ]: true } )
705
+ );
706
+
707
+ expect( actionMocks.toggleFlip ).not.toHaveBeenCalled();
708
+ }
709
+ );
710
+
597
711
  it( 'respects custom keyboardStep (read lazily)', () => {
598
712
  const state = makeState( { zoom: 2 } );
599
713
  const { controller, opts } = createController( state, {
@@ -611,6 +725,42 @@ describe( 'InteractionController', () => {
611
725
  expect( call![ 0 ].x ).toBeCloseTo( -0.1 );
612
726
  } );
613
727
 
728
+ it( 'uses fine keyboardStep by default for arrow key panning', () => {
729
+ const state = makeState( { zoom: 2 } );
730
+ const { controller } = createController( state );
731
+
732
+ controller.handleKeyDown( createKeyboardEvent( 'ArrowRight' ) );
733
+
734
+ const call = actionMocks.setPan.mock.calls[ 0 ];
735
+ expect( call![ 0 ].x ).toBeCloseTo( -0.01 );
736
+ } );
737
+
738
+ it( 'uses a 10x larger keyboardStep when Shift is held while panning', () => {
739
+ const state = makeState( { zoom: 2 } );
740
+ const { controller } = createController( state );
741
+
742
+ controller.handleKeyDown(
743
+ createKeyboardEvent( 'ArrowRight', { shiftKey: true } )
744
+ );
745
+
746
+ const call = actionMocks.setPan.mock.calls[ 0 ];
747
+ expect( call![ 0 ].x ).toBeCloseTo( -0.1 );
748
+ } );
749
+
750
+ it( 'applies the Shift multiplier to custom keyboardStep while panning', () => {
751
+ const state = makeState( { zoom: 2 } );
752
+ const { controller } = createController( state, {
753
+ keyboardStep: 0.02,
754
+ } );
755
+
756
+ controller.handleKeyDown(
757
+ createKeyboardEvent( 'ArrowRight', { shiftKey: true } )
758
+ );
759
+
760
+ const call = actionMocks.setPan.mock.calls[ 0 ];
761
+ expect( call![ 0 ].x ).toBeCloseTo( -0.2 );
762
+ } );
763
+
614
764
  it( 'does not dispatch on unhandled keys', () => {
615
765
  const state = makeState();
616
766
  const { controller } = createController( state );
@@ -621,6 +771,7 @@ describe( 'InteractionController', () => {
621
771
  expect( actionMocks.setZoom ).not.toHaveBeenCalled();
622
772
  expect( actionMocks.setZoomAtPoint ).not.toHaveBeenCalled();
623
773
  expect( actionMocks.snapRotate90 ).not.toHaveBeenCalled();
774
+ expect( actionMocks.toggleFlip ).not.toHaveBeenCalled();
624
775
  } );
625
776
  } );
626
777
 
@@ -1,6 +1,6 @@
1
1
  import type { CropperState, Size } from '../types';
2
2
  import { DEFAULT_STATE } from '../constants';
3
- import { cropperReducer, enforceContainment } from '../state';
3
+ import { cropperReducer, enforceContainment, isStateDirty } from '../state';
4
4
  import {
5
5
  createCamera,
6
6
  screenToWorld,
@@ -126,6 +126,26 @@ describe( 'enforceContainment', () => {
126
126
  } );
127
127
  } );
128
128
 
129
+ describe( 'isStateDirty', () => {
130
+ it( 'ignores floating-point noise from containment math', () => {
131
+ const initial = makeState();
132
+ const current = makeState( {
133
+ pan: { x: initial.pan.x, y: initial.pan.y + 2e-8 },
134
+ } );
135
+
136
+ expect( isStateDirty( current, initial ) ).toBe( false );
137
+ } );
138
+
139
+ it( 'detects visible cropper state changes', () => {
140
+ const initial = makeState();
141
+ const current = makeState( {
142
+ pan: { x: initial.pan.x, y: initial.pan.y + 0.01 },
143
+ } );
144
+
145
+ expect( isStateDirty( current, initial ) ).toBe( true );
146
+ } );
147
+ } );
148
+
129
149
  describe( 'cropperReducer — SETTLE_CROP', () => {
130
150
  /**
131
151
  * Assert that the world-space region visible through the crop is
@@ -12,7 +12,7 @@ import { degreesToRadians } from './math/rotation';
12
12
  *
13
13
  * Flip is composed outside rotation so it is viewport-relative — horizontal
14
14
  * flip mirrors across the viewport's vertical axis regardless of rotation.
15
- * Must match the matrix order in `createCamera` / `getCropBounds`.
15
+ * Must match the matrix order in `createCamera` / `getImageCropBounds`.
16
16
  *
17
17
  * This is a pure function with no framework dependencies. The React hook
18
18
  * `useTransformStyle` wraps this in `useMemo` for memoization.
@@ -142,6 +142,22 @@ export type CropperAction =
142
142
  /** Resets to DEFAULT_STATE, optionally merging a partial override. */
143
143
  | { type: 'RESET'; payload?: Partial< CropperState > };
144
144
 
145
+ /**
146
+ * Viewport camera state — display-only, does not affect export or undo.
147
+ *
148
+ * Applied as a CSS transform on the inner stage div so the user can scroll
149
+ * the view independently of the crop. zoom > 1 magnifies; pan shifts in CSS px.
150
+ */
151
+ export interface ViewportState {
152
+ zoom: number;
153
+ pan: { x: number; y: number };
154
+ }
155
+
156
+ export type ViewportAction =
157
+ | { type: 'SET_VIEWPORT_ZOOM'; payload: number }
158
+ | { type: 'SET_VIEWPORT_PAN'; payload: { x: number; y: number } }
159
+ | { type: 'RESET_VIEWPORT' };
160
+
145
161
  /**
146
162
  * The contract for a pluggable stencil component.
147
163
  * Stencils render the crop area overlay and handle resize interactions.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { ViewportState, ViewportAction } from './types';
5
+
6
+ export const DEFAULT_VIEWPORT_STATE: ViewportState = {
7
+ zoom: 1,
8
+ pan: { x: 0, y: 0 },
9
+ };
10
+
11
+ export function viewportReducer(
12
+ state: ViewportState,
13
+ action: ViewportAction
14
+ ): ViewportState {
15
+ switch ( action.type ) {
16
+ case 'SET_VIEWPORT_ZOOM': {
17
+ const zoom = Math.min( 4, Math.max( 0.1, action.payload ) );
18
+ return zoom === state.zoom ? state : { ...state, zoom };
19
+ }
20
+ case 'SET_VIEWPORT_PAN': {
21
+ const { x, y } = action.payload;
22
+ return x === state.pan.x && y === state.pan.y
23
+ ? state
24
+ : { ...state, pan: action.payload };
25
+ }
26
+ case 'RESET_VIEWPORT':
27
+ return state.zoom === DEFAULT_VIEWPORT_STATE.zoom &&
28
+ state.pan.x === DEFAULT_VIEWPORT_STATE.pan.x &&
29
+ state.pan.y === DEFAULT_VIEWPORT_STATE.pan.y
30
+ ? state
31
+ : DEFAULT_VIEWPORT_STATE;
32
+ }
33
+ }
@@ -32,7 +32,7 @@ graph TD
32
32
  restrictPanZoom["restrictPanZoom()\nbuilds camera → inverse → clamp"]
33
33
  restrictCropRect["restrictCropRect()"]
34
34
  getMinZoomForCover["getMinZoomForCover()"]
35
- getCropBounds["getCropBounds()"]
35
+ getImageCropBounds["getImageCropBounds()"]
36
36
  end
37
37
 
38
38
  subgraph Rendering["Render Path"]
@@ -647,10 +647,10 @@ function ImageEditorWithUndo( { src }: { src: string } ) {
647
647
  The cropper is keyboard-accessible and screen-reader friendly:
648
648
 
649
649
  **Keyboard controls:**
650
- - **Arrow keys** on the container: pan the image
650
+ - **Arrow keys** on the container: pan the image (Shift for larger jumps)
651
651
  - **+/-** on the container: zoom in/out
652
652
  - **R** on the container: snap rotate 90°
653
- - **Tab** to crop handles, then **arrow keys** to resize (0.02 step per keypress)
653
+ - **Tab** to crop handles, then **arrow keys** to resize (Shift for larger jumps)
654
654
  - Aspect ratio lock is respected during keyboard resize
655
655
 
656
656
  **Screen reader support:**
@@ -21,6 +21,19 @@ $handle-touch-target-size: 44px;
21
21
  &__canvas {
22
22
  position: absolute;
23
23
  inset: calc($handle-touch-target-size / 2);
24
+
25
+ // Suppress the browser's default focus ring — the crop rectangle
26
+ // border provides the custom keyboard-focus indicator instead.
27
+ &:focus {
28
+ outline: none;
29
+ }
30
+ }
31
+
32
+ // Inner stage — receives the viewport pan transform so the canvas div
33
+ // itself stays fixed, preventing the root background from showing through.
34
+ &__stage {
35
+ position: absolute;
36
+ inset: 0;
24
37
  }
25
38
 
26
39
  &--dragging {
@@ -71,6 +84,11 @@ $handle-touch-target-size: 44px;
71
84
  transition-delay: 0s;
72
85
  }
73
86
 
87
+ &__canvas--settling &__grid {
88
+ opacity: 0;
89
+ transition: none;
90
+ }
91
+
74
92
  &__grid-line {
75
93
  position: absolute;
76
94
  background: rgba(255, 255, 255, 0.4);
@@ -93,6 +111,16 @@ $handle-touch-target-size: 44px;
93
111
  border: 1px solid rgba(255, 255, 255, 0.7);
94
112
  box-sizing: border-box;
95
113
  pointer-events: none;
114
+ transition: border-color 0.15s ease, box-shadow 0.15s ease;
115
+ }
116
+
117
+ // Blue border on the crop rectangle when the canvas has keyboard focus.
118
+ // Uses a JS-controlled class rather than :focus-visible — browsers can
119
+ // restore :focus-visible across programmatic focus calls, making pure
120
+ // CSS unreliable for pointer-to-keyboard transitions.
121
+ &__canvas--focus-visible &__stencil-rect {
122
+ border-color: var(--wp-image-editor-focus-color, var(--wp-admin-theme-color, #007cba));
123
+ box-shadow: 0 0 0 1px var(--wp-image-editor-focus-color, var(--wp-admin-theme-color, #007cba));
96
124
  }
97
125
 
98
126
  &__handle {