@wordpress/media-editor 0.11.0 → 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/CHANGELOG.md +16 -0
- package/build/components/media-editor/index.cjs +41 -51
- package/build/components/media-editor/index.cjs.map +3 -3
- 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-crop-panel/index.cjs +15 -45
- package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
- package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
- package/build/components/media-editor-image-controls/index.cjs +230 -0
- package/build/components/media-editor-image-controls/index.cjs.map +7 -0
- 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/media-form/index.cjs +12 -23
- package/build/components/media-form/index.cjs.map +3 -3
- 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 +15 -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 +14 -6
- 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 +231 -49
- 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 +41 -51
- package/build-module/components/media-editor/index.mjs.map +2 -2
- 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-crop-panel/index.mjs +8 -51
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs +221 -0
- package/build-module/components/media-editor-image-controls/index.mjs.map +7 -0
- 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/media-form/index.mjs +12 -13
- package/build-module/components/media-form/index.mjs.map +2 -2
- 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 +10 -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 +12 -5
- 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 -52
- 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 +179 -47
- package/build-style/style.css +179 -46
- package/build-types/components/media-editor/index.d.ts +6 -7
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +11 -6
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts +4 -3
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +46 -0
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -0
- package/build-types/components/media-form/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 +30 -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 +22 -4
- 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 +30 -20
- package/src/components/media-editor/index.tsx +69 -77
- package/src/components/media-editor/style.scss +136 -4
- package/src/components/media-editor-canvas/index.tsx +82 -13
- package/src/components/media-editor-canvas/style.scss +41 -0
- package/src/components/media-editor-crop-panel/index.tsx +16 -62
- package/src/components/media-editor-crop-panel/test/index.tsx +25 -41
- package/src/components/media-editor-fine-rotation/index.tsx +4 -3
- package/src/components/media-editor-image-controls/index.tsx +262 -0
- package/src/components/media-editor-image-controls/style.scss +48 -0
- package/src/components/media-editor-image-controls/test/index.tsx +150 -0
- package/src/components/media-editor-modal/style.scss +32 -42
- package/src/components/media-form/index.tsx +17 -21
- package/src/components/media-form/style.scss +6 -0
- package/src/components/rotation-ruler/style.scss +10 -3
- package/src/image-editor/core/camera.ts +60 -1
- package/src/image-editor/core/constants.ts +34 -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 +42 -10
- 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 +153 -0
- package/src/image-editor/core/types.ts +17 -0
- package/src/image-editor/react/components/cropper.scss +28 -17
- package/src/image-editor/react/components/cropper.tsx +362 -62
- 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/src/style.scss +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-transform-controls/index.cjs +0 -84
- package/build/components/media-editor-transform-controls/index.cjs.map +0 -7
- package/build/components/media-form/sidebar-datetime-view.cjs +0 -53
- package/build/components/media-form/sidebar-datetime-view.cjs.map +0 -7
- package/build-module/components/media-editor-transform-controls/index.mjs +0 -68
- package/build-module/components/media-editor-transform-controls/index.mjs.map +0 -7
- package/build-module/components/media-form/sidebar-datetime-view.mjs +0 -32
- package/build-module/components/media-form/sidebar-datetime-view.mjs.map +0 -7
- package/build-types/components/media-editor-transform-controls/index.d.ts +0 -8
- 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/src/components/media-editor-transform-controls/index.tsx +0 -70
- package/src/components/media-editor-transform-controls/style.scss +0 -8
- package/src/components/media-form/sidebar-datetime-view.tsx +0 -47
- package/src/components/media-form/test/sidebar-datetime-view.test.tsx +0 -96
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
createExportCamera,
|
|
7
7
|
getImageFit,
|
|
8
8
|
getRotatedBBox,
|
|
9
|
+
getViewScale,
|
|
9
10
|
} from '../camera';
|
|
10
11
|
import {
|
|
11
12
|
restrictPanZoom,
|
|
@@ -13,7 +14,12 @@ import {
|
|
|
13
14
|
getImageCropBounds,
|
|
14
15
|
getMinZoom,
|
|
15
16
|
} from '../containment';
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
getSourceRegion,
|
|
19
|
+
getSourceRegionPercent,
|
|
20
|
+
snapCropRectToSourcePixelGrid,
|
|
21
|
+
snapCropRectToSourcePixels,
|
|
22
|
+
} from '../source-region';
|
|
17
23
|
import { computeTransformStyle } from '../transform-style';
|
|
18
24
|
import { DEFAULT_STATE, MAX_ZOOM, MIN_ZOOM } from '../constants';
|
|
19
25
|
import type { CropperState, Size } from '../types';
|
|
@@ -576,6 +582,114 @@ describe( 'getSourceRegion', () => {
|
|
|
576
582
|
} );
|
|
577
583
|
} );
|
|
578
584
|
|
|
585
|
+
describe( 'snapCropRectToSourcePixels', () => {
|
|
586
|
+
const getSourceEdges = ( state: CropperState ) => {
|
|
587
|
+
const region = getSourceRegion( state, IMAGE );
|
|
588
|
+
return {
|
|
589
|
+
left: region.x,
|
|
590
|
+
top: region.y,
|
|
591
|
+
right: region.x + region.width,
|
|
592
|
+
bottom: region.y + region.height,
|
|
593
|
+
};
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
it( 'snaps the selected source-region edges to whole pixels under pan and zoom', () => {
|
|
597
|
+
const state = makeState( {
|
|
598
|
+
zoom: 2.25,
|
|
599
|
+
pan: { x: 0.013, y: -0.017 },
|
|
600
|
+
cropRect: { x: 0.12, y: 0.18, width: 0.33, height: 0.41 },
|
|
601
|
+
} );
|
|
602
|
+
const candidate = { x: 0.123, y: 0.187, width: 0.337, height: 0.419 };
|
|
603
|
+
|
|
604
|
+
const unsnapped = getSourceRegion(
|
|
605
|
+
{ ...state, cropRect: candidate },
|
|
606
|
+
IMAGE
|
|
607
|
+
);
|
|
608
|
+
expect(
|
|
609
|
+
Math.abs(
|
|
610
|
+
unsnapped.x +
|
|
611
|
+
unsnapped.width -
|
|
612
|
+
Math.round( unsnapped.x + unsnapped.width )
|
|
613
|
+
)
|
|
614
|
+
).toBeGreaterThan( 0.01 );
|
|
615
|
+
expect(
|
|
616
|
+
Math.abs(
|
|
617
|
+
unsnapped.y +
|
|
618
|
+
unsnapped.height -
|
|
619
|
+
Math.round( unsnapped.y + unsnapped.height )
|
|
620
|
+
)
|
|
621
|
+
).toBeGreaterThan( 0.01 );
|
|
622
|
+
|
|
623
|
+
const snappedCropRect = snapCropRectToSourcePixels(
|
|
624
|
+
state,
|
|
625
|
+
IMAGE,
|
|
626
|
+
candidate,
|
|
627
|
+
'se'
|
|
628
|
+
);
|
|
629
|
+
|
|
630
|
+
const snapped = getSourceEdges( {
|
|
631
|
+
...state,
|
|
632
|
+
cropRect: snappedCropRect,
|
|
633
|
+
} );
|
|
634
|
+
expect( snapped.left ).toBeCloseTo( unsnapped.x, 3 );
|
|
635
|
+
expect( snapped.top ).toBeCloseTo( unsnapped.y, 3 );
|
|
636
|
+
expect( snapped.right ).toBeCloseTo( Math.round( snapped.right ), 3 );
|
|
637
|
+
expect( snapped.bottom ).toBeCloseTo( Math.round( snapped.bottom ), 3 );
|
|
638
|
+
} );
|
|
639
|
+
|
|
640
|
+
it( 'snaps all source-region edges to whole pixels', () => {
|
|
641
|
+
const state = makeState( {
|
|
642
|
+
rotation: 30,
|
|
643
|
+
zoom: 2.25,
|
|
644
|
+
pan: { x: 0.013, y: -0.017 },
|
|
645
|
+
cropRect: { x: 0.12, y: 0.18, width: 0.33, height: 0.41 },
|
|
646
|
+
} );
|
|
647
|
+
const candidate = { x: 0.123, y: 0.187, width: 0.337, height: 0.419 };
|
|
648
|
+
|
|
649
|
+
const snappedCropRect = snapCropRectToSourcePixelGrid(
|
|
650
|
+
state,
|
|
651
|
+
IMAGE,
|
|
652
|
+
candidate
|
|
653
|
+
);
|
|
654
|
+
const snapped = getSourceEdges( {
|
|
655
|
+
...state,
|
|
656
|
+
cropRect: snappedCropRect,
|
|
657
|
+
} );
|
|
658
|
+
|
|
659
|
+
expect( snapped.left ).toBeCloseTo( Math.round( snapped.left ), 3 );
|
|
660
|
+
expect( snapped.top ).toBeCloseTo( Math.round( snapped.top ), 3 );
|
|
661
|
+
expect( snapped.right ).toBeCloseTo( Math.round( snapped.right ), 3 );
|
|
662
|
+
expect( snapped.bottom ).toBeCloseTo( Math.round( snapped.bottom ), 3 );
|
|
663
|
+
} );
|
|
664
|
+
|
|
665
|
+
it( 'does not snap selected edges while fine rotation couples source axes', () => {
|
|
666
|
+
const state = makeState( {
|
|
667
|
+
rotation: 30,
|
|
668
|
+
zoom: 2.25,
|
|
669
|
+
pan: { x: 0.013, y: -0.017 },
|
|
670
|
+
cropRect: { x: 0.12, y: 0.18, width: 0.33, height: 0.41 },
|
|
671
|
+
} );
|
|
672
|
+
const candidate = { x: 0.123, y: 0.187, width: 0.337, height: 0.419 };
|
|
673
|
+
|
|
674
|
+
expect(
|
|
675
|
+
snapCropRectToSourcePixels( state, IMAGE, candidate, 'e' )
|
|
676
|
+
).toBe( candidate );
|
|
677
|
+
} );
|
|
678
|
+
|
|
679
|
+
it( 'returns the input crop rect when the image dimensions are invalid', () => {
|
|
680
|
+
const cropRect = { x: 0.1, y: 0.2, width: 0.3, height: 0.4 };
|
|
681
|
+
|
|
682
|
+
expect(
|
|
683
|
+
snapCropRectToSourcePixels(
|
|
684
|
+
makeState(),
|
|
685
|
+
{ width: 0, height: 0 },
|
|
686
|
+
cropRect,
|
|
687
|
+
'se'
|
|
688
|
+
)
|
|
689
|
+
).toBe( cropRect );
|
|
690
|
+
} );
|
|
691
|
+
} );
|
|
692
|
+
|
|
579
693
|
describe( 'getSourceRegionPercent', () => {
|
|
580
694
|
it( 'at default state, returns 0/0/100/100', () => {
|
|
581
695
|
const state = makeState();
|
|
@@ -946,3 +1060,160 @@ describe( 'getSourceRegion — non-finite input regression', () => {
|
|
|
946
1060
|
expect( out.zoom ).toBeGreaterThanOrEqual( 1 );
|
|
947
1061
|
} );
|
|
948
1062
|
} );
|
|
1063
|
+
|
|
1064
|
+
describe( 'getViewScale — presentational magnification to fill the canvas', () => {
|
|
1065
|
+
// A tall image (1400x2500) fit into a short, wide canvas (1000x500):
|
|
1066
|
+
// contain fit = min(1000/1400, 500/2500) = 0.2, so the rendered footprint
|
|
1067
|
+
// is 280x500 — it fills the canvas height but only 280 of 1000 px wide.
|
|
1068
|
+
const CANVAS: Size = { width: 1000, height: 500 };
|
|
1069
|
+
const FOOTPRINT: Size = { width: 280, height: 500 };
|
|
1070
|
+
const TARGET = 0.8;
|
|
1071
|
+
const MAX = 8;
|
|
1072
|
+
|
|
1073
|
+
it( 'returns 1 when the crop already fills at least the target on its binding axis', () => {
|
|
1074
|
+
// Full-footprint crop is 280x500 on screen: 500 == canvas height, well
|
|
1075
|
+
// above 0.8 of it. No magnification needed.
|
|
1076
|
+
const full = { x: 0, y: 0, width: 1, height: 1 };
|
|
1077
|
+
expect( getViewScale( full, CANVAS, FOOTPRINT, TARGET, MAX ) ).toBe(
|
|
1078
|
+
1
|
|
1079
|
+
);
|
|
1080
|
+
} );
|
|
1081
|
+
|
|
1082
|
+
it( 'magnifies an under-filling crop so its binding axis reaches target * canvas', () => {
|
|
1083
|
+
// A square crop in the 280x500 footprint: width fills (cropRect.width=1
|
|
1084
|
+
// -> 280px), height is 280/500 = 0.56 (-> 280px). On-screen 280x280.
|
|
1085
|
+
// kW = 0.8*1000/280 = 2.857, kH = 0.8*500/280 = 1.4286, k = min = 1.4286.
|
|
1086
|
+
const square = { x: 0, y: 0.22, width: 1, height: 280 / 500 };
|
|
1087
|
+
const scale = getViewScale( square, CANVAS, FOOTPRINT, TARGET, MAX );
|
|
1088
|
+
expect( scale ).toBeCloseTo( ( TARGET * 500 ) / 280, 5 );
|
|
1089
|
+
// After magnification the binding (height) axis reaches 0.8 * canvas.
|
|
1090
|
+
expect( square.height * FOOTPRINT.height * scale ).toBeCloseTo(
|
|
1091
|
+
TARGET * CANVAS.height,
|
|
1092
|
+
5
|
|
1093
|
+
);
|
|
1094
|
+
} );
|
|
1095
|
+
|
|
1096
|
+
it( 'clamps magnification at maxScale for a near-degenerate crop', () => {
|
|
1097
|
+
// Tiny crop would need an enormous scale to fill; cap it.
|
|
1098
|
+
const tiny = { x: 0.5, y: 0.5, width: 0.02, height: 0.02 };
|
|
1099
|
+
expect( getViewScale( tiny, CANVAS, FOOTPRINT, TARGET, MAX ) ).toBe(
|
|
1100
|
+
MAX
|
|
1101
|
+
);
|
|
1102
|
+
} );
|
|
1103
|
+
|
|
1104
|
+
it( 'never shrinks below 1 even when the crop overfills the target', () => {
|
|
1105
|
+
const full = { x: 0, y: 0, width: 1, height: 1 };
|
|
1106
|
+
expect( getViewScale( full, CANVAS, FOOTPRINT, 0.5, MAX ) ).toBe( 1 );
|
|
1107
|
+
} );
|
|
1108
|
+
|
|
1109
|
+
it( 'returns 1 for zero or degenerate inputs', () => {
|
|
1110
|
+
const full = { x: 0, y: 0, width: 1, height: 1 };
|
|
1111
|
+
const zeroRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
1112
|
+
expect( getViewScale( zeroRect, CANVAS, FOOTPRINT, TARGET, MAX ) ).toBe(
|
|
1113
|
+
1
|
|
1114
|
+
);
|
|
1115
|
+
expect(
|
|
1116
|
+
getViewScale(
|
|
1117
|
+
full,
|
|
1118
|
+
{ width: 0, height: 0 },
|
|
1119
|
+
FOOTPRINT,
|
|
1120
|
+
TARGET,
|
|
1121
|
+
MAX
|
|
1122
|
+
)
|
|
1123
|
+
).toBe( 1 );
|
|
1124
|
+
expect(
|
|
1125
|
+
getViewScale( full, CANVAS, { width: 0, height: 0 }, TARGET, MAX )
|
|
1126
|
+
).toBe( 1 );
|
|
1127
|
+
} );
|
|
1128
|
+
|
|
1129
|
+
it( 'returns 1 (never NaN) for non-finite inputs', () => {
|
|
1130
|
+
const full = { x: 0, y: 0, width: 1, height: 1 };
|
|
1131
|
+
const nanRect = { x: 0, y: 0, width: NaN, height: 1 };
|
|
1132
|
+
expect( getViewScale( nanRect, CANVAS, FOOTPRINT, TARGET, MAX ) ).toBe(
|
|
1133
|
+
1
|
|
1134
|
+
);
|
|
1135
|
+
expect(
|
|
1136
|
+
getViewScale(
|
|
1137
|
+
full,
|
|
1138
|
+
{ width: NaN, height: 500 },
|
|
1139
|
+
FOOTPRINT,
|
|
1140
|
+
TARGET,
|
|
1141
|
+
MAX
|
|
1142
|
+
)
|
|
1143
|
+
).toBe( 1 );
|
|
1144
|
+
expect(
|
|
1145
|
+
getViewScale(
|
|
1146
|
+
full,
|
|
1147
|
+
CANVAS,
|
|
1148
|
+
{ width: Infinity, height: 500 },
|
|
1149
|
+
TARGET,
|
|
1150
|
+
MAX
|
|
1151
|
+
)
|
|
1152
|
+
).toBe( 1 );
|
|
1153
|
+
expect( getViewScale( full, CANVAS, FOOTPRINT, NaN, MAX ) ).toBe( 1 );
|
|
1154
|
+
expect( getViewScale( full, CANVAS, FOOTPRINT, TARGET, NaN ) ).toBe(
|
|
1155
|
+
1
|
|
1156
|
+
);
|
|
1157
|
+
} );
|
|
1158
|
+
} );
|
|
1159
|
+
|
|
1160
|
+
describe( 'getViewScale — property invariants', () => {
|
|
1161
|
+
const ITERATIONS = 100;
|
|
1162
|
+
|
|
1163
|
+
it( `holds across ${ ITERATIONS } random valid inputs`, () => {
|
|
1164
|
+
for ( let i = 0; i < ITERATIONS; i++ ) {
|
|
1165
|
+
const canvasW = 200 + ( ( i * 37 ) % 1800 );
|
|
1166
|
+
const canvasH = 200 + ( ( i * 53 ) % 1200 );
|
|
1167
|
+
const footprintW = 50 + ( ( i * 19 ) % 800 );
|
|
1168
|
+
const footprintH = 50 + ( ( i * 29 ) % 1000 );
|
|
1169
|
+
const cropW = 0.05 + ( ( i * 3 ) % 95 ) / 100;
|
|
1170
|
+
const cropH = 0.05 + ( ( i * 5 ) % 95 ) / 100;
|
|
1171
|
+
const cropX = Math.min( ( ( i * 11 ) % 100 ) / 100, 1 - cropW );
|
|
1172
|
+
const cropY = Math.min( ( ( i * 17 ) % 100 ) / 100, 1 - cropH );
|
|
1173
|
+
const targetFill = 0.1 + ( ( i * 7 ) % 90 ) / 100;
|
|
1174
|
+
const maxScale = 1 + ( ( i * 13 ) % 20 );
|
|
1175
|
+
|
|
1176
|
+
const canvas: Size = { width: canvasW, height: canvasH };
|
|
1177
|
+
const footprint: Size = { width: footprintW, height: footprintH };
|
|
1178
|
+
const cropRect = {
|
|
1179
|
+
x: cropX,
|
|
1180
|
+
y: cropY,
|
|
1181
|
+
width: cropW,
|
|
1182
|
+
height: cropH,
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
const scale = getViewScale(
|
|
1186
|
+
cropRect,
|
|
1187
|
+
canvas,
|
|
1188
|
+
footprint,
|
|
1189
|
+
targetFill,
|
|
1190
|
+
maxScale
|
|
1191
|
+
);
|
|
1192
|
+
|
|
1193
|
+
expect( Number.isFinite( scale ) ).toBe( true );
|
|
1194
|
+
expect( scale ).toBeGreaterThanOrEqual( 1 );
|
|
1195
|
+
expect( scale ).toBeLessThanOrEqual( maxScale );
|
|
1196
|
+
|
|
1197
|
+
const cropScreenW = cropRect.width * footprintW;
|
|
1198
|
+
const cropScreenH = cropRect.height * footprintH;
|
|
1199
|
+
const kW = ( targetFill * canvasW ) / cropScreenW;
|
|
1200
|
+
const kH = ( targetFill * canvasH ) / cropScreenH;
|
|
1201
|
+
const k = Math.min( kW, kH );
|
|
1202
|
+
const unclamped = Math.max( 1, k );
|
|
1203
|
+
|
|
1204
|
+
expect( scale ).toBeCloseTo( Math.min( maxScale, unclamped ), 10 );
|
|
1205
|
+
|
|
1206
|
+
const shouldCheckFill = scale > 1 && scale < maxScale - 1e-10;
|
|
1207
|
+
const bindingIsWidth = kW <= kH + 1e-10;
|
|
1208
|
+
const magnifiedBinding = bindingIsWidth
|
|
1209
|
+
? cropScreenW * scale
|
|
1210
|
+
: cropScreenH * scale;
|
|
1211
|
+
const targetBinding = bindingIsWidth
|
|
1212
|
+
? targetFill * canvasW
|
|
1213
|
+
: targetFill * canvasH;
|
|
1214
|
+
expect(
|
|
1215
|
+
shouldCheckFill ? magnifiedBinding / targetBinding : 1
|
|
1216
|
+
).toBeCloseTo( 1, shouldCheckFill ? 4 : 10 );
|
|
1217
|
+
}
|
|
1218
|
+
} );
|
|
1219
|
+
} );
|
|
@@ -291,6 +291,38 @@ describe( 'InteractionController', () => {
|
|
|
291
291
|
el._fire( 'pointerup', createPointerEvent() );
|
|
292
292
|
} );
|
|
293
293
|
|
|
294
|
+
it( 'ignores touch pointerdown so touch gestures own touch input', () => {
|
|
295
|
+
const state = makeState( { zoom: 2 } );
|
|
296
|
+
const onGestureStart = jest.fn();
|
|
297
|
+
const onStatusChange = jest.fn();
|
|
298
|
+
const { controller } = createController( state, {
|
|
299
|
+
onGestureStart,
|
|
300
|
+
onStatusChange,
|
|
301
|
+
} );
|
|
302
|
+
const el = createMockElement();
|
|
303
|
+
const event = createPointerEvent( {
|
|
304
|
+
clientX: 100,
|
|
305
|
+
clientY: 100,
|
|
306
|
+
pointerType: 'touch',
|
|
307
|
+
} );
|
|
308
|
+
|
|
309
|
+
controller.handlePointerDown( event, el );
|
|
310
|
+
|
|
311
|
+
expect( event.preventDefault ).not.toHaveBeenCalled();
|
|
312
|
+
expect( el.focus ).not.toHaveBeenCalled();
|
|
313
|
+
expect( el.setPointerCapture ).not.toHaveBeenCalled();
|
|
314
|
+
expect( el.addEventListener ).not.toHaveBeenCalled();
|
|
315
|
+
expect( onGestureStart ).not.toHaveBeenCalled();
|
|
316
|
+
expect( onStatusChange ).not.toHaveBeenCalled();
|
|
317
|
+
|
|
318
|
+
el._fire(
|
|
319
|
+
'pointermove',
|
|
320
|
+
createPointerEvent( { clientX: 150, clientY: 120 } )
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
expect( actionMocks.setPan ).not.toHaveBeenCalled();
|
|
324
|
+
} );
|
|
325
|
+
|
|
294
326
|
it( 'stops dispatching after pointerup', () => {
|
|
295
327
|
const state = makeState( { zoom: 2 } );
|
|
296
328
|
const { controller } = createController( state );
|
|
@@ -797,6 +829,26 @@ describe( 'InteractionController', () => {
|
|
|
797
829
|
expect( actionMocks.setPan ).toHaveBeenCalled();
|
|
798
830
|
} );
|
|
799
831
|
|
|
832
|
+
it( 'prevents default on touchmove so the page does not scroll mid-gesture', () => {
|
|
833
|
+
const state = makeState( { zoom: 2 } );
|
|
834
|
+
const { controller } = createController( state );
|
|
835
|
+
const doc = createMockDocument();
|
|
836
|
+
const rect = createContainerRect();
|
|
837
|
+
|
|
838
|
+
controller.handleTouchStart(
|
|
839
|
+
createTouchEvent( [ { clientX: 100, clientY: 100 } ] ),
|
|
840
|
+
rect,
|
|
841
|
+
doc
|
|
842
|
+
);
|
|
843
|
+
|
|
844
|
+
const moveEvent = createTouchEvent( [
|
|
845
|
+
{ clientX: 150, clientY: 120 },
|
|
846
|
+
] );
|
|
847
|
+
doc._fire( 'touchmove', moveEvent );
|
|
848
|
+
|
|
849
|
+
expect( moveEvent.preventDefault ).toHaveBeenCalled();
|
|
850
|
+
} );
|
|
851
|
+
|
|
800
852
|
it( 'calls onGestureStart/onGestureEnd for single-finger pan', () => {
|
|
801
853
|
const state = makeState( { zoom: 2 } );
|
|
802
854
|
const onGestureStart = jest.fn();
|
|
@@ -888,6 +940,54 @@ describe( 'InteractionController', () => {
|
|
|
888
940
|
expect( actionMocks.setZoomAtPoint ).toHaveBeenCalled();
|
|
889
941
|
} );
|
|
890
942
|
|
|
943
|
+
it( 'keeps a repeated pinch zoom anchored to the pinch-start midpoint from a zoomed and panned state', () => {
|
|
944
|
+
let state = makeState( {
|
|
945
|
+
zoom: 2,
|
|
946
|
+
pan: { x: 0.1, y: -0.05 },
|
|
947
|
+
} );
|
|
948
|
+
actionMocks.setZoomAtPoint.mockImplementation( ( zoom, pan ) => {
|
|
949
|
+
state = { ...state, zoom, pan };
|
|
950
|
+
} );
|
|
951
|
+
const { controller } = createController( state, {
|
|
952
|
+
getState: () => state,
|
|
953
|
+
} );
|
|
954
|
+
const doc = createMockDocument();
|
|
955
|
+
const rect = createContainerRect();
|
|
956
|
+
|
|
957
|
+
controller.handleTouchStart(
|
|
958
|
+
createTouchEvent( [
|
|
959
|
+
{ clientX: 300, clientY: 180 },
|
|
960
|
+
{ clientX: 400, clientY: 180 },
|
|
961
|
+
] ),
|
|
962
|
+
rect,
|
|
963
|
+
doc
|
|
964
|
+
);
|
|
965
|
+
|
|
966
|
+
doc._fire(
|
|
967
|
+
'touchmove',
|
|
968
|
+
createTouchEvent( [
|
|
969
|
+
{ clientX: 275, clientY: 180 },
|
|
970
|
+
{ clientX: 425, clientY: 180 },
|
|
971
|
+
] )
|
|
972
|
+
);
|
|
973
|
+
doc._fire(
|
|
974
|
+
'touchmove',
|
|
975
|
+
createTouchEvent( [
|
|
976
|
+
{ clientX: 250, clientY: 180 },
|
|
977
|
+
{ clientX: 450, clientY: 180 },
|
|
978
|
+
] )
|
|
979
|
+
);
|
|
980
|
+
|
|
981
|
+
expect( actionMocks.setZoomAtPoint ).toHaveBeenCalledTimes( 2 );
|
|
982
|
+
const [ zoom, pan ] =
|
|
983
|
+
actionMocks.setZoomAtPoint.mock.calls[
|
|
984
|
+
actionMocks.setZoomAtPoint.mock.calls.length - 1
|
|
985
|
+
];
|
|
986
|
+
expect( zoom ).toBeCloseTo( 4 );
|
|
987
|
+
expect( pan.x ).toBeCloseTo( 0 );
|
|
988
|
+
expect( pan.y ).toBeCloseTo( -0.2 );
|
|
989
|
+
} );
|
|
990
|
+
|
|
891
991
|
it( 'calls onGestureStart for pinch, onGestureEnd on touchend', () => {
|
|
892
992
|
const state = makeState( { zoom: 1 } );
|
|
893
993
|
const onGestureStart = jest.fn();
|
|
@@ -5,11 +5,53 @@ import {
|
|
|
5
5
|
computeFreeResizeRect,
|
|
6
6
|
computeLockedResizeRect,
|
|
7
7
|
computeShiftLockedResizeRect,
|
|
8
|
+
getMinCropPixels,
|
|
8
9
|
type CropBounds,
|
|
9
10
|
type ResizeDragState,
|
|
10
11
|
} from '../stencil-math';
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_KEYBOARD_STEP,
|
|
14
|
+
MIN_CROP_PIXELS,
|
|
15
|
+
MIN_CROP_SCREEN_PX,
|
|
16
|
+
} from '../constants';
|
|
11
17
|
import type { Size } from '../types';
|
|
12
18
|
|
|
19
|
+
describe( 'getMinCropPixels — operable on-screen floor', () => {
|
|
20
|
+
it( 'returns the source-pixel hard floor when the image is shown large enough', () => {
|
|
21
|
+
const displayScale = ( MIN_CROP_SCREEN_PX / MIN_CROP_PIXELS ) * 1.1;
|
|
22
|
+
|
|
23
|
+
expect( getMinCropPixels( displayScale ) ).toBe( MIN_CROP_PIXELS );
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
it( 'raises the floor so the crop stays operable when the image is shown small', () => {
|
|
27
|
+
// A large image fit into a small window: ~0.2 CSS px per source px.
|
|
28
|
+
// The source-pixel floor would render too small on screen. The
|
|
29
|
+
// usability term (44 / 0.2 = 220 source px) must win.
|
|
30
|
+
expect( getMinCropPixels( 0.2 ) ).toBeCloseTo(
|
|
31
|
+
MIN_CROP_SCREEN_PX / 0.2,
|
|
32
|
+
5
|
|
33
|
+
);
|
|
34
|
+
expect( getMinCropPixels( 0.2 ) ).toBeGreaterThan( MIN_CROP_PIXELS );
|
|
35
|
+
} );
|
|
36
|
+
|
|
37
|
+
it( 'crosses over from usability floor to hard floor at displayScale = MIN_CROP_SCREEN_PX / MIN_CROP_PIXELS', () => {
|
|
38
|
+
const crossover = MIN_CROP_SCREEN_PX / MIN_CROP_PIXELS;
|
|
39
|
+
expect( getMinCropPixels( crossover ) ).toBeCloseTo(
|
|
40
|
+
MIN_CROP_PIXELS,
|
|
41
|
+
5
|
|
42
|
+
);
|
|
43
|
+
// Just below the crossover, the usability term exceeds the hard floor.
|
|
44
|
+
expect( getMinCropPixels( crossover * 0.99 ) ).toBeGreaterThan(
|
|
45
|
+
MIN_CROP_PIXELS
|
|
46
|
+
);
|
|
47
|
+
} );
|
|
48
|
+
|
|
49
|
+
it( 'falls back to the hard floor for a non-positive display scale', () => {
|
|
50
|
+
expect( getMinCropPixels( 0 ) ).toBe( MIN_CROP_PIXELS );
|
|
51
|
+
expect( getMinCropPixels( -1 ) ).toBe( MIN_CROP_PIXELS );
|
|
52
|
+
} );
|
|
53
|
+
} );
|
|
54
|
+
|
|
13
55
|
const FULL_BOUNDS: CropBounds = { minX: 0, minY: 0, maxX: 1, maxY: 1 };
|
|
14
56
|
|
|
15
57
|
describe( 'computeLockedResizeRect — driver-axis selection', () => {
|
|
@@ -111,6 +153,117 @@ describe( 'computeLockedResizeRect — driver-axis selection', () => {
|
|
|
111
153
|
expect( pixelW ).toBeCloseTo( 200, 5 );
|
|
112
154
|
expect( pixelH ).toBeCloseTo( 200, 5 );
|
|
113
155
|
} );
|
|
156
|
+
|
|
157
|
+
it( 'keeps pointer resize continuous near the pixel-motion threshold', () => {
|
|
158
|
+
const originalImageSize: Size = { width: 600, height: 400 };
|
|
159
|
+
const fullImageCrop = { x: 0, y: 0, width: 1, height: 1 };
|
|
160
|
+
const drag: ResizeDragState = {
|
|
161
|
+
handle: 'nw',
|
|
162
|
+
startX: 0,
|
|
163
|
+
startY: 0,
|
|
164
|
+
startRect: fullImageCrop,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const beforeThreshold = computeLockedResizeRect(
|
|
168
|
+
drag,
|
|
169
|
+
60,
|
|
170
|
+
-39.6,
|
|
171
|
+
originalImageSize,
|
|
172
|
+
FULL_BOUNDS,
|
|
173
|
+
1
|
|
174
|
+
);
|
|
175
|
+
const afterThreshold = computeLockedResizeRect(
|
|
176
|
+
drag,
|
|
177
|
+
60,
|
|
178
|
+
-40.4,
|
|
179
|
+
originalImageSize,
|
|
180
|
+
FULL_BOUNDS,
|
|
181
|
+
1
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
expect(
|
|
185
|
+
Math.abs( beforeThreshold.width - afterThreshold.width )
|
|
186
|
+
).toBeLessThan( 0.01 );
|
|
187
|
+
expect(
|
|
188
|
+
Math.abs( beforeThreshold.height - afterThreshold.height )
|
|
189
|
+
).toBeLessThan( 0.01 );
|
|
190
|
+
} );
|
|
191
|
+
|
|
192
|
+
it( 'shrinks a locked-ratio crop from horizontal keyboard movement', () => {
|
|
193
|
+
const squareImageSize: Size = { width: 500, height: 500 };
|
|
194
|
+
const lockedStartRect = { x: 0.1, y: 0.1, width: 0.8, height: 0.8 };
|
|
195
|
+
const drag: ResizeDragState = {
|
|
196
|
+
handle: 'nw',
|
|
197
|
+
startX: 0,
|
|
198
|
+
startY: 0,
|
|
199
|
+
startRect: lockedStartRect,
|
|
200
|
+
};
|
|
201
|
+
const rect = computeLockedResizeRect(
|
|
202
|
+
drag,
|
|
203
|
+
DEFAULT_KEYBOARD_STEP * squareImageSize.width,
|
|
204
|
+
0,
|
|
205
|
+
squareImageSize,
|
|
206
|
+
FULL_BOUNDS,
|
|
207
|
+
1,
|
|
208
|
+
undefined,
|
|
209
|
+
'width'
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
expect( rect.x ).toBeCloseTo(
|
|
213
|
+
lockedStartRect.x + DEFAULT_KEYBOARD_STEP,
|
|
214
|
+
5
|
|
215
|
+
);
|
|
216
|
+
expect( rect.y ).toBeCloseTo(
|
|
217
|
+
lockedStartRect.y + DEFAULT_KEYBOARD_STEP,
|
|
218
|
+
5
|
|
219
|
+
);
|
|
220
|
+
expect( rect.width ).toBeCloseTo(
|
|
221
|
+
lockedStartRect.width - DEFAULT_KEYBOARD_STEP,
|
|
222
|
+
5
|
|
223
|
+
);
|
|
224
|
+
expect( rect.height ).toBeCloseTo(
|
|
225
|
+
lockedStartRect.height - DEFAULT_KEYBOARD_STEP,
|
|
226
|
+
5
|
|
227
|
+
);
|
|
228
|
+
} );
|
|
229
|
+
|
|
230
|
+
it( 'shrinks a locked-ratio crop from vertical keyboard movement', () => {
|
|
231
|
+
const squareImageSize: Size = { width: 500, height: 500 };
|
|
232
|
+
const lockedStartRect = { x: 0.1, y: 0.1, width: 0.8, height: 0.8 };
|
|
233
|
+
const drag: ResizeDragState = {
|
|
234
|
+
handle: 'nw',
|
|
235
|
+
startX: 0,
|
|
236
|
+
startY: 0,
|
|
237
|
+
startRect: lockedStartRect,
|
|
238
|
+
};
|
|
239
|
+
const rect = computeLockedResizeRect(
|
|
240
|
+
drag,
|
|
241
|
+
0,
|
|
242
|
+
DEFAULT_KEYBOARD_STEP * squareImageSize.height,
|
|
243
|
+
squareImageSize,
|
|
244
|
+
FULL_BOUNDS,
|
|
245
|
+
1,
|
|
246
|
+
undefined,
|
|
247
|
+
'height'
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
expect( rect.x ).toBeCloseTo(
|
|
251
|
+
lockedStartRect.x + DEFAULT_KEYBOARD_STEP,
|
|
252
|
+
5
|
|
253
|
+
);
|
|
254
|
+
expect( rect.y ).toBeCloseTo(
|
|
255
|
+
lockedStartRect.y + DEFAULT_KEYBOARD_STEP,
|
|
256
|
+
5
|
|
257
|
+
);
|
|
258
|
+
expect( rect.width ).toBeCloseTo(
|
|
259
|
+
lockedStartRect.width - DEFAULT_KEYBOARD_STEP,
|
|
260
|
+
5
|
|
261
|
+
);
|
|
262
|
+
expect( rect.height ).toBeCloseTo(
|
|
263
|
+
lockedStartRect.height - DEFAULT_KEYBOARD_STEP,
|
|
264
|
+
5
|
|
265
|
+
);
|
|
266
|
+
} );
|
|
114
267
|
} );
|
|
115
268
|
|
|
116
269
|
const IMAGE: Size = { width: 1000, height: 500 };
|
|
@@ -193,6 +193,8 @@ export interface StencilProps {
|
|
|
193
193
|
aspectRatio?: number;
|
|
194
194
|
/** Whether the crop handles are shown for freeform resizing. */
|
|
195
195
|
freeformCrop?: boolean;
|
|
196
|
+
/** Whether resize handles should ignore pointer and keyboard input. */
|
|
197
|
+
isResizeDisabled?: boolean;
|
|
196
198
|
/** CSS transition string for settle animation. */
|
|
197
199
|
stencilTransition?: string;
|
|
198
200
|
/** Maximum crop rect bounds based on current zoom/rotation. */
|
|
@@ -210,4 +212,19 @@ export interface StencilProps {
|
|
|
210
212
|
* the source image dimensions. Omit to use the stencil's default.
|
|
211
213
|
*/
|
|
212
214
|
minCropSize?: Size;
|
|
215
|
+
/**
|
|
216
|
+
* Optional post-processor for freeform resize output. Hosts use this for
|
|
217
|
+
* display-gated behavior such as snapping visible pixel grids to source
|
|
218
|
+
* pixel boundaries.
|
|
219
|
+
*/
|
|
220
|
+
snapCropRect?: (
|
|
221
|
+
rect: NormalizedRect,
|
|
222
|
+
handle: HandlePosition
|
|
223
|
+
) => NormalizedRect;
|
|
224
|
+
/**
|
|
225
|
+
* Optional keyboard resize step in normalized space, per axis. Hosts use
|
|
226
|
+
* this when keyboard resize should follow the rendered image scale instead
|
|
227
|
+
* of the default percentage-based step.
|
|
228
|
+
*/
|
|
229
|
+
keyboardResizeStep?: Size;
|
|
213
230
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
@use "@wordpress/base-styles/colors" as *;
|
|
2
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
3
|
+
|
|
4
|
+
// Handle touch target size — used for the handle ::before hit area. The
|
|
5
|
+
// inner canvas inset must stay at least half this (22px) so the handles'
|
|
6
|
+
// reach isn't clipped by the root.
|
|
4
7
|
$handle-touch-target-size: 44px;
|
|
5
8
|
|
|
6
9
|
.wp-media-editor-image-editor {
|
|
@@ -15,12 +18,15 @@ $handle-touch-target-size: 44px;
|
|
|
15
18
|
// Inner gutter for resize handles. Handles use negative offsets and a
|
|
16
19
|
// touch target that extends past the crop edge; the root clips overflow
|
|
17
20
|
// (required for the dimming overlay's box-shadow trick), so a flush
|
|
18
|
-
// handle would be clipped. The inner `__canvas` wrapper is inset
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
+
// handle would be clipped. The inner `__canvas` wrapper is inset to
|
|
22
|
+
// reserve reach room on all sides while keeping the root as the clipping
|
|
23
|
+
// boundary. `$grid-unit-30` (24px) ≥ half the 44px touch target, so the
|
|
24
|
+
// handles still clear the edge.
|
|
21
25
|
&__canvas {
|
|
22
26
|
position: absolute;
|
|
23
|
-
inset:
|
|
27
|
+
inset: $grid-unit-30;
|
|
28
|
+
min-height: 100px;
|
|
29
|
+
min-width: 100px;
|
|
24
30
|
|
|
25
31
|
// Suppress the browser's default focus ring — the crop rectangle
|
|
26
32
|
// border provides the custom keyboard-focus indicator instead.
|
|
@@ -56,15 +62,16 @@ $handle-touch-target-size: 44px;
|
|
|
56
62
|
&__dimming {
|
|
57
63
|
position: absolute;
|
|
58
64
|
pointer-events: none;
|
|
59
|
-
/* Large shadow spread
|
|
60
|
-
|
|
61
|
-
so the user can see
|
|
62
|
-
|
|
65
|
+
/* Large shadow spread washes everything outside the crop area
|
|
66
|
+
toward the canvas grey ($gray-200). Slightly stronger at rest
|
|
67
|
+
for clear crop framing, lighter during drag so the user can see
|
|
68
|
+
where they're panning. */
|
|
69
|
+
box-shadow: 0 0 0 9999px rgba($gray-200, 0.6);
|
|
63
70
|
transition: box-shadow 0.15s ease;
|
|
64
71
|
}
|
|
65
72
|
|
|
66
73
|
&--dragging &__dimming {
|
|
67
|
-
box-shadow: 0 0 0 9999px rgba(
|
|
74
|
+
box-shadow: 0 0 0 9999px rgba($gray-200, 0.4);
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
&__grid {
|
|
@@ -122,7 +129,9 @@ $handle-touch-target-size: 44px;
|
|
|
122
129
|
|
|
123
130
|
&__stencil-rect {
|
|
124
131
|
position: absolute;
|
|
125
|
-
|
|
132
|
+
// Dark crop outline, matching the sidebar control/heading text so
|
|
133
|
+
// the crop boundary stays legible against the light grey wash.
|
|
134
|
+
border: 1px solid $gray-900;
|
|
126
135
|
box-sizing: border-box;
|
|
127
136
|
pointer-events: none;
|
|
128
137
|
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
@@ -152,8 +161,10 @@ $handle-touch-target-size: 44px;
|
|
|
152
161
|
position: absolute;
|
|
153
162
|
width: 12px;
|
|
154
163
|
height: 12px;
|
|
155
|
-
|
|
156
|
-
|
|
164
|
+
// Solid white fill with an accent-blue border so the handles read
|
|
165
|
+
// clearly against the light grey wash.
|
|
166
|
+
background: $white;
|
|
167
|
+
border: 1px solid var(--wp-admin-theme-color, #007cba);
|
|
157
168
|
border-radius: 50%;
|
|
158
169
|
box-sizing: border-box;
|
|
159
170
|
pointer-events: auto;
|
|
@@ -163,8 +174,8 @@ $handle-touch-target-size: 44px;
|
|
|
163
174
|
outline: none;
|
|
164
175
|
}
|
|
165
176
|
|
|
166
|
-
// Double ring (white inner + theme-color outer) for
|
|
167
|
-
//
|
|
177
|
+
// Double ring (white inner + theme-color outer) for a clear
|
|
178
|
+
// keyboard-focus state on the handle. Gated on the JS-controlled
|
|
168
179
|
// keyboard-active class so that mouse interactions after a
|
|
169
180
|
// keyboard session — e.g., clicking a handle to start a drag —
|
|
170
181
|
// don't leave the active ring stuck on the handle.
|