@wordpress/media-editor 0.11.1 → 0.11.2-next.v.202606191442.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.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +63 -15
- package/build/components/media-editor-canvas/index.cjs.map +3 -3
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +2 -2
- package/build/components/media-editor-image-controls/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +4 -4
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +1 -1
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/image-editor/core/camera.cjs +13 -0
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs +12 -3
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs.map +1 -1
- package/build/image-editor/core/crop-rect.cjs.map +1 -1
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -1
- package/build/image-editor/core/interaction-controller.cjs +9 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs.map +1 -1
- package/build/image-editor/core/setter-helpers.cjs.map +1 -1
- package/build/image-editor/core/source-region.cjs +111 -2
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs.map +1 -1
- package/build/image-editor/core/stencil-math.cjs +3 -4
- package/build/image-editor/core/stencil-math.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/react/components/cropper.cjs +232 -55
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +1 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +65 -19
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -1
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +1 -1
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -1
- package/build/index.cjs.map +1 -1
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +1 -1
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +55 -17
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +4 -4
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -1
- package/build-module/components/rotation-ruler/index.mjs +1 -1
- package/build-module/components/rotation-ruler/index.mjs.map +1 -1
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -1
- package/build-module/image-editor/core/camera.mjs +12 -0
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +8 -2
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs.map +1 -1
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -1
- package/build-module/image-editor/core/interaction-controller.mjs +9 -7
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -1
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -1
- package/build-module/image-editor/core/source-region.mjs +108 -1
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs.map +1 -1
- package/build-module/image-editor/core/stencil-math.mjs +3 -4
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/react/components/cropper.mjs +242 -57
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +1 -0
- 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 +65 -19
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -1
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +1 -1
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +1 -1
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-style/style-rtl.css +49 -6
- package/build-style/style.css +49 -6
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts +25 -1
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +20 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/source-region.d.ts +23 -1
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +10 -5
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/types.d.ts +14 -0
- package/build-types/image-editor/core/types.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/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +17 -14
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/package.json +25 -20
- package/src/components/media-editor/style.scss +21 -9
- package/src/components/media-editor-canvas/index.tsx +82 -13
- package/src/components/media-editor-canvas/style.scss +41 -0
- package/src/image-editor/core/camera.ts +60 -1
- package/src/image-editor/core/constants.ts +23 -1
- package/src/image-editor/core/interaction-controller.ts +25 -11
- package/src/image-editor/core/source-region.ts +202 -1
- package/src/image-editor/core/stencil-math.ts +23 -14
- package/src/image-editor/core/test/camera.ts +272 -1
- package/src/image-editor/core/test/interaction-controller.ts +100 -0
- package/src/image-editor/core/test/stencil-math.ts +120 -6
- package/src/image-editor/core/types.ts +17 -0
- package/src/image-editor/react/components/cropper.tsx +362 -72
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +1 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +101 -32
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +169 -17
- package/src/image-editor/react/components/test/cropper.tsx +689 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +0 -21
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -108
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import { Cropper } from '../cropper';
|
|
16
16
|
import type { CropperController } from '../../hooks/use-cropper-reducer';
|
|
17
17
|
import { DEFAULT_STATE } from '../../../core/constants';
|
|
18
|
+
import { getSourceRegion } from '../../../core/source-region';
|
|
18
19
|
|
|
19
20
|
const GRID_TEST_ID = 'cropper-grid';
|
|
20
21
|
const GRID_INTERACTIVE_CLASS =
|
|
@@ -65,9 +66,13 @@ describe( 'Cropper', () => {
|
|
|
65
66
|
MouseEvent
|
|
66
67
|
) {
|
|
67
68
|
pointerId: number;
|
|
69
|
+
pointerType: string;
|
|
70
|
+
isPrimary: boolean;
|
|
68
71
|
constructor( type: string, init: PointerEventInit = {} ) {
|
|
69
72
|
super( type, init );
|
|
70
73
|
this.pointerId = init.pointerId ?? 0;
|
|
74
|
+
this.pointerType = init.pointerType ?? '';
|
|
75
|
+
this.isPrimary = init.isPrimary ?? false;
|
|
71
76
|
}
|
|
72
77
|
};
|
|
73
78
|
}
|
|
@@ -340,7 +345,7 @@ describe( 'Cropper', () => {
|
|
|
340
345
|
);
|
|
341
346
|
} );
|
|
342
347
|
|
|
343
|
-
it( 'clears settling state when a new resize starts before the settle
|
|
348
|
+
it( 'clears settling state when a new resize starts before the settle fallback fires', async () => {
|
|
344
349
|
jest.useFakeTimers();
|
|
345
350
|
|
|
346
351
|
render(
|
|
@@ -371,7 +376,7 @@ describe( 'Cropper', () => {
|
|
|
371
376
|
// The settle transition should now be active on the stage.
|
|
372
377
|
expect( stage ).toHaveStyle( 'transition: transform 200ms ease-out' );
|
|
373
378
|
|
|
374
|
-
// Start a new resize before the
|
|
379
|
+
// Start a new resize before the settle fallback fires.
|
|
375
380
|
fireEvent.pointerDown( handle, {
|
|
376
381
|
button: 0,
|
|
377
382
|
clientX: 100,
|
|
@@ -384,15 +389,144 @@ describe( 'Cropper', () => {
|
|
|
384
389
|
'transition: transform 200ms ease-out'
|
|
385
390
|
);
|
|
386
391
|
|
|
387
|
-
// Advance past the old settle
|
|
392
|
+
// Advance past the old settle fallback; it was cancelled so the stage
|
|
388
393
|
// should still have no transition.
|
|
394
|
+
act( () => jest.advanceTimersByTime( 300 ) );
|
|
395
|
+
expect( stage ).not.toHaveStyle(
|
|
396
|
+
'transition: transform 200ms ease-out'
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
fireEvent.pointerUp( handle, { pointerId: 1 } );
|
|
400
|
+
|
|
401
|
+
jest.useRealTimers();
|
|
402
|
+
} );
|
|
403
|
+
|
|
404
|
+
it( 'keeps settling active until the settle transform transition ends', async () => {
|
|
405
|
+
jest.useFakeTimers();
|
|
406
|
+
|
|
407
|
+
render(
|
|
408
|
+
<Cropper
|
|
409
|
+
src="test.jpg"
|
|
410
|
+
controller={ createController() }
|
|
411
|
+
showDimming={ false }
|
|
412
|
+
freeformCrop
|
|
413
|
+
/>
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
const handle = await screen.findByRole( 'button', {
|
|
417
|
+
name: 'Resize top-left corner',
|
|
418
|
+
} );
|
|
419
|
+
const stage = screen.getByTestId( 'cropper-stage' );
|
|
420
|
+
|
|
421
|
+
fireEvent.pointerDown( handle, {
|
|
422
|
+
button: 0,
|
|
423
|
+
clientX: 100,
|
|
424
|
+
clientY: 100,
|
|
425
|
+
pointerId: 1,
|
|
426
|
+
} );
|
|
427
|
+
fireEvent.pointerUp( handle, { pointerId: 1 } );
|
|
428
|
+
|
|
429
|
+
expect( stage ).toHaveStyle( 'transition: transform 200ms ease-out' );
|
|
430
|
+
|
|
389
431
|
act( () => jest.advanceTimersByTime( 200 ) );
|
|
432
|
+
expect( stage ).toHaveStyle( 'transition: transform 200ms ease-out' );
|
|
433
|
+
|
|
434
|
+
// The transform transition runs on the image and bubbles up to the
|
|
435
|
+
// stage handler, so fire from the image to exercise the real path.
|
|
436
|
+
const image = screen.getByTestId( 'cropper-image' );
|
|
437
|
+
const transitionEndEvent = new Event( 'transitionend', {
|
|
438
|
+
bubbles: true,
|
|
439
|
+
} );
|
|
440
|
+
Object.defineProperty( transitionEndEvent, 'propertyName', {
|
|
441
|
+
value: 'transform',
|
|
442
|
+
} );
|
|
443
|
+
fireEvent( image, transitionEndEvent );
|
|
444
|
+
|
|
390
445
|
expect( stage ).not.toHaveStyle(
|
|
391
446
|
'transition: transform 200ms ease-out'
|
|
392
447
|
);
|
|
393
448
|
|
|
449
|
+
jest.useRealTimers();
|
|
450
|
+
} );
|
|
451
|
+
|
|
452
|
+
it( 'clears settling via the fallback timer when no transitionend fires', async () => {
|
|
453
|
+
jest.useFakeTimers();
|
|
454
|
+
|
|
455
|
+
render(
|
|
456
|
+
<Cropper
|
|
457
|
+
src="test.jpg"
|
|
458
|
+
controller={ createController() }
|
|
459
|
+
showDimming={ false }
|
|
460
|
+
freeformCrop
|
|
461
|
+
/>
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
const handle = await screen.findByRole( 'button', {
|
|
465
|
+
name: 'Resize top-left corner',
|
|
466
|
+
} );
|
|
467
|
+
const stage = screen.getByTestId( 'cropper-stage' );
|
|
468
|
+
|
|
469
|
+
fireEvent.pointerDown( handle, {
|
|
470
|
+
button: 0,
|
|
471
|
+
clientX: 100,
|
|
472
|
+
clientY: 100,
|
|
473
|
+
pointerId: 1,
|
|
474
|
+
} );
|
|
394
475
|
fireEvent.pointerUp( handle, { pointerId: 1 } );
|
|
395
476
|
|
|
477
|
+
expect( stage ).toHaveStyle( 'transition: transform 200ms ease-out' );
|
|
478
|
+
|
|
479
|
+
// Without a transitionend, settling persists past the CSS duration...
|
|
480
|
+
act( () => jest.advanceTimersByTime( 200 ) );
|
|
481
|
+
expect( stage ).toHaveStyle( 'transition: transform 200ms ease-out' );
|
|
482
|
+
|
|
483
|
+
// ...and is cleared by the fallback timer (CSS duration + 100ms).
|
|
484
|
+
act( () => jest.advanceTimersByTime( 100 ) );
|
|
485
|
+
expect( stage ).not.toHaveStyle(
|
|
486
|
+
'transition: transform 200ms ease-out'
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
jest.useRealTimers();
|
|
490
|
+
} );
|
|
491
|
+
|
|
492
|
+
it( 'ignores non-transform transitionend events while settling', async () => {
|
|
493
|
+
jest.useFakeTimers();
|
|
494
|
+
|
|
495
|
+
render(
|
|
496
|
+
<Cropper
|
|
497
|
+
src="test.jpg"
|
|
498
|
+
controller={ createController() }
|
|
499
|
+
showDimming={ false }
|
|
500
|
+
freeformCrop
|
|
501
|
+
/>
|
|
502
|
+
);
|
|
503
|
+
|
|
504
|
+
const handle = await screen.findByRole( 'button', {
|
|
505
|
+
name: 'Resize top-left corner',
|
|
506
|
+
} );
|
|
507
|
+
const stage = screen.getByTestId( 'cropper-stage' );
|
|
508
|
+
|
|
509
|
+
fireEvent.pointerDown( handle, {
|
|
510
|
+
button: 0,
|
|
511
|
+
clientX: 100,
|
|
512
|
+
clientY: 100,
|
|
513
|
+
pointerId: 1,
|
|
514
|
+
} );
|
|
515
|
+
fireEvent.pointerUp( handle, { pointerId: 1 } );
|
|
516
|
+
|
|
517
|
+
expect( stage ).toHaveStyle( 'transition: transform 200ms ease-out' );
|
|
518
|
+
|
|
519
|
+
// A stencil left/top/width/height transitionend must not clear settling.
|
|
520
|
+
const stencilTransitionEnd = new Event( 'transitionend', {
|
|
521
|
+
bubbles: true,
|
|
522
|
+
} );
|
|
523
|
+
Object.defineProperty( stencilTransitionEnd, 'propertyName', {
|
|
524
|
+
value: 'left',
|
|
525
|
+
} );
|
|
526
|
+
fireEvent( stage, stencilTransitionEnd );
|
|
527
|
+
|
|
528
|
+
expect( stage ).toHaveStyle( 'transition: transform 200ms ease-out' );
|
|
529
|
+
|
|
396
530
|
jest.useRealTimers();
|
|
397
531
|
} );
|
|
398
532
|
|
|
@@ -420,12 +554,18 @@ describe( 'Cropper', () => {
|
|
|
420
554
|
const stage = screen.getByTestId( 'cropper-stage' );
|
|
421
555
|
|
|
422
556
|
// cropRect starts at {x:0, y:0, width:1, height:1} (right edge = 1.0).
|
|
423
|
-
//
|
|
557
|
+
// Pixel snapping is active at zoom:2, so one ArrowRight step is one
|
|
558
|
+
// source pixel: zoom / sourceWidth = 2 / 600 normalized.
|
|
424
559
|
// With canvasSize=600×400 and visualSize=600×400:
|
|
425
|
-
// rightOverflow = 1
|
|
560
|
+
// rightOverflow = (1 + 2/600) * 600 − 600 = 2 → pan.x = −2
|
|
426
561
|
fireEvent.keyDown( eHandle, { key: 'ArrowRight' } );
|
|
427
562
|
|
|
428
|
-
|
|
563
|
+
const match = stage.style.transform.match(
|
|
564
|
+
/^translate\((-?\d+(?:\.\d+)?)px, (-?\d+(?:\.\d+)?)px\)$/
|
|
565
|
+
);
|
|
566
|
+
expect( match ).not.toBeNull();
|
|
567
|
+
expect( Number( match?.[ 1 ] ) ).toBeCloseTo( -2, 4 );
|
|
568
|
+
expect( Number( match?.[ 2 ] ) ).toBeCloseTo( 0, 5 );
|
|
429
569
|
|
|
430
570
|
jest.useRealTimers();
|
|
431
571
|
} );
|
|
@@ -468,4 +608,547 @@ describe( 'Cropper', () => {
|
|
|
468
608
|
|
|
469
609
|
fireEvent.pointerUp( resizeHandle, { pointerId: 1 } );
|
|
470
610
|
} );
|
|
611
|
+
|
|
612
|
+
it( 'does not start canvas drag from touch pointer events', async () => {
|
|
613
|
+
const controller = createController();
|
|
614
|
+
render(
|
|
615
|
+
<Cropper
|
|
616
|
+
src="test.jpg"
|
|
617
|
+
controller={ controller }
|
|
618
|
+
showDimming
|
|
619
|
+
showGrid="interactive"
|
|
620
|
+
freeformCrop
|
|
621
|
+
/>
|
|
622
|
+
);
|
|
623
|
+
|
|
624
|
+
await screen.findByRole( 'button', {
|
|
625
|
+
name: 'Resize top-left corner',
|
|
626
|
+
} );
|
|
627
|
+
const canvas = screen.getByRole( 'group', { name: 'Crop area' } );
|
|
628
|
+
|
|
629
|
+
fireEvent.pointerDown( canvas, {
|
|
630
|
+
button: 0,
|
|
631
|
+
clientX: 100,
|
|
632
|
+
clientY: 100,
|
|
633
|
+
pointerId: 1,
|
|
634
|
+
pointerType: 'touch',
|
|
635
|
+
isPrimary: true,
|
|
636
|
+
} );
|
|
637
|
+
fireEvent.pointerMove( canvas, {
|
|
638
|
+
button: 0,
|
|
639
|
+
clientX: 150,
|
|
640
|
+
clientY: 120,
|
|
641
|
+
pointerId: 1,
|
|
642
|
+
pointerType: 'touch',
|
|
643
|
+
isPrimary: true,
|
|
644
|
+
} );
|
|
645
|
+
|
|
646
|
+
expect( canvas ).not.toHaveClass( SHOW_GRID_CLASS );
|
|
647
|
+
expect( controller.setPan ).not.toHaveBeenCalled();
|
|
648
|
+
} );
|
|
649
|
+
|
|
650
|
+
it( 'cancels handle resize when a touch gesture becomes a pinch', async () => {
|
|
651
|
+
const originalRAF = globalThis.requestAnimationFrame;
|
|
652
|
+
const originalCAF = globalThis.cancelAnimationFrame;
|
|
653
|
+
globalThis.requestAnimationFrame = ( cb: FrameRequestCallback ) => {
|
|
654
|
+
cb( 0 );
|
|
655
|
+
return 0;
|
|
656
|
+
};
|
|
657
|
+
globalThis.cancelAnimationFrame = jest.fn();
|
|
658
|
+
|
|
659
|
+
try {
|
|
660
|
+
const controller = createController();
|
|
661
|
+
const onGestureEnd = jest.fn();
|
|
662
|
+
render(
|
|
663
|
+
<Cropper
|
|
664
|
+
src="test.jpg"
|
|
665
|
+
controller={ controller }
|
|
666
|
+
showDimming={ false }
|
|
667
|
+
freeformCrop
|
|
668
|
+
onGestureEnd={ onGestureEnd }
|
|
669
|
+
/>
|
|
670
|
+
);
|
|
671
|
+
|
|
672
|
+
const resizeHandle = await screen.findByRole( 'button', {
|
|
673
|
+
name: 'Resize top-left corner',
|
|
674
|
+
} );
|
|
675
|
+
const canvas = screen.getByRole( 'group', {
|
|
676
|
+
name: 'Crop area',
|
|
677
|
+
} );
|
|
678
|
+
|
|
679
|
+
fireEvent.pointerDown( resizeHandle, {
|
|
680
|
+
button: 0,
|
|
681
|
+
clientX: 100,
|
|
682
|
+
clientY: 100,
|
|
683
|
+
pointerId: 1,
|
|
684
|
+
pointerType: 'touch',
|
|
685
|
+
isPrimary: true,
|
|
686
|
+
} );
|
|
687
|
+
|
|
688
|
+
( controller.setPan as jest.Mock ).mockClear();
|
|
689
|
+
fireEvent.pointerDown( canvas, {
|
|
690
|
+
button: 0,
|
|
691
|
+
clientX: 250,
|
|
692
|
+
clientY: 200,
|
|
693
|
+
pointerId: 2,
|
|
694
|
+
pointerType: 'touch',
|
|
695
|
+
isPrimary: false,
|
|
696
|
+
} );
|
|
697
|
+
fireEvent.pointerMove( canvas, {
|
|
698
|
+
button: 0,
|
|
699
|
+
clientX: 275,
|
|
700
|
+
clientY: 200,
|
|
701
|
+
pointerId: 2,
|
|
702
|
+
pointerType: 'touch',
|
|
703
|
+
isPrimary: false,
|
|
704
|
+
} );
|
|
705
|
+
|
|
706
|
+
expect( controller.setPan ).not.toHaveBeenCalled();
|
|
707
|
+
|
|
708
|
+
fireEvent.touchStart( canvas, {
|
|
709
|
+
touches: [
|
|
710
|
+
{ clientX: 250, clientY: 200 },
|
|
711
|
+
{ clientX: 350, clientY: 200 },
|
|
712
|
+
],
|
|
713
|
+
} );
|
|
714
|
+
|
|
715
|
+
await act( async () => {
|
|
716
|
+
await Promise.resolve();
|
|
717
|
+
} );
|
|
718
|
+
|
|
719
|
+
expect( controller.settleCrop ).not.toHaveBeenCalled();
|
|
720
|
+
expect( onGestureEnd ).not.toHaveBeenCalled();
|
|
721
|
+
|
|
722
|
+
( controller.setCropRect as jest.Mock ).mockClear();
|
|
723
|
+
( controller.setZoomAtPoint as jest.Mock ).mockClear();
|
|
724
|
+
|
|
725
|
+
fireEvent.pointerMove( resizeHandle, {
|
|
726
|
+
button: 0,
|
|
727
|
+
clientX: 60,
|
|
728
|
+
clientY: 60,
|
|
729
|
+
pointerId: 1,
|
|
730
|
+
pointerType: 'touch',
|
|
731
|
+
isPrimary: true,
|
|
732
|
+
} );
|
|
733
|
+
fireEvent.touchMove( document, {
|
|
734
|
+
touches: [
|
|
735
|
+
{ clientX: 225, clientY: 200 },
|
|
736
|
+
{ clientX: 375, clientY: 200 },
|
|
737
|
+
],
|
|
738
|
+
} );
|
|
739
|
+
|
|
740
|
+
expect( controller.setCropRect ).not.toHaveBeenCalled();
|
|
741
|
+
expect( controller.setZoomAtPoint ).toHaveBeenCalled();
|
|
742
|
+
|
|
743
|
+
fireEvent.touchEnd( canvas, { touches: [] } );
|
|
744
|
+
|
|
745
|
+
expect( onGestureEnd ).toHaveBeenCalledTimes( 1 );
|
|
746
|
+
} finally {
|
|
747
|
+
globalThis.requestAnimationFrame = originalRAF;
|
|
748
|
+
globalThis.cancelAnimationFrame = originalCAF;
|
|
749
|
+
}
|
|
750
|
+
} );
|
|
751
|
+
|
|
752
|
+
// View-scale: at rest, the scene magnifies so an under-filling crop fills
|
|
753
|
+
// the canvas. Canvas is mocked at 600x400. A tall 400x1200 image contain-
|
|
754
|
+
// fits to a 133.33x400 footprint (fills the height, 133px of 600 wide). A
|
|
755
|
+
// square crop is bound by the footprint's 133px width, so it magnifies.
|
|
756
|
+
const TALL_IMAGE = {
|
|
757
|
+
src: 'tall.jpg',
|
|
758
|
+
naturalWidth: 400,
|
|
759
|
+
naturalHeight: 1200,
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
// The view-scale magnification is folded into the image's transform as a
|
|
763
|
+
// leading `scale(...)`, always present (identity `scale(1)` at rest) so the
|
|
764
|
+
// transform's function list stays structurally constant for transitions.
|
|
765
|
+
function imageScale(): number {
|
|
766
|
+
const img = screen.getByTestId< HTMLImageElement >( 'cropper-image' );
|
|
767
|
+
const match = img.style.transform.match( /^scale\(\s*([\d.]+)/ );
|
|
768
|
+
return match ? parseFloat( match[ 1 ] ) : 1;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function imageTransformParts(): { viewScale: number; matrix: number[] } {
|
|
772
|
+
const img = screen.getByTestId< HTMLImageElement >( 'cropper-image' );
|
|
773
|
+
const match = img.style.transform.match(
|
|
774
|
+
/^scale\(\s*([^)]+?)\s*\)\s+matrix\(([^)]+)\)/
|
|
775
|
+
);
|
|
776
|
+
expect( match ).not.toBeNull();
|
|
777
|
+
const [ , viewScale, matrix ] = match as RegExpMatchArray;
|
|
778
|
+
return {
|
|
779
|
+
viewScale: parseFloat( viewScale ),
|
|
780
|
+
matrix: matrix
|
|
781
|
+
.split( ',' )
|
|
782
|
+
.map( ( value ) => parseFloat( value.trim() ) ),
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
it( 'magnifies the scene so an under-filling crop fills the canvas at rest', () => {
|
|
787
|
+
const controller = createController();
|
|
788
|
+
controller.state = {
|
|
789
|
+
...controller.state,
|
|
790
|
+
image: TALL_IMAGE,
|
|
791
|
+
// Centered square crop: width fills the footprint (133px), height
|
|
792
|
+
// 1/3 of 400 = 133px. On-screen 133x133, well below 0.8 * 400.
|
|
793
|
+
cropRect: { x: 0, y: 1 / 3, width: 1, height: 1 / 3 },
|
|
794
|
+
};
|
|
795
|
+
render( <Cropper src="tall.jpg" controller={ controller } /> );
|
|
796
|
+
|
|
797
|
+
// Footprint is 133.33x400. The square crop's binding axis (height) fills
|
|
798
|
+
// to 0.8 * 400, so the image magnifies by 0.8 * 400 / 133.33 = 2.4.
|
|
799
|
+
expect( imageScale() ).toBeCloseTo( 2.4, 2 );
|
|
800
|
+
} );
|
|
801
|
+
|
|
802
|
+
it( 'computes image pan from the unscaled footprint before applying view scale', () => {
|
|
803
|
+
const controller = createController();
|
|
804
|
+
controller.state = {
|
|
805
|
+
...controller.state,
|
|
806
|
+
image: TALL_IMAGE,
|
|
807
|
+
cropRect: { x: 0, y: 1 / 3, width: 1, height: 1 / 3 },
|
|
808
|
+
pan: { x: 0.1, y: -0.05 },
|
|
809
|
+
};
|
|
810
|
+
render( <Cropper src="tall.jpg" controller={ controller } /> );
|
|
811
|
+
|
|
812
|
+
const { viewScale, matrix } = imageTransformParts();
|
|
813
|
+
|
|
814
|
+
expect( viewScale ).toBeCloseTo( 2.4, 2 );
|
|
815
|
+
// Pan translations are produced by useTransformStyle from the unscaled
|
|
816
|
+
// 133.33x400 footprint, then magnified by the leading scale(viewScale).
|
|
817
|
+
// If useTransformStyle received scaledVisualSize, these would be 32 and
|
|
818
|
+
// -48 instead.
|
|
819
|
+
expect( matrix[ 4 ] ).toBeCloseTo( ( 400 / 3 ) * 0.1, 5 );
|
|
820
|
+
expect( matrix[ 5 ] ).toBeCloseTo( 400 * -0.05, 5 );
|
|
821
|
+
} );
|
|
822
|
+
|
|
823
|
+
it( 'positions crop overlays against the magnified footprint', () => {
|
|
824
|
+
const controller = createController();
|
|
825
|
+
controller.state = {
|
|
826
|
+
...controller.state,
|
|
827
|
+
image: TALL_IMAGE,
|
|
828
|
+
cropRect: { x: 0, y: 1 / 3, width: 1, height: 1 / 3 },
|
|
829
|
+
};
|
|
830
|
+
render( <Cropper src="tall.jpg" controller={ controller } showGrid /> );
|
|
831
|
+
|
|
832
|
+
expect( imageScale() ).toBeCloseTo( 2.4, 2 );
|
|
833
|
+
|
|
834
|
+
const expectedRect = {
|
|
835
|
+
left: 140,
|
|
836
|
+
top: 40,
|
|
837
|
+
width: 320,
|
|
838
|
+
height: 320,
|
|
839
|
+
};
|
|
840
|
+
const expectOverlayRect = ( element: HTMLElement | null ) => {
|
|
841
|
+
expect( element ).not.toBeNull();
|
|
842
|
+
const overlay = element as HTMLElement;
|
|
843
|
+
expect( parseFloat( overlay.style.left ) ).toBeCloseTo(
|
|
844
|
+
expectedRect.left,
|
|
845
|
+
1
|
|
846
|
+
);
|
|
847
|
+
expect( parseFloat( overlay.style.top ) ).toBeCloseTo(
|
|
848
|
+
expectedRect.top,
|
|
849
|
+
1
|
|
850
|
+
);
|
|
851
|
+
expect( parseFloat( overlay.style.width ) ).toBeCloseTo(
|
|
852
|
+
expectedRect.width,
|
|
853
|
+
1
|
|
854
|
+
);
|
|
855
|
+
expect( parseFloat( overlay.style.height ) ).toBeCloseTo(
|
|
856
|
+
expectedRect.height,
|
|
857
|
+
1
|
|
858
|
+
);
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
expectOverlayRect( screen.getByTestId( 'cropper-stencil' ) );
|
|
862
|
+
expectOverlayRect( screen.getByTestId( 'cropper-dimming' ) );
|
|
863
|
+
expectOverlayRect( screen.getByTestId( GRID_TEST_ID ) );
|
|
864
|
+
} );
|
|
865
|
+
|
|
866
|
+
it( 'does not magnify when the crop already fills the canvas', () => {
|
|
867
|
+
const controller = createController();
|
|
868
|
+
controller.state = {
|
|
869
|
+
...controller.state,
|
|
870
|
+
image: TALL_IMAGE,
|
|
871
|
+
// Full-frame crop already fills the canvas height (footprint == 400).
|
|
872
|
+
cropRect: { x: 0, y: 0, width: 1, height: 1 },
|
|
873
|
+
};
|
|
874
|
+
render( <Cropper src="tall.jpg" controller={ controller } /> );
|
|
875
|
+
|
|
876
|
+
// viewScale = 1, so the leading scale is identity (no magnification).
|
|
877
|
+
expect( imageScale() ).toBe( 1 );
|
|
878
|
+
} );
|
|
879
|
+
|
|
880
|
+
it( 'holds the magnified view while resizing instead of resetting the zoom', async () => {
|
|
881
|
+
const controller = createController();
|
|
882
|
+
controller.state = {
|
|
883
|
+
...controller.state,
|
|
884
|
+
image: TALL_IMAGE,
|
|
885
|
+
cropRect: { x: 0, y: 1 / 3, width: 1, height: 1 / 3 },
|
|
886
|
+
};
|
|
887
|
+
render(
|
|
888
|
+
<Cropper src="tall.jpg" controller={ controller } freeformCrop />
|
|
889
|
+
);
|
|
890
|
+
|
|
891
|
+
// At rest the square crop magnifies the image by 2.4.
|
|
892
|
+
expect( imageScale() ).toBeCloseTo( 2.4, 2 );
|
|
893
|
+
|
|
894
|
+
const handle = await screen.findByRole( 'button', {
|
|
895
|
+
name: 'Resize top-left corner',
|
|
896
|
+
} );
|
|
897
|
+
fireEvent.pointerDown( handle, {
|
|
898
|
+
button: 0,
|
|
899
|
+
clientX: 100,
|
|
900
|
+
clientY: 100,
|
|
901
|
+
pointerId: 1,
|
|
902
|
+
} );
|
|
903
|
+
|
|
904
|
+
// Grabbing a handle must not snap the scene back to the footprint;
|
|
905
|
+
// the magnification holds for the duration of the drag.
|
|
906
|
+
expect( imageScale() ).toBeCloseTo( 2.4, 2 );
|
|
907
|
+
|
|
908
|
+
fireEvent.pointerUp( handle, { pointerId: 1 } );
|
|
909
|
+
} );
|
|
910
|
+
|
|
911
|
+
it( 'snaps freeform resize output to source pixels when the image is shown at 1:1 or larger', async () => {
|
|
912
|
+
const image = { src: 'tiny.png', naturalWidth: 50, naturalHeight: 50 };
|
|
913
|
+
const cropRect = { x: 0.1, y: 0.12, width: 0.6, height: 0.44 };
|
|
914
|
+
const controller = createController();
|
|
915
|
+
controller.state = {
|
|
916
|
+
...controller.state,
|
|
917
|
+
image,
|
|
918
|
+
cropRect,
|
|
919
|
+
};
|
|
920
|
+
const initialRegion = getSourceRegion(
|
|
921
|
+
{ ...controller.state, cropRect },
|
|
922
|
+
{ width: image.naturalWidth, height: image.naturalHeight }
|
|
923
|
+
);
|
|
924
|
+
render(
|
|
925
|
+
<Cropper src="tiny.png" controller={ controller } freeformCrop />
|
|
926
|
+
);
|
|
927
|
+
|
|
928
|
+
const handle = await screen.findByRole( 'button', {
|
|
929
|
+
name: 'Resize right edge',
|
|
930
|
+
} );
|
|
931
|
+
fireEvent.keyDown( handle, { key: 'ArrowRight' } );
|
|
932
|
+
|
|
933
|
+
const rect = ( controller.setCropRect as jest.Mock ).mock
|
|
934
|
+
.calls[ 0 ][ 0 ];
|
|
935
|
+
const region = getSourceRegion(
|
|
936
|
+
{ ...controller.state, cropRect: rect },
|
|
937
|
+
{ width: image.naturalWidth, height: image.naturalHeight }
|
|
938
|
+
);
|
|
939
|
+
expect( region.x ).toBeCloseTo( initialRegion.x, 3 );
|
|
940
|
+
expect( region.x + region.width ).toBeCloseTo(
|
|
941
|
+
Math.round( region.x + region.width ),
|
|
942
|
+
3
|
|
943
|
+
);
|
|
944
|
+
expect( rect.x ).toBeCloseTo( cropRect.x, 5 );
|
|
945
|
+
expect( rect.y ).toBeCloseTo( cropRect.y, 5 );
|
|
946
|
+
expect( rect.height ).toBeCloseTo( cropRect.height, 5 );
|
|
947
|
+
} );
|
|
948
|
+
|
|
949
|
+
it( 'uses source-pixel keyboard steps for horizontal freeform resize when snapping is active', async () => {
|
|
950
|
+
const image = {
|
|
951
|
+
src: 'wide.png',
|
|
952
|
+
naturalWidth: 200,
|
|
953
|
+
naturalHeight: 100,
|
|
954
|
+
};
|
|
955
|
+
const cropRect = { x: 0.1, y: 0.1, width: 0.6, height: 0.6 };
|
|
956
|
+
const controller = createController();
|
|
957
|
+
controller.state = {
|
|
958
|
+
...controller.state,
|
|
959
|
+
image,
|
|
960
|
+
cropRect,
|
|
961
|
+
};
|
|
962
|
+
const initialRegion = getSourceRegion(
|
|
963
|
+
{ ...controller.state, cropRect },
|
|
964
|
+
{ width: image.naturalWidth, height: image.naturalHeight }
|
|
965
|
+
);
|
|
966
|
+
render(
|
|
967
|
+
<Cropper src="wide.png" controller={ controller } freeformCrop />
|
|
968
|
+
);
|
|
969
|
+
|
|
970
|
+
const handle = await screen.findByRole( 'button', {
|
|
971
|
+
name: 'Resize right edge',
|
|
972
|
+
} );
|
|
973
|
+
( controller.setCropRect as jest.Mock ).mockClear();
|
|
974
|
+
fireEvent.keyDown( handle, { key: 'ArrowRight' } );
|
|
975
|
+
|
|
976
|
+
const rect = ( controller.setCropRect as jest.Mock ).mock
|
|
977
|
+
.calls[ 0 ][ 0 ];
|
|
978
|
+
const region = getSourceRegion(
|
|
979
|
+
{ ...controller.state, cropRect: rect },
|
|
980
|
+
{ width: image.naturalWidth, height: image.naturalHeight }
|
|
981
|
+
);
|
|
982
|
+
expect( region.x + region.width ).toBeCloseTo(
|
|
983
|
+
initialRegion.x + initialRegion.width + 1,
|
|
984
|
+
3
|
|
985
|
+
);
|
|
986
|
+
} );
|
|
987
|
+
|
|
988
|
+
it( 'keeps freeform resize smooth below 1:1 display scale', async () => {
|
|
989
|
+
const image = {
|
|
990
|
+
src: 'large.png',
|
|
991
|
+
naturalWidth: 3333,
|
|
992
|
+
naturalHeight: 3333,
|
|
993
|
+
};
|
|
994
|
+
const cropRect = { x: 0.113, y: 0.127, width: 0.6, height: 0.456 };
|
|
995
|
+
const controller = createController();
|
|
996
|
+
controller.state = {
|
|
997
|
+
...controller.state,
|
|
998
|
+
image,
|
|
999
|
+
cropRect,
|
|
1000
|
+
};
|
|
1001
|
+
render(
|
|
1002
|
+
<Cropper src="large.png" controller={ controller } freeformCrop />
|
|
1003
|
+
);
|
|
1004
|
+
|
|
1005
|
+
const handle = await screen.findByRole( 'button', {
|
|
1006
|
+
name: 'Resize right edge',
|
|
1007
|
+
} );
|
|
1008
|
+
fireEvent.keyDown( handle, { key: 'ArrowRight' } );
|
|
1009
|
+
|
|
1010
|
+
const rect = ( controller.setCropRect as jest.Mock ).mock
|
|
1011
|
+
.calls[ 0 ][ 0 ];
|
|
1012
|
+
const region = getSourceRegion(
|
|
1013
|
+
{ ...controller.state, cropRect: rect },
|
|
1014
|
+
{ width: image.naturalWidth, height: image.naturalHeight }
|
|
1015
|
+
);
|
|
1016
|
+
expect( rect.width ).toBeCloseTo( 0.61, 5 );
|
|
1017
|
+
expect(
|
|
1018
|
+
Math.abs(
|
|
1019
|
+
region.x + region.width - Math.round( region.x + region.width )
|
|
1020
|
+
)
|
|
1021
|
+
).toBeGreaterThan( 0.01 );
|
|
1022
|
+
} );
|
|
1023
|
+
|
|
1024
|
+
it( 'snaps all crop edges once when display scale reaches source-pixel size', async () => {
|
|
1025
|
+
const image = {
|
|
1026
|
+
src: 'crossing.png',
|
|
1027
|
+
naturalWidth: 1000,
|
|
1028
|
+
naturalHeight: 1000,
|
|
1029
|
+
};
|
|
1030
|
+
const cropRect = {
|
|
1031
|
+
x: 0.113,
|
|
1032
|
+
y: 0.127,
|
|
1033
|
+
width: 0.733,
|
|
1034
|
+
height: 0.641,
|
|
1035
|
+
};
|
|
1036
|
+
const controller = createController();
|
|
1037
|
+
controller.state = {
|
|
1038
|
+
...controller.state,
|
|
1039
|
+
image,
|
|
1040
|
+
cropRect,
|
|
1041
|
+
zoom: 0.5,
|
|
1042
|
+
};
|
|
1043
|
+
const { rerender } = render(
|
|
1044
|
+
<Cropper
|
|
1045
|
+
src="crossing.png"
|
|
1046
|
+
controller={ controller }
|
|
1047
|
+
freeformCrop
|
|
1048
|
+
/>
|
|
1049
|
+
);
|
|
1050
|
+
|
|
1051
|
+
await screen.findByTestId( 'cropper-image' );
|
|
1052
|
+
expect( controller.setCropRect ).not.toHaveBeenCalled();
|
|
1053
|
+
|
|
1054
|
+
controller.state = { ...controller.state, zoom: 3 };
|
|
1055
|
+
rerender(
|
|
1056
|
+
<Cropper
|
|
1057
|
+
src="crossing.png"
|
|
1058
|
+
controller={ controller }
|
|
1059
|
+
freeformCrop
|
|
1060
|
+
/>
|
|
1061
|
+
);
|
|
1062
|
+
|
|
1063
|
+
await waitFor( () =>
|
|
1064
|
+
expect( controller.setCropRect ).toHaveBeenCalledTimes( 1 )
|
|
1065
|
+
);
|
|
1066
|
+
const rect = ( controller.setCropRect as jest.Mock ).mock
|
|
1067
|
+
.calls[ 0 ][ 0 ];
|
|
1068
|
+
const region = getSourceRegion(
|
|
1069
|
+
{ ...controller.state, cropRect: rect },
|
|
1070
|
+
{ width: image.naturalWidth, height: image.naturalHeight }
|
|
1071
|
+
);
|
|
1072
|
+
for ( const edge of [
|
|
1073
|
+
region.x,
|
|
1074
|
+
region.y,
|
|
1075
|
+
region.x + region.width,
|
|
1076
|
+
region.y + region.height,
|
|
1077
|
+
] ) {
|
|
1078
|
+
expect( edge ).toBeCloseTo( Math.round( edge ), 3 );
|
|
1079
|
+
}
|
|
1080
|
+
} );
|
|
1081
|
+
|
|
1082
|
+
it( 'does not snap all crop edges for fixed-aspect freeform crops', async () => {
|
|
1083
|
+
const image = {
|
|
1084
|
+
src: 'locked-ratio.png',
|
|
1085
|
+
naturalWidth: 1000,
|
|
1086
|
+
naturalHeight: 1000,
|
|
1087
|
+
};
|
|
1088
|
+
const controller = createController();
|
|
1089
|
+
controller.state = {
|
|
1090
|
+
...controller.state,
|
|
1091
|
+
image,
|
|
1092
|
+
cropRect: {
|
|
1093
|
+
x: 0.113,
|
|
1094
|
+
y: 0.127,
|
|
1095
|
+
width: 0.733,
|
|
1096
|
+
height: 0.641,
|
|
1097
|
+
},
|
|
1098
|
+
zoom: 0.5,
|
|
1099
|
+
};
|
|
1100
|
+
const { rerender } = render(
|
|
1101
|
+
<Cropper
|
|
1102
|
+
src="locked-ratio.png"
|
|
1103
|
+
controller={ controller }
|
|
1104
|
+
freeformCrop
|
|
1105
|
+
aspectRatio={ 1 }
|
|
1106
|
+
/>
|
|
1107
|
+
);
|
|
1108
|
+
|
|
1109
|
+
await screen.findByTestId( 'cropper-image' );
|
|
1110
|
+
controller.state = { ...controller.state, zoom: 3 };
|
|
1111
|
+
rerender(
|
|
1112
|
+
<Cropper
|
|
1113
|
+
src="locked-ratio.png"
|
|
1114
|
+
controller={ controller }
|
|
1115
|
+
freeformCrop
|
|
1116
|
+
aspectRatio={ 1 }
|
|
1117
|
+
/>
|
|
1118
|
+
);
|
|
1119
|
+
|
|
1120
|
+
expect( controller.setCropRect ).not.toHaveBeenCalled();
|
|
1121
|
+
} );
|
|
1122
|
+
|
|
1123
|
+
function imageRendering(): string {
|
|
1124
|
+
return screen.getByTestId< HTMLImageElement >( 'cropper-image' ).style
|
|
1125
|
+
.imageRendering;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
it( 'renders upscaled (small) images pixelated so pixel boundaries stay crisp', () => {
|
|
1129
|
+
const controller = createController();
|
|
1130
|
+
controller.state = {
|
|
1131
|
+
...controller.state,
|
|
1132
|
+
// A 50x50 image contain-fits to 400px in the 600x400 canvas — an 8x
|
|
1133
|
+
// upscale — so the display scale exceeds 1:1.
|
|
1134
|
+
image: { src: 'tiny.png', naturalWidth: 50, naturalHeight: 50 },
|
|
1135
|
+
};
|
|
1136
|
+
render( <Cropper src="tiny.png" controller={ controller } /> );
|
|
1137
|
+
|
|
1138
|
+
expect( imageRendering() ).toBe( 'pixelated' );
|
|
1139
|
+
} );
|
|
1140
|
+
|
|
1141
|
+
it( 'renders downscaled (large) images smoothly', () => {
|
|
1142
|
+
const controller = createController();
|
|
1143
|
+
controller.state = {
|
|
1144
|
+
...controller.state,
|
|
1145
|
+
// Tall image is shown well below 1:1 (fit ~0.33), even when the crop
|
|
1146
|
+
// magnifies, so the image is downscaled and should stay smooth.
|
|
1147
|
+
image: TALL_IMAGE,
|
|
1148
|
+
cropRect: { x: 0, y: 1 / 3, width: 1, height: 1 / 3 },
|
|
1149
|
+
};
|
|
1150
|
+
render( <Cropper src="tall.jpg" controller={ controller } /> );
|
|
1151
|
+
|
|
1152
|
+
expect( imageRendering() ).not.toBe( 'pixelated' );
|
|
1153
|
+
} );
|
|
471
1154
|
} );
|