@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.
- package/build/components/media-editor/index.cjs +560 -0
- package/build/components/media-editor/index.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +14 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +34 -27
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +42 -430
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-toolbar/index.cjs +143 -75
- package/build/components/media-editor-toolbar/index.cjs.map +3 -3
- package/build/components/media-form/index.cjs +3 -0
- package/build/components/media-form/index.cjs.map +2 -2
- package/build/components/rotation-ruler/index.cjs +197 -0
- package/build/components/rotation-ruler/index.cjs.map +7 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
- package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
- package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +9 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +7 -13
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs +43 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +5 -1
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs.map +1 -1
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/core/viewport-state.cjs +50 -0
- package/build/image-editor/core/viewport-state.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +192 -72
- package/build/image-editor/react/components/cropper.cjs.map +3 -3
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +16 -4
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/components/viewport-provider.cjs +51 -0
- package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
- package/build/image-editor/react/visually-hidden-style.cjs +41 -0
- package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
- package/build/private-apis.cjs +2 -0
- package/build/private-apis.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +545 -0
- package/build-module/components/media-editor/index.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +14 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +46 -455
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-toolbar/index.mjs +137 -77
- package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
- package/build-module/components/media-form/index.mjs +3 -0
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/index.mjs +166 -0
- package/build-module/components/rotation-ruler/index.mjs.map +7 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +6 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +6 -12
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs +50 -8
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +5 -1
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/core/viewport-state.mjs +24 -0
- package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +195 -73
- package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +26 -5
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
- package/build-module/private-apis.mjs +2 -0
- package/build-module/private-apis.mjs.map +2 -2
- package/build-style/style-rtl.css +254 -29
- package/build-style/style.css +254 -29
- package/build-types/components/media-editor/index.d.ts +34 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +10 -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-keyboard-shortcuts-modal/index.d.ts +6 -0
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +2 -2
- 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 +4 -1
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
- 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/rotation-ruler/index.d.ts +46 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +9 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +11 -7
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +25 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/core/viewport-state.d.ts +7 -0
- package/build-types/image-editor/core/viewport-state.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 +2 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +3 -13
- 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 +9 -0
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
- 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 +29 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +3 -3
- package/build-types/store/actions.d.ts.map +1 -1
- package/package.json +16 -15
- package/src/components/media-editor/index.tsx +709 -0
- package/src/components/media-editor/style.scss +89 -0
- package/src/components/media-editor-canvas/index.tsx +24 -0
- package/src/components/media-editor-crop-panel/index.tsx +39 -27
- package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
- package/src/components/media-editor-modal/index.tsx +49 -589
- package/src/components/media-editor-modal/style.scss +13 -112
- package/src/components/media-editor-toolbar/index.tsx +122 -63
- package/src/components/media-editor-toolbar/style.scss +39 -11
- package/src/components/media-form/index.tsx +5 -0
- package/src/components/rotation-ruler/README.md +37 -0
- package/src/components/rotation-ruler/index.tsx +266 -0
- package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
- package/src/components/rotation-ruler/style.scss +147 -0
- package/src/components/rotation-ruler/test/index.tsx +109 -0
- package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
- package/src/hooks/use-crop-gesture-handlers.ts +54 -0
- package/src/image-editor/core/constants.ts +12 -0
- package/src/image-editor/core/containment.ts +16 -28
- package/src/image-editor/core/interaction-controller.ts +66 -10
- package/src/image-editor/core/state.ts +15 -8
- package/src/image-editor/core/test/camera.ts +15 -26
- package/src/image-editor/core/test/interaction-controller.ts +158 -7
- package/src/image-editor/core/test/state.ts +21 -1
- package/src/image-editor/core/transform-style.ts +1 -1
- package/src/image-editor/core/types.ts +16 -0
- package/src/image-editor/core/viewport-state.ts +33 -0
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +2 -2
- package/src/image-editor/react/components/cropper.scss +28 -0
- package/src/image-editor/react/components/cropper.tsx +268 -72
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
- package/src/image-editor/react/components/test/cropper.tsx +294 -5
- package/src/image-editor/react/components/viewport-provider.tsx +39 -0
- package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
- package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
- package/src/image-editor/react/hooks/use-interaction.ts +36 -6
- package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
- package/src/image-editor/react/visually-hidden-style.ts +15 -0
- package/src/private-apis.ts +2 -0
- package/src/style.scss +3 -0
- package/tsconfig.json +1 -0
- 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 {
|
|
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.
|
|
383
|
-
expect( setZoomCall![ 0 ] ).
|
|
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(
|
|
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 +
|
|
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 + (-
|
|
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
|
|
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` / `
|
|
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
|
-
|
|
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 (
|
|
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 {
|