@wordpress/media-editor 0.10.1 → 0.11.1
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-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-form/index.cjs +12 -23
- package/build/components/media-form/index.cjs.map +3 -3
- package/build/image-editor/core/constants.cjs +3 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/stencil-math.cjs +11 -2
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +12 -7
- package/build/image-editor/react/components/cropper.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-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-form/index.mjs +12 -13
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +2 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/stencil-math.mjs +9 -1
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +12 -7
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-style/style-rtl.css +136 -47
- package/build-style/style.css +136 -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-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-editor-toolbar/index.d.ts +24 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts +18 -5
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +10 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +16 -3
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +108 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/package.json +25 -20
- package/src/components/media-editor/index.tsx +69 -77
- package/src/components/media-editor/style.scss +124 -4
- 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/constants.ts +11 -0
- package/src/image-editor/core/stencil-math.ts +23 -0
- package/src/image-editor/core/test/stencil-math.ts +39 -0
- package/src/image-editor/react/components/cropper.scss +28 -17
- package/src/image-editor/react/components/cropper.tsx +17 -7
- 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/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
|
@@ -21,71 +21,51 @@
|
|
|
21
21
|
min-height: 0;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
// Footer chrome —
|
|
25
|
-
//
|
|
26
|
-
// flex row
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
24
|
+
// Footer chrome — two layouts driven by `is-wide` / `is-narrow` modifier
|
|
25
|
+
// classes set from the media editor at the sidebar-collapse breakpoint.
|
|
26
|
+
// Wide is a single flex row (History | Cancel/Save); narrow stacks via
|
|
27
|
+
// `flex-direction: column` (image controls above the History |
|
|
28
|
+
// Cancel/Save row). Each layout has its own JSX tree (not `order`
|
|
29
|
+
// reshuffling, which the project's stylelint rule treats as an a11y red
|
|
30
|
+
// flag), so DOM order always matches visual order.
|
|
30
31
|
.media-editor-modal.components-modal__frame .media-editor-modal__footer {
|
|
31
32
|
flex-shrink: 0;
|
|
32
33
|
display: flex;
|
|
33
34
|
gap: $grid-unit-20;
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
// Borderless: sections are demarcated by the inset canvas panel and
|
|
36
|
+
// spacing, not divider lines. 16px top / 32px sides / 24px bottom.
|
|
37
|
+
padding: $grid-unit-20 $grid-unit-40 $grid-unit-30;
|
|
36
38
|
background: $white;
|
|
39
|
+
// Above the `.interface-interface-skeleton__sidebar` which has a z-index of 100000.
|
|
40
|
+
z-index: z-index(".media-editor-modal__footer");
|
|
37
41
|
|
|
38
42
|
&.is-wide {
|
|
39
43
|
flex-direction: row;
|
|
40
44
|
align-items: center;
|
|
41
45
|
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
.media-editor-modal__footer-toolbar {
|
|
47
|
-
flex: 1 1 0;
|
|
48
|
-
min-width: 0;
|
|
49
|
-
display: flex;
|
|
50
|
-
align-items: center;
|
|
51
|
-
justify-content: center;
|
|
52
|
-
gap: $grid-unit-10;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.media-editor-fine-rotation {
|
|
56
|
-
flex: 1 1 280px;
|
|
57
|
-
min-width: 0;
|
|
58
|
-
max-width: 360px;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.media-editor-transform-controls {
|
|
62
|
-
border-left: $border-width solid $gray-300;
|
|
63
|
-
padding-left: $grid-unit-15;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// `margin-left: auto` guarantees right alignment whether or not
|
|
67
|
-
// History / the toolbar is rendered (handles non-image
|
|
68
|
-
// attachments where only `FooterActions` is present).
|
|
46
|
+
// Panel mode: the footer holds only History (left) and
|
|
47
|
+
// Cancel/Save (right). `margin-left: auto` pins the actions to the
|
|
48
|
+
// right edge whether or not History renders (e.g. non-image
|
|
49
|
+
// attachments show only `FooterActions`).
|
|
69
50
|
.media-editor__footer-actions {
|
|
70
51
|
margin-left: auto;
|
|
71
52
|
}
|
|
72
53
|
}
|
|
73
54
|
|
|
74
|
-
&.is-medium,
|
|
75
55
|
&.is-narrow {
|
|
76
56
|
flex-direction: column;
|
|
77
57
|
}
|
|
78
58
|
|
|
79
|
-
// Narrow only:
|
|
80
|
-
&.is-narrow > .media-editor-
|
|
59
|
+
// Narrow only: image controls sit on their own row, centered.
|
|
60
|
+
&.is-narrow > .media-editor-image-controls {
|
|
81
61
|
align-self: center;
|
|
82
62
|
}
|
|
83
63
|
}
|
|
84
64
|
|
|
85
|
-
// Secondary row used by medium (History +
|
|
86
|
-
// narrow (History + Cancel/Save). `margin-left: auto` on the
|
|
65
|
+
// Secondary row used by medium (History + Image controls + Cancel/Save) and
|
|
66
|
+
// narrow (History + Cancel/Save). `margin-left: auto` on the image controls
|
|
87
67
|
// cluster and on Cancel/Save splits any free space — History gets the
|
|
88
|
-
// left edge, Cancel/Save the right edge, and the
|
|
68
|
+
// left edge, Cancel/Save the right edge, and the image controls (when
|
|
89
69
|
// present, i.e. medium only) approximately centers. Exact centering only
|
|
90
70
|
// holds when History and Cancel/Save have matching widths; in practice
|
|
91
71
|
// they're close enough that the offset is imperceptible.
|
|
@@ -95,12 +75,22 @@
|
|
|
95
75
|
align-items: center;
|
|
96
76
|
gap: $grid-unit-20;
|
|
97
77
|
|
|
98
|
-
.media-editor-
|
|
78
|
+
.media-editor-image-controls,
|
|
99
79
|
.media-editor__footer-actions {
|
|
100
80
|
margin-left: auto;
|
|
101
81
|
}
|
|
102
82
|
}
|
|
103
83
|
|
|
84
|
+
// Active (enabled) undo/redo icon buttons take the admin accent colour so
|
|
85
|
+
// they read as live alongside the Reset/Cancel/Save actions. Disabled
|
|
86
|
+
// buttons (rendered with `aria-disabled` via `accessibleWhenDisabled`)
|
|
87
|
+
// keep the default muted icon colour.
|
|
88
|
+
// NOTE: overrides @wordpress/components Button internals (`.components-button`,
|
|
89
|
+
// `.has-icon`), scoped to our history-actions wrapper. Update if renamed.
|
|
90
|
+
.media-editor__history-actions .components-button.has-icon:not([aria-disabled="true"]) {
|
|
91
|
+
color: var(--wp-admin-theme-color);
|
|
92
|
+
}
|
|
93
|
+
|
|
104
94
|
.media-editor-modal {
|
|
105
95
|
display: flex;
|
|
106
96
|
flex-direction: column;
|
|
@@ -6,7 +6,6 @@ import type { Form, Field } from '@wordpress/dataviews';
|
|
|
6
6
|
import { Spinner, __experimentalVStack as VStack } from '@wordpress/components';
|
|
7
7
|
import { VisuallyHidden } from '@wordpress/ui';
|
|
8
8
|
import { __ } from '@wordpress/i18n';
|
|
9
|
-
import { useMemo } from '@wordpress/element';
|
|
10
9
|
import type { ReactNode } from 'react';
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -14,7 +13,6 @@ import type { ReactNode } from 'react';
|
|
|
14
13
|
*/
|
|
15
14
|
import { useMediaEditorContext } from '../media-editor-provider';
|
|
16
15
|
import type { Media } from '../media-editor-provider';
|
|
17
|
-
import SidebarDatetimeView from './sidebar-datetime-view';
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* Props for MediaForm component.
|
|
@@ -41,18 +39,6 @@ export default function MediaForm( {
|
|
|
41
39
|
}: MediaFormProps ) {
|
|
42
40
|
const { media, fields, onChange } = useMediaEditorContext();
|
|
43
41
|
|
|
44
|
-
// Render readonly datetime fields compactly in the sidebar: date only,
|
|
45
|
-
// with the full datetime exposed on hover via Tooltip and `title`.
|
|
46
|
-
const formFields = useMemo(
|
|
47
|
-
() =>
|
|
48
|
-
fields.map( ( field: Field< Media > ) =>
|
|
49
|
-
field.type === 'datetime' && field.readOnly
|
|
50
|
-
? { ...field, render: SidebarDatetimeView }
|
|
51
|
-
: field
|
|
52
|
-
),
|
|
53
|
-
[ fields ]
|
|
54
|
-
);
|
|
55
|
-
|
|
56
42
|
if ( ! media || ! onChange ) {
|
|
57
43
|
return (
|
|
58
44
|
<div className="media-editor-form media-editor-form--loading">
|
|
@@ -61,18 +47,28 @@ export default function MediaForm( {
|
|
|
61
47
|
);
|
|
62
48
|
}
|
|
63
49
|
|
|
50
|
+
// Fields that use a regular (non-panel) layout, rendered at the top.
|
|
51
|
+
const regularFieldIds = [ 'title', 'alt_text', 'caption', 'description' ];
|
|
52
|
+
|
|
53
|
+
// Place the non-panel (regular layout) fields at the top of the array,
|
|
54
|
+
// with the remaining panel fields below.
|
|
55
|
+
const sortedFields = [
|
|
56
|
+
...fields.filter( ( field: Field< Media > ) =>
|
|
57
|
+
regularFieldIds.includes( field.id )
|
|
58
|
+
),
|
|
59
|
+
...fields.filter(
|
|
60
|
+
( field: Field< Media > ) => ! regularFieldIds.includes( field.id )
|
|
61
|
+
),
|
|
62
|
+
];
|
|
63
|
+
|
|
64
64
|
// Default form structure with panel layout
|
|
65
65
|
const defaultForm: Form = {
|
|
66
66
|
layout: {
|
|
67
67
|
type: 'panel',
|
|
68
68
|
},
|
|
69
|
-
fields:
|
|
69
|
+
fields: sortedFields.map( ( field: Field< Media > ) => {
|
|
70
70
|
// Use regular layout for main editable fields
|
|
71
|
-
if (
|
|
72
|
-
[ 'title', 'alt_text', 'caption', 'description' ].includes(
|
|
73
|
-
field.id
|
|
74
|
-
)
|
|
75
|
-
) {
|
|
71
|
+
if ( regularFieldIds.includes( field.id ) ) {
|
|
76
72
|
return {
|
|
77
73
|
id: field.id,
|
|
78
74
|
layout: {
|
|
@@ -96,7 +92,7 @@ export default function MediaForm( {
|
|
|
96
92
|
{ header }
|
|
97
93
|
<DataForm
|
|
98
94
|
data={ media }
|
|
99
|
-
fields={
|
|
95
|
+
fields={ fields }
|
|
100
96
|
form={ form }
|
|
101
97
|
onChange={ onChange }
|
|
102
98
|
/>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Discourage an orphaned "am/pm" (or other single-word widow) when a read-only
|
|
2
|
+
// value wraps in the narrow Details panel. Progressive enhancement: browsers
|
|
3
|
+
// without `text-wrap: pretty` simply wrap normally.
|
|
4
|
+
.media-editor-form .dataforms-layouts-panel__field-control {
|
|
5
|
+
text-wrap: pretty;
|
|
6
|
+
}
|
|
@@ -80,6 +80,12 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
80
80
|
|
|
81
81
|
.rotation-ruler__ticks {
|
|
82
82
|
position: absolute;
|
|
83
|
+
// The tick offset is applied as a JS-set inline `transform: translateX()`
|
|
84
|
+
// (see rotation-ruler/index.tsx), which rtlcss can't mirror. If rtlcss
|
|
85
|
+
// flipped this `left` to `right`, the anchor and the transform would
|
|
86
|
+
// disagree and the ticks would render off-screen in RTL. Keep it `left`
|
|
87
|
+
// so the two stay in sync; the strip is a symmetric number line anyway.
|
|
88
|
+
/*rtl:ignore*/
|
|
83
89
|
left: 50%;
|
|
84
90
|
top: 0;
|
|
85
91
|
display: block;
|
|
@@ -118,8 +124,9 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
118
124
|
// pointer while the SVG behind it transitions smoothly. The label box
|
|
119
125
|
// is sized to the number alone — the unit is positioned absolutely so
|
|
120
126
|
// it does not influence centering — and a fixed-width ::before
|
|
121
|
-
// pseudo-element provides the
|
|
122
|
-
// occludes the static labels directly
|
|
127
|
+
// pseudo-element provides the grey-fading-to-transparent mask (matching
|
|
128
|
+
// the canvas/ruler surface) that occludes the static labels directly
|
|
129
|
+
// behind.
|
|
123
130
|
.rotation-ruler__active-label {
|
|
124
131
|
position: absolute;
|
|
125
132
|
top: 0;
|
|
@@ -140,7 +147,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
|
|
|
140
147
|
width: 60px;
|
|
141
148
|
height: 100%;
|
|
142
149
|
transform: translateX(-50%);
|
|
143
|
-
background: linear-gradient(to right, transparent 0, $
|
|
150
|
+
background: linear-gradient(to right, transparent 0, $gray-200 12px, $gray-200 calc(100% - 12px), transparent 100%);
|
|
144
151
|
}
|
|
145
152
|
}
|
|
146
153
|
|
|
@@ -30,6 +30,17 @@ export const MAX_ZOOM = 10;
|
|
|
30
30
|
*/
|
|
31
31
|
export const MIN_CROP_PIXELS = 24;
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Minimum on-screen crop rect dimension in CSS pixels. The source-pixel
|
|
35
|
+
* floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large
|
|
36
|
+
* image fit into a small canvas it can render only a few CSS pixels wide —
|
|
37
|
+
* too small to grab the resize handles. This floor keeps the crop operable
|
|
38
|
+
* regardless of display scale; it binds when zoomed out and yields to the
|
|
39
|
+
* source-pixel floor once the image is shown large enough. Sized to one
|
|
40
|
+
* handle touch target (`$handle-touch-target-size` in `cropper.scss`).
|
|
41
|
+
*/
|
|
42
|
+
export const MIN_CROP_SCREEN_PX = 44;
|
|
43
|
+
|
|
33
44
|
/**
|
|
34
45
|
* Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.
|
|
35
46
|
* This could be made configurable as a prop to the Cropper component.
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
+
import { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';
|
|
4
5
|
import type { HandlePosition, NormalizedRect, Size } from './types';
|
|
5
6
|
|
|
6
7
|
export type { HandlePosition };
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the minimum crop dimension, in source-image pixels, for the current
|
|
11
|
+
* display scale.
|
|
12
|
+
*
|
|
13
|
+
* Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that
|
|
14
|
+
* avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that
|
|
15
|
+
* keeps the crop large enough to grab. The on-screen floor converted to source
|
|
16
|
+
* pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the
|
|
17
|
+
* larger of the two. When zoomed out (small `displayScale`) the on-screen floor
|
|
18
|
+
* dominates; once the image is shown large enough the source-pixel floor takes
|
|
19
|
+
* over.
|
|
20
|
+
*
|
|
21
|
+
* @param displayScale CSS pixels rendered per source pixel (fit scale × zoom).
|
|
22
|
+
* @return Minimum crop dimension in source-image pixels.
|
|
23
|
+
*/
|
|
24
|
+
export function getMinCropPixels( displayScale: number ): number {
|
|
25
|
+
if ( displayScale <= 0 ) {
|
|
26
|
+
return MIN_CROP_PIXELS;
|
|
27
|
+
}
|
|
28
|
+
return Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
/**
|
|
9
32
|
* Default minimum crop rect dimension in normalized space, used when no
|
|
10
33
|
* explicit per-axis minimum is supplied (e.g. before the source image
|
|
@@ -5,11 +5,50 @@ 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 { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from '../constants';
|
|
11
13
|
import type { Size } from '../types';
|
|
12
14
|
|
|
15
|
+
describe( 'getMinCropPixels — operable on-screen floor', () => {
|
|
16
|
+
it( 'returns the source-pixel hard floor when the image is shown large enough', () => {
|
|
17
|
+
// displayScale = 2 CSS px per source px (zoomed in). The usability
|
|
18
|
+
// term is 44 / 2 = 22 px, below the 24-source-px hard floor, so the
|
|
19
|
+
// hard floor wins.
|
|
20
|
+
expect( getMinCropPixels( 2 ) ).toBe( MIN_CROP_PIXELS );
|
|
21
|
+
} );
|
|
22
|
+
|
|
23
|
+
it( 'raises the floor so the crop stays operable when the image is shown small', () => {
|
|
24
|
+
// A large image fit into a small window: ~0.2 CSS px per source px.
|
|
25
|
+
// 24 source px would render as ~4.8 px on screen — unusable. The
|
|
26
|
+
// usability term (44 / 0.2 = 220 source px) must win.
|
|
27
|
+
expect( getMinCropPixels( 0.2 ) ).toBeCloseTo(
|
|
28
|
+
MIN_CROP_SCREEN_PX / 0.2,
|
|
29
|
+
5
|
|
30
|
+
);
|
|
31
|
+
expect( getMinCropPixels( 0.2 ) ).toBeGreaterThan( MIN_CROP_PIXELS );
|
|
32
|
+
} );
|
|
33
|
+
|
|
34
|
+
it( 'crosses over from usability floor to hard floor at displayScale = MIN_CROP_SCREEN_PX / MIN_CROP_PIXELS', () => {
|
|
35
|
+
const crossover = MIN_CROP_SCREEN_PX / MIN_CROP_PIXELS;
|
|
36
|
+
expect( getMinCropPixels( crossover ) ).toBeCloseTo(
|
|
37
|
+
MIN_CROP_PIXELS,
|
|
38
|
+
5
|
|
39
|
+
);
|
|
40
|
+
// Just below the crossover, the usability term exceeds the hard floor.
|
|
41
|
+
expect( getMinCropPixels( crossover * 0.99 ) ).toBeGreaterThan(
|
|
42
|
+
MIN_CROP_PIXELS
|
|
43
|
+
);
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
it( 'falls back to the hard floor for a non-positive display scale', () => {
|
|
47
|
+
expect( getMinCropPixels( 0 ) ).toBe( MIN_CROP_PIXELS );
|
|
48
|
+
expect( getMinCropPixels( -1 ) ).toBe( MIN_CROP_PIXELS );
|
|
49
|
+
} );
|
|
50
|
+
} );
|
|
51
|
+
|
|
13
52
|
const FULL_BOUNDS: CropBounds = { minX: 0, minY: 0, maxX: 1, maxY: 1 };
|
|
14
53
|
|
|
15
54
|
describe( 'computeLockedResizeRect — driver-axis selection', () => {
|
|
@@ -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.
|
|
@@ -32,7 +32,7 @@ import type {
|
|
|
32
32
|
import type { CropperController } from '../hooks/use-cropper-reducer';
|
|
33
33
|
import { getImageFit, getRotatedBBox } from '../../core/camera';
|
|
34
34
|
import { getImageCropBounds, getMinZoom } from '../../core/containment';
|
|
35
|
-
import {
|
|
35
|
+
import { getMinCropPixels } from '../../core/stencil-math';
|
|
36
36
|
import { computeInscribedRect } from '../../core/crop-rect';
|
|
37
37
|
import { useInteraction } from '../hooks/use-interaction';
|
|
38
38
|
import { useTransformStyle } from '../hooks/use-transform-style';
|
|
@@ -275,6 +275,11 @@ function CropperInner(
|
|
|
275
275
|
// floor scales with `zoom` to keep the source-pixel floor constant.
|
|
276
276
|
// Without this, SETTLE_CROP zooms in proportional to the shrink and
|
|
277
277
|
// successive drags can crop arbitrarily small.
|
|
278
|
+
//
|
|
279
|
+
// The source-pixel floor is resolved per display scale so the crop
|
|
280
|
+
// stays grabbable: a large image fit into a small canvas would render
|
|
281
|
+
// the 24px floor only a few CSS pixels wide. `elementSize.width /
|
|
282
|
+
// naturalWidth` is the fit scale; × zoom gives CSS px per source px.
|
|
278
283
|
const minCropSize: Size | undefined = useMemo( () => {
|
|
279
284
|
if ( naturalWidth <= 0 || naturalHeight <= 0 ) {
|
|
280
285
|
return undefined;
|
|
@@ -285,14 +290,19 @@ function CropperInner(
|
|
|
285
290
|
naturalHeight,
|
|
286
291
|
snapRotation
|
|
287
292
|
);
|
|
293
|
+
const displayScale = ( elementSize.width / naturalWidth ) * state.zoom;
|
|
294
|
+
const minPixels = getMinCropPixels( displayScale );
|
|
288
295
|
return {
|
|
289
|
-
width: Math.min( 1, (
|
|
290
|
-
height: Math.min(
|
|
291
|
-
1,
|
|
292
|
-
( MIN_CROP_PIXELS * state.zoom ) / bbox.height
|
|
293
|
-
),
|
|
296
|
+
width: Math.min( 1, ( minPixels * state.zoom ) / bbox.width ),
|
|
297
|
+
height: Math.min( 1, ( minPixels * state.zoom ) / bbox.height ),
|
|
294
298
|
};
|
|
295
|
-
}, [
|
|
299
|
+
}, [
|
|
300
|
+
naturalWidth,
|
|
301
|
+
naturalHeight,
|
|
302
|
+
state.rotation,
|
|
303
|
+
state.zoom,
|
|
304
|
+
elementSize.width,
|
|
305
|
+
] );
|
|
296
306
|
|
|
297
307
|
// Report the rendered image size to the controller. Composite
|
|
298
308
|
// controllers need it to compute aspect-ratio reshapes from the
|
package/src/style.scss
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
@use "./components/media-preview/style.scss" as *;
|
|
3
3
|
@use "./image-editor/style.scss" as *;
|
|
4
4
|
@use "./components/media-editor/style.scss" as *;
|
|
5
|
+
@use "./components/media-form/style.scss" as *;
|
|
5
6
|
@use "./components/media-editor-modal/style.scss" as *;
|
|
6
7
|
@use "./components/media-editor-canvas/style.scss" as *;
|
|
7
|
-
@use "./components/media-editor-
|
|
8
|
+
@use "./components/media-editor-image-controls/style.scss" as *;
|
|
8
9
|
@use "./components/media-editor-keyboard-shortcuts-modal/style.scss" as *;
|
|
9
10
|
@use "./components/rotation-ruler/style.scss" as *;
|