@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.
Files changed (85) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/components/media-editor/index.cjs +41 -51
  3. package/build/components/media-editor/index.cjs.map +3 -3
  4. package/build/components/media-editor-crop-panel/index.cjs +15 -45
  5. package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
  6. package/build/components/media-editor-fine-rotation/index.cjs.map +2 -2
  7. package/build/components/media-editor-image-controls/index.cjs +230 -0
  8. package/build/components/media-editor-image-controls/index.cjs.map +7 -0
  9. package/build/components/media-form/index.cjs +12 -23
  10. package/build/components/media-form/index.cjs.map +3 -3
  11. package/build/image-editor/core/constants.cjs +3 -0
  12. package/build/image-editor/core/constants.cjs.map +2 -2
  13. package/build/image-editor/core/stencil-math.cjs +11 -2
  14. package/build/image-editor/core/stencil-math.cjs.map +2 -2
  15. package/build/image-editor/react/components/cropper.cjs +12 -7
  16. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  17. package/build-module/components/media-editor/index.mjs +41 -51
  18. package/build-module/components/media-editor/index.mjs.map +2 -2
  19. package/build-module/components/media-editor-crop-panel/index.mjs +8 -51
  20. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  21. package/build-module/components/media-editor-fine-rotation/index.mjs.map +2 -2
  22. package/build-module/components/media-editor-image-controls/index.mjs +221 -0
  23. package/build-module/components/media-editor-image-controls/index.mjs.map +7 -0
  24. package/build-module/components/media-form/index.mjs +12 -13
  25. package/build-module/components/media-form/index.mjs.map +2 -2
  26. package/build-module/image-editor/core/constants.mjs +2 -0
  27. package/build-module/image-editor/core/constants.mjs.map +2 -2
  28. package/build-module/image-editor/core/stencil-math.mjs +9 -1
  29. package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
  30. package/build-module/image-editor/react/components/cropper.mjs +12 -7
  31. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  32. package/build-style/style-rtl.css +136 -47
  33. package/build-style/style.css +136 -46
  34. package/build-types/components/media-editor/index.d.ts +6 -7
  35. package/build-types/components/media-editor/index.d.ts.map +1 -1
  36. package/build-types/components/media-editor-crop-panel/index.d.ts +11 -6
  37. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  38. package/build-types/components/media-editor-fine-rotation/index.d.ts +4 -3
  39. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  40. package/build-types/components/media-editor-image-controls/index.d.ts +46 -0
  41. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -0
  42. package/build-types/components/media-editor-toolbar/index.d.ts +24 -0
  43. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
  44. package/build-types/components/media-editor-transform-controls/index.d.ts +18 -5
  45. package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -1
  46. package/build-types/components/media-form/index.d.ts.map +1 -1
  47. package/build-types/image-editor/core/constants.d.ts +10 -0
  48. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  49. package/build-types/image-editor/core/stencil-math.d.ts +16 -3
  50. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
  51. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  52. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +108 -0
  53. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
  54. package/package.json +25 -20
  55. package/src/components/media-editor/index.tsx +69 -77
  56. package/src/components/media-editor/style.scss +124 -4
  57. package/src/components/media-editor-crop-panel/index.tsx +16 -62
  58. package/src/components/media-editor-crop-panel/test/index.tsx +25 -41
  59. package/src/components/media-editor-fine-rotation/index.tsx +4 -3
  60. package/src/components/media-editor-image-controls/index.tsx +262 -0
  61. package/src/components/media-editor-image-controls/style.scss +48 -0
  62. package/src/components/media-editor-image-controls/test/index.tsx +150 -0
  63. package/src/components/media-editor-modal/style.scss +32 -42
  64. package/src/components/media-form/index.tsx +17 -21
  65. package/src/components/media-form/style.scss +6 -0
  66. package/src/components/rotation-ruler/style.scss +10 -3
  67. package/src/image-editor/core/constants.ts +11 -0
  68. package/src/image-editor/core/stencil-math.ts +23 -0
  69. package/src/image-editor/core/test/stencil-math.ts +39 -0
  70. package/src/image-editor/react/components/cropper.scss +28 -17
  71. package/src/image-editor/react/components/cropper.tsx +17 -7
  72. package/src/style.scss +2 -1
  73. package/tsconfig.tsbuildinfo +1 -1
  74. package/build/components/media-editor-transform-controls/index.cjs +0 -84
  75. package/build/components/media-editor-transform-controls/index.cjs.map +0 -7
  76. package/build/components/media-form/sidebar-datetime-view.cjs +0 -53
  77. package/build/components/media-form/sidebar-datetime-view.cjs.map +0 -7
  78. package/build-module/components/media-editor-transform-controls/index.mjs +0 -68
  79. package/build-module/components/media-editor-transform-controls/index.mjs.map +0 -7
  80. package/build-module/components/media-form/sidebar-datetime-view.mjs +0 -32
  81. package/build-module/components/media-form/sidebar-datetime-view.mjs.map +0 -7
  82. package/src/components/media-editor-transform-controls/index.tsx +0 -70
  83. package/src/components/media-editor-transform-controls/style.scss +0 -8
  84. package/src/components/media-form/sidebar-datetime-view.tsx +0 -47
  85. package/src/components/media-form/test/sidebar-datetime-view.test.tsx +0 -96
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/media-editor/src/components/media-editor-image-controls/index.tsx
21
+ var media_editor_image_controls_exports = {};
22
+ __export(media_editor_image_controls_exports, {
23
+ DEFAULT_ZOOM_FACTOR: () => DEFAULT_ZOOM_FACTOR,
24
+ default: () => MediaEditorImageControls
25
+ });
26
+ module.exports = __toCommonJS(media_editor_image_controls_exports);
27
+ var import_components = require("@wordpress/components");
28
+ var import_i18n = require("@wordpress/i18n");
29
+ var import_icons = require("@wordpress/icons");
30
+ var import_state = require("../../state/index.cjs");
31
+ var import_constants = require("../../image-editor/core/constants.cjs");
32
+ var import_containment = require("../../image-editor/core/containment.cjs");
33
+ var import_use_crop_options = require("../media-editor/use-crop-options.cjs");
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var DEFAULT_ZOOM_FACTOR = 1.2;
36
+ function MediaEditorImageControls({
37
+ withLabels = false,
38
+ showAspectRatioControl = false,
39
+ aspectRatioPresets,
40
+ zoomFactor = DEFAULT_ZOOM_FACTOR
41
+ }) {
42
+ const { state, setFlip, snapRotate90, setZoom } = (0, import_state.useMediaEditor)();
43
+ const { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } = (0, import_use_crop_options.useCropOptions)({ aspectRatioPresets });
44
+ const hasAspectRatioControl = !withLabels && showAspectRatioControl;
45
+ const minZoom = (0, import_containment.getMinZoom)(state);
46
+ const zoomByFactor = (factor) => {
47
+ setZoom(
48
+ Math.min(import_constants.MAX_ZOOM, Math.max(minZoom, state.zoom * factor))
49
+ );
50
+ };
51
+ const rotateButtons = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
52
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
53
+ import_components.Button,
54
+ {
55
+ size: "compact",
56
+ icon: import_icons.rotateLeft,
57
+ label: (0, import_i18n.__)("Rotate 90\xB0 counter-clockwise"),
58
+ showTooltip: true,
59
+ onClick: () => snapRotate90(-1)
60
+ }
61
+ ),
62
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
63
+ import_components.Button,
64
+ {
65
+ size: "compact",
66
+ icon: import_icons.rotateRight,
67
+ label: (0, import_i18n.__)("Rotate 90\xB0 clockwise"),
68
+ showTooltip: true,
69
+ onClick: () => snapRotate90(1)
70
+ }
71
+ )
72
+ ] });
73
+ const flipButtons = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
74
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
75
+ import_components.Button,
76
+ {
77
+ size: "compact",
78
+ icon: import_icons.flipHorizontal,
79
+ label: (0, import_i18n.__)("Flip horizontal"),
80
+ showTooltip: true,
81
+ isPressed: state.flip.horizontal,
82
+ onClick: () => setFlip({
83
+ horizontal: !state.flip.horizontal,
84
+ vertical: state.flip.vertical
85
+ })
86
+ }
87
+ ),
88
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
89
+ import_components.Button,
90
+ {
91
+ size: "compact",
92
+ icon: import_icons.flipVertical,
93
+ label: (0, import_i18n.__)("Flip vertical"),
94
+ showTooltip: true,
95
+ isPressed: state.flip.vertical,
96
+ onClick: () => setFlip({
97
+ horizontal: state.flip.horizontal,
98
+ vertical: !state.flip.vertical
99
+ })
100
+ }
101
+ )
102
+ ] });
103
+ const zoomButtons = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
104
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
105
+ import_components.Button,
106
+ {
107
+ size: "compact",
108
+ icon: import_icons.plus,
109
+ label: (0, import_i18n.__)("Zoom in"),
110
+ showTooltip: true,
111
+ disabled: state.zoom >= import_constants.MAX_ZOOM,
112
+ accessibleWhenDisabled: true,
113
+ onClick: () => zoomByFactor(zoomFactor)
114
+ }
115
+ ),
116
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
117
+ import_components.Button,
118
+ {
119
+ size: "compact",
120
+ icon: import_icons.lineSolid,
121
+ label: (0, import_i18n.__)("Zoom out"),
122
+ showTooltip: true,
123
+ disabled: state.zoom <= minZoom,
124
+ accessibleWhenDisabled: true,
125
+ onClick: () => zoomByFactor(1 / zoomFactor)
126
+ }
127
+ )
128
+ ] });
129
+ const aspectRatioDropdown = hasAspectRatioControl ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
130
+ import_components.DropdownMenu,
131
+ {
132
+ icon: import_icons.aspectRatio,
133
+ label: (0, import_i18n.__)("Aspect ratio"),
134
+ popoverProps: { placement: "top" },
135
+ toggleProps: { size: "compact" },
136
+ children: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { label: (0, import_i18n.__)("Aspect ratio"), children: aspectRatioOptions.map((preset) => {
137
+ const value = preset.value.toString();
138
+ const isSelected = value === aspectRatioValue;
139
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
140
+ import_components.MenuItem,
141
+ {
142
+ role: "menuitemradio",
143
+ isSelected,
144
+ icon: isSelected ? import_icons.check : void 0,
145
+ onClick: () => {
146
+ setAspectRatioValue(value);
147
+ onClose();
148
+ },
149
+ children: preset.label
150
+ },
151
+ value
152
+ );
153
+ }) })
154
+ }
155
+ ) : null;
156
+ if (withLabels) {
157
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-image-controls is-stacked", children: [
158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-image-controls__transforms", children: [
159
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
160
+ "div",
161
+ {
162
+ className: "media-editor-image-controls__group",
163
+ role: "group",
164
+ "aria-label": (0, import_i18n.__)("Rotate"),
165
+ children: [
166
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
167
+ "span",
168
+ {
169
+ className: "media-editor-image-controls__label",
170
+ "aria-hidden": "true",
171
+ children: (0, import_i18n.__)("Rotate")
172
+ }
173
+ ),
174
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-image-controls__buttons", children: rotateButtons })
175
+ ]
176
+ }
177
+ ),
178
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
179
+ "div",
180
+ {
181
+ className: "media-editor-image-controls__group",
182
+ role: "group",
183
+ "aria-label": (0, import_i18n.__)("Flip"),
184
+ children: [
185
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
186
+ "span",
187
+ {
188
+ className: "media-editor-image-controls__label",
189
+ "aria-hidden": "true",
190
+ children: (0, import_i18n.__)("Flip")
191
+ }
192
+ ),
193
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-image-controls__buttons", children: flipButtons })
194
+ ]
195
+ }
196
+ )
197
+ ] }),
198
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
199
+ "div",
200
+ {
201
+ className: "media-editor-image-controls__group",
202
+ role: "group",
203
+ "aria-label": (0, import_i18n.__)("Zoom"),
204
+ children: [
205
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
206
+ "span",
207
+ {
208
+ className: "media-editor-image-controls__label",
209
+ "aria-hidden": "true",
210
+ children: (0, import_i18n.__)("Zoom")
211
+ }
212
+ ),
213
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-image-controls__buttons", children: zoomButtons })
214
+ ]
215
+ }
216
+ )
217
+ ] });
218
+ }
219
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-image-controls", children: [
220
+ rotateButtons,
221
+ flipButtons,
222
+ zoomButtons,
223
+ aspectRatioDropdown
224
+ ] });
225
+ }
226
+ // Annotate the CommonJS export names for ESM import in node:
227
+ 0 && (module.exports = {
228
+ DEFAULT_ZOOM_FACTOR
229
+ });
230
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/media-editor-image-controls/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport {\n\taspectRatio as aspectRatioIcon,\n\tcheck,\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tlineSolid,\n\tplus,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../../state';\nimport {\n\tMAX_ZOOM,\n\ttype AspectRatioPreset,\n} from '../../image-editor/core/constants';\nimport { getMinZoom } from '../../image-editor/core/containment';\nimport { useCropOptions } from '../media-editor/use-crop-options';\n\n/**\n * Default zoom factor per +/- click. Zooming is geometric, so a fixed\n * multiplier \u2014 rather than an additive step \u2014 makes each click feel like the\n * same amount of zoom at any level (an additive `+0.1` is a 10% jump at 1\u00D7 but\n * a ~1% nudge at 10\u00D7). `1.2` is ~+20% per click. Overridable via the\n * `zoomFactor` prop.\n */\nexport const DEFAULT_ZOOM_FACTOR = 1.2;\n\nexport interface MediaEditorImageControlsProps {\n\t/**\n\t * When `true`, render rotate, flip and zoom as labelled groups \u2014 the Crop\n\t * panel layout used on wide viewports. When `false` (default), render a\n\t * single flat row of icon buttons \u2014 the footer layout used at narrower\n\t * widths.\n\t */\n\twithLabels?: boolean;\n\t/**\n\t * When `true`, include an aspect-ratio dropdown in the flat toolbar.\n\t * Omitted from the labelled panel layout because the Crop panel already\n\t * renders the full aspect-ratio select control.\n\t */\n\tshowAspectRatioControl?: boolean;\n\t/** Optional caller-supplied aspect-ratio presets. */\n\taspectRatioPresets?: AspectRatioPreset[];\n\t/**\n\t * Multiplier applied to the zoom per +/- click \u2014 zoom in multiplies by it,\n\t * zoom out divides by it. Must be greater than 1. Defaults to\n\t * `DEFAULT_ZOOM_FACTOR` (1.2).\n\t */\n\tzoomFactor?: number;\n}\n\n/**\n * Image editing controls placed independently per viewport: on wide viewports\n * rotate/flip/zoom render inside the Crop panel (`withLabels`), and at narrower\n * widths they fall back into the footer toolbar (flat row), where the\n * aspect-ratio dropdown can also be shown.\n *\n * @param props\n * @param props.withLabels\n * @param props.showAspectRatioControl\n * @param props.aspectRatioPresets\n * @param props.zoomFactor\n */\nexport default function MediaEditorImageControls( {\n\twithLabels = false,\n\tshowAspectRatioControl = false,\n\taspectRatioPresets,\n\tzoomFactor = DEFAULT_ZOOM_FACTOR,\n}: MediaEditorImageControlsProps ) {\n\tconst { state, setFlip, snapRotate90, setZoom } = useMediaEditor();\n\tconst { aspectRatioValue, setAspectRatioValue, aspectRatioOptions } =\n\t\tuseCropOptions( { aspectRatioPresets } );\n\tconst hasAspectRatioControl = ! withLabels && showAspectRatioControl;\n\tconst minZoom = getMinZoom( state );\n\tconst zoomByFactor = ( factor: number ) => {\n\t\tsetZoom(\n\t\t\tMath.min( MAX_ZOOM, Math.max( minZoom, state.zoom * factor ) )\n\t\t);\n\t};\n\n\tconst rotateButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateLeft }\n\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ rotateRight }\n\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst flipButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipHorizontal }\n\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ flipVertical }\n\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\tonClick={ () =>\n\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t} )\n\t\t\t\t}\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst zoomButtons = (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ plus }\n\t\t\t\tlabel={ __( 'Zoom in' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ state.zoom >= MAX_ZOOM }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( zoomFactor ) }\n\t\t\t/>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\ticon={ lineSolid }\n\t\t\t\tlabel={ __( 'Zoom out' ) }\n\t\t\t\tshowTooltip\n\t\t\t\tdisabled={ state.zoom <= minZoom }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tonClick={ () => zoomByFactor( 1 / zoomFactor ) }\n\t\t\t/>\n\t\t</>\n\t);\n\n\tconst aspectRatioDropdown = hasAspectRatioControl ? (\n\t\t<DropdownMenu\n\t\t\ticon={ aspectRatioIcon }\n\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\tpopoverProps={ { placement: 'top' } }\n\t\t\ttoggleProps={ { size: 'compact' } }\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<MenuGroup label={ __( 'Aspect ratio' ) }>\n\t\t\t\t\t{ aspectRatioOptions.map( ( preset ) => {\n\t\t\t\t\t\tconst value = preset.value.toString();\n\t\t\t\t\t\tconst isSelected = value === aspectRatioValue;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tkey={ value }\n\t\t\t\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\t\ticon={ isSelected ? check : undefined }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tsetAspectRatioValue( value );\n\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ preset.label }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t);\n\t\t\t\t\t} ) }\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t) : null;\n\n\tif ( withLabels ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-image-controls is-stacked\">\n\t\t\t\t<div className=\"media-editor-image-controls__transforms\">\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Rotate' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Rotate' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ rotateButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\t\trole=\"group\"\n\t\t\t\t\t\taria-label={ __( 'Flip' ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Flip' ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t\t{ flipButtons }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div\n\t\t\t\t\tclassName=\"media-editor-image-controls__group\"\n\t\t\t\t\trole=\"group\"\n\t\t\t\t\taria-label={ __( 'Zoom' ) }\n\t\t\t\t>\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"media-editor-image-controls__label\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Zoom' ) }\n\t\t\t\t\t</span>\n\t\t\t\t\t<div className=\"media-editor-image-controls__buttons\">\n\t\t\t\t\t\t{ zoomButtons }\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-image-controls\">\n\t\t\t{ rotateButtons }\n\t\t\t{ flipButtons }\n\t\t\t{ zoomButtons }\n\t\t\t{ aspectRatioDropdown }\n\t\t</div>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAKO;AACP,kBAAmB;AACnB,mBASO;AAKP,mBAA+B;AAC/B,uBAGO;AACP,yBAA2B;AAC3B,8BAA+B;AAiE7B;AAxDK,IAAM,sBAAsB;AAsCpB,SAAR,yBAA2C;AAAA,EACjD,aAAa;AAAA,EACb,yBAAyB;AAAA,EACzB;AAAA,EACA,aAAa;AACd,GAAmC;AAClC,QAAM,EAAE,OAAO,SAAS,cAAc,QAAQ,QAAI,6BAAe;AACjE,QAAM,EAAE,kBAAkB,qBAAqB,mBAAmB,QACjE,wCAAgB,EAAE,mBAAmB,CAAE;AACxC,QAAM,wB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AI,QAAS;AAAA;AAAA,cAChB;AAAA,cACA,4CAAC,SAAI,WAAU,wCACZ,yBACH;AAAA;AAAA;AAAA,QACD;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,MAAK;AAAA,YACL,kBAAa,gBAAI,MAAO;AAAA,YAExB;AAAA;AAAA,gBAAC;AAAA;AAAA,kBACA,WAAU;AAAA,kBACV,eAAY;AAAA,kBAEV,8BAAI,MAAO;AAAA;AAAA,cACd;AAAA,cACA,4CAAC,SAAI,WAAU,wCACZ,uBACH;AAAA;AAAA;AAAA,QACD;AAAA,SACD;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACA,WAAU;AAAA,UACV,MAAK;AAAA,UACL,kBAAa,gBAAI,MAAO;AAAA,UAExB;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,WAAU;AAAA,gBACV,eAAY;AAAA,gBAEV,8BAAI,MAAO;AAAA;AAAA,YACd;AAAA,YACA,4CAAC,SAAI,WAAU,wCACZ,uBACH;AAAA;AAAA;AAAA,MACD;AAAA,OACD;AAAA,EAEF;AAEA,SACC,6CAAC,SAAI,WAAU,+BACZ;AAAA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,KACH;AAEF;",
6
+ "names": ["aspectRatioIcon"]
7
+ }
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // packages/media-editor/src/components/media-form/index.tsx
@@ -37,32 +27,31 @@ var import_dataviews = require("@wordpress/dataviews");
37
27
  var import_components = require("@wordpress/components");
38
28
  var import_ui = require("@wordpress/ui");
39
29
  var import_i18n = require("@wordpress/i18n");
40
- var import_element = require("@wordpress/element");
41
30
  var import_media_editor_provider = require("../media-editor-provider/index.cjs");
42
- var import_sidebar_datetime_view = __toESM(require("./sidebar-datetime-view.cjs"));
43
31
  var import_jsx_runtime = require("react/jsx-runtime");
44
32
  function MediaForm({
45
33
  form: formOverrides,
46
34
  header
47
35
  }) {
48
36
  const { media, fields, onChange } = (0, import_media_editor_provider.useMediaEditorContext)();
49
- const formFields = (0, import_element.useMemo)(
50
- () => fields.map(
51
- (field) => field.type === "datetime" && field.readOnly ? { ...field, render: import_sidebar_datetime_view.default } : field
52
- ),
53
- [fields]
54
- );
55
37
  if (!media || !onChange) {
56
38
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-form media-editor-form--loading", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) });
57
39
  }
40
+ const regularFieldIds = ["title", "alt_text", "caption", "description"];
41
+ const sortedFields = [
42
+ ...fields.filter(
43
+ (field) => regularFieldIds.includes(field.id)
44
+ ),
45
+ ...fields.filter(
46
+ (field) => !regularFieldIds.includes(field.id)
47
+ )
48
+ ];
58
49
  const defaultForm = {
59
50
  layout: {
60
51
  type: "panel"
61
52
  },
62
- fields: fields.map((field) => {
63
- if (["title", "alt_text", "caption", "description"].includes(
64
- field.id
65
- )) {
53
+ fields: sortedFields.map((field) => {
54
+ if (regularFieldIds.includes(field.id)) {
66
55
  return {
67
56
  id: field.id,
68
57
  layout: {
@@ -82,7 +71,7 @@ function MediaForm({
82
71
  import_dataviews.DataForm,
83
72
  {
84
73
  data: media,
85
- fields: formFields,
74
+ fields,
86
75
  form,
87
76
  onChange
88
77
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/media-form/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DataForm } from '@wordpress/dataviews';\nimport type { Form, Field } from '@wordpress/dataviews';\nimport { Spinner, __experimentalVStack as VStack } from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport type { ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport SidebarDatetimeView from './sidebar-datetime-view';\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst { media, fields, onChange } = useMediaEditorContext();\n\n\t// Render readonly datetime fields compactly in the sidebar: date only,\n\t// with the full datetime exposed on hover via Tooltip and `title`.\n\tconst formFields = useMemo(\n\t\t() =>\n\t\t\tfields.map( ( field: Field< Media > ) =>\n\t\t\t\tfield.type === 'datetime' && field.readOnly\n\t\t\t\t\t? { ...field, render: SidebarDatetimeView }\n\t\t\t\t\t: field\n\t\t\t),\n\t\t[ fields ]\n\t);\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Default form structure with panel layout\n\tconst defaultForm: Form = {\n\t\tlayout: {\n\t\t\ttype: 'panel',\n\t\t},\n\t\tfields: fields.map( ( field: Field< Media > ) => {\n\t\t\t// Use regular layout for main editable fields\n\t\t\tif (\n\t\t\t\t[ 'title', 'alt_text', 'caption', 'description' ].includes(\n\t\t\t\t\tfield.id\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\tid: field.id,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'top',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field.id;\n\t\t} ),\n\t};\n\n\tconst form = formOverrides || defaultForm;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ formFields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAyB;AAEzB,wBAAwD;AACxD,gBAA+B;AAC/B,kBAAmB;AACnB,qBAAwB;AAMxB,mCAAsC;AAEtC,mCAAgC;AA0C5B;AArBW,SAAR,UAA4B;AAAA,EAClC,MAAM;AAAA,EACN;AACD,GAAoB;AACnB,QAAM,EAAE,OAAO,QAAQ,SAAS,QAAI,oDAAsB;AAI1D,QAAM,iBAAa;AAAA,IAClB,MACC,OAAO;AAAA,MAAK,CAAE,UACb,MAAM,SAAS,cAAc,MAAM,WAChC,EAAE,GAAG,OAAO,QAAQ,6BAAAA,QAAoB,IACxC;AAAA,IACJ;AAAA,IACD,CAAE,MAAO;AAAA,EACV;AAEA,MAAK,CAAE,SAAS,CAAE,UAAW;AAC5B,WACC,4CAAC,SAAI,WAAU,gDACd,sDAAC,6BAAQ,GACV;AAAA,EAEF;AAGA,QAAM,cAAoB;AAAA,IACzB,QAAQ;AAAA,MACP,MAAM;AAAA,IACP;AAAA,IACA,QAAQ,OAAO,IAAK,CAAE,UAA2B;AAEhD,UACC,CAAE,SAAS,YAAY,WAAW,aAAc,EAAE;AAAA,QACjD,MAAM;AAAA,MACP,GACC;AACD,eAAO;AAAA,UACN,IAAI,MAAM;AAAA,UACV,QAAQ;AAAA,YACP,MAAM;AAAA,YACN,eAAe;AAAA,UAChB;AAAA,QACD;AAAA,MACD;AACA,aAAO,MAAM;AAAA,IACd,CAAE;AAAA,EACH;AAEA,QAAM,OAAO,iBAAiB;AAE9B,SACC,4CAAC,SAAI,WAAU,qBACd,uDAAC,kBAAAC,sBAAA,EAAO,SAAU,GACjB;AAAA,gDAAC,4BAAe,QAAS,4CAAC,QAAG,GAC1B,8BAAI,eAAgB,GACvB;AAAA,IACE;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP,QAAS;AAAA,QACT;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
6
- "names": ["SidebarDatetimeView", "VStack"]
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { DataForm } from '@wordpress/dataviews';\nimport type { Form, Field } from '@wordpress/dataviews';\nimport { Spinner, __experimentalVStack as VStack } from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst { media, fields, onChange } = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Fields that use a regular (non-panel) layout, rendered at the top.\n\tconst regularFieldIds = [ 'title', 'alt_text', 'caption', 'description' ];\n\n\t// Place the non-panel (regular layout) fields at the top of the array,\n\t// with the remaining panel fields below.\n\tconst sortedFields = [\n\t\t...fields.filter( ( field: Field< Media > ) =>\n\t\t\tregularFieldIds.includes( field.id )\n\t\t),\n\t\t...fields.filter(\n\t\t\t( field: Field< Media > ) => ! regularFieldIds.includes( field.id )\n\t\t),\n\t];\n\n\t// Default form structure with panel layout\n\tconst defaultForm: Form = {\n\t\tlayout: {\n\t\t\ttype: 'panel',\n\t\t},\n\t\tfields: sortedFields.map( ( field: Field< Media > ) => {\n\t\t\t// Use regular layout for main editable fields\n\t\t\tif ( regularFieldIds.includes( field.id ) ) {\n\t\t\t\treturn {\n\t\t\t\t\tid: field.id,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'regular',\n\t\t\t\t\t\tlabelPosition: 'top',\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn field.id;\n\t\t} ),\n\t};\n\n\tconst form = formOverrides || defaultForm;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details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BAAAA,sBAAA,EAAO,SAAU,GACjB;AAAA,gDAAC,4BAAe,QAAS,4CAAC,QAAG,GAC1B,8BAAI,eAAgB,GACvB;AAAA,IACE;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KACD,GACD;AAEF;",
6
+ "names": ["VStack"]
7
7
  }
@@ -29,6 +29,7 @@ __export(constants_exports, {
29
29
  MAX_ROTATION_OFFSET: () => MAX_ROTATION_OFFSET,
30
30
  MAX_ZOOM: () => MAX_ZOOM,
31
31
  MIN_CROP_PIXELS: () => MIN_CROP_PIXELS,
32
+ MIN_CROP_SCREEN_PX: () => MIN_CROP_SCREEN_PX,
32
33
  MIN_ZOOM: () => MIN_ZOOM,
33
34
  ORIGINAL_ASPECT_RATIO: () => ORIGINAL_ASPECT_RATIO
34
35
  });
@@ -38,6 +39,7 @@ var MIN_ZOOM = 1;
38
39
  var ABSOLUTE_MIN_ZOOM = 0.1;
39
40
  var MAX_ZOOM = 10;
40
41
  var MIN_CROP_PIXELS = 24;
42
+ var MIN_CROP_SCREEN_PX = 44;
41
43
  var DEFAULT_WHEEL_ZOOM_SPEED = 25e-4;
42
44
  var DEFAULT_KEYBOARD_STEP = 0.01;
43
45
  var KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;
@@ -90,6 +92,7 @@ var DEFAULT_ASPECT_RATIOS = [
90
92
  MAX_ROTATION_OFFSET,
91
93
  MAX_ZOOM,
92
94
  MIN_CROP_PIXELS,
95
+ MIN_CROP_SCREEN_PX,
93
96
  MIN_ZOOM,
94
97
  ORIGINAL_ASPECT_RATIO
95
98
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/constants.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Flip, CropperState } from './types';\n\n/**\n * Default/resting zoom. A full, unrotated crop needs at least 1x to cover the\n * crop area, but smaller/fine-rotated crops can be valid below 1x \u2014 the true\n * floor for those comes from `getMinZoom`.\n */\nexport const MIN_ZOOM = 1;\n/**\n * Safety floor for coverage-aware zoom. Degenerate crops can have a geometric\n * coverage minimum of 0, but camera and inverse-matrix math need a stable,\n * positive scale.\n */\nexport const ABSOLUTE_MIN_ZOOM = 0.1;\nexport const MAX_ZOOM = 10;\n\n/**\n * Minimum crop rect dimension in source-image pixels, enforced per axis\n * during resize. Prevents accidental sub-pixel crops while staying small\n * enough to allow tight crops (favicons, icons). Adjust here to tune the\n * floor globally.\n */\nexport const MIN_CROP_PIXELS = 24;\n\n/**\n * Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.\n * This could be made configurable as a prop to the Cropper component.\n */\nexport const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;\n\n/** Fine step for keyboard-driven cropper movement, in normalized coordinates. */\nexport const DEFAULT_KEYBOARD_STEP = 0.01;\n\n/** Coarse keyboard movement multiplier when Shift is held. */\nexport const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;\n\n/**\n * Maximum free-rotation offset in degrees from the nearest 90\u00B0 step.\n * The rotation slider allows \u00B145\u00B0 around the current cardinal angle.\n */\nexport const MAX_ROTATION_OFFSET = 45;\n\nconst DEFAULT_CROP_RECT: NormalizedRect = {\n\tx: 0,\n\ty: 0,\n\twidth: 1,\n\theight: 1,\n};\n\nconst DEFAULT_FLIP: Flip = {\n\thorizontal: false,\n\tvertical: false,\n};\n\nconst DEFAULT_PAN: { x: number; y: number } = {\n\tx: 0,\n\ty: 0,\n};\n\nexport const DEFAULT_STATE: CropperState = {\n\timage: null,\n\tpan: { ...DEFAULT_PAN },\n\tzoom: MIN_ZOOM,\n\trotation: 0,\n\tbasePan: { ...DEFAULT_PAN },\n\tbaseZoom: MIN_ZOOM,\n\tbaseRotation: 0,\n\tflip: { ...DEFAULT_FLIP },\n\tcropRect: { ...DEFAULT_CROP_RECT },\n};\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/** The aspect ratio value (width / height). 0 = free / original. */\n\tvalue: number;\n}\n\n/**\n * Default aspect ratio presets. Consumers can use these as-is, override\n * with their own list, or extend with additional presets.\n *\n * @example\n * // Use defaults:\n * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />\n *\n * // Custom presets:\n * const socialPresets = [\n * { label: 'Instagram Post', value: 1 },\n * { label: 'Instagram Story', value: 9 / 16 },\n * { label: 'YouTube Thumbnail', value: 16 / 9 },\n * ];\n *\n * // Extend defaults:\n * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];\n */\n/**\n * Sentinel value for \"Original\" aspect ratio \u2014 resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },\n\t{ label: __( 'Photo (3:2)' ), value: 3 / 2 },\n\t{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },\n];\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AAYZ,IAAM,WAAW;AAMjB,IAAM,oBAAoB;AAC1B,IAAM,WAAW;AAQjB,IAAM,kB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';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Flip, CropperState } from './types';\n\n/**\n * Default/resting zoom. A full, unrotated crop needs at least 1x to cover the\n * crop area, but smaller/fine-rotated crops can be valid below 1x \u2014 the true\n * floor for those comes from `getMinZoom`.\n */\nexport const MIN_ZOOM = 1;\n/**\n * Safety floor for coverage-aware zoom. Degenerate crops can have a geometric\n * coverage minimum of 0, but camera and inverse-matrix math need a stable,\n * positive scale.\n */\nexport const ABSOLUTE_MIN_ZOOM = 0.1;\nexport const MAX_ZOOM = 10;\n\n/**\n * Minimum crop rect dimension in source-image pixels, enforced per axis\n * during resize. Prevents accidental sub-pixel crops while staying small\n * enough to allow tight crops (favicons, icons). Adjust here to tune the\n * floor globally.\n */\nexport const MIN_CROP_PIXELS = 24;\n\n/**\n * Minimum on-screen crop rect dimension in CSS pixels. The source-pixel\n * floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large\n * image fit into a small canvas it can render only a few CSS pixels wide \u2014\n * too small to grab the resize handles. This floor keeps the crop operable\n * regardless of display scale; it binds when zoomed out and yields to the\n * source-pixel floor once the image is shown large enough. Sized to one\n * handle touch target (`$handle-touch-target-size` in `cropper.scss`).\n */\nexport const MIN_CROP_SCREEN_PX = 44;\n\n/**\n * Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.\n * This could be made configurable as a prop to the Cropper component.\n */\nexport const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;\n\n/** Fine step for keyboard-driven cropper movement, in normalized coordinates. */\nexport const DEFAULT_KEYBOARD_STEP = 0.01;\n\n/** Coarse keyboard movement multiplier when Shift is held. */\nexport const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;\n\n/**\n * Maximum free-rotation offset in degrees from the nearest 90\u00B0 step.\n * The rotation slider allows \u00B145\u00B0 around the current cardinal angle.\n */\nexport const MAX_ROTATION_OFFSET = 45;\n\nconst DEFAULT_CROP_RECT: NormalizedRect = {\n\tx: 0,\n\ty: 0,\n\twidth: 1,\n\theight: 1,\n};\n\nconst DEFAULT_FLIP: Flip = {\n\thorizontal: false,\n\tvertical: false,\n};\n\nconst DEFAULT_PAN: { x: number; y: number } = {\n\tx: 0,\n\ty: 0,\n};\n\nexport const DEFAULT_STATE: CropperState = {\n\timage: null,\n\tpan: { ...DEFAULT_PAN },\n\tzoom: MIN_ZOOM,\n\trotation: 0,\n\tbasePan: { ...DEFAULT_PAN },\n\tbaseZoom: MIN_ZOOM,\n\tbaseRotation: 0,\n\tflip: { ...DEFAULT_FLIP },\n\tcropRect: { ...DEFAULT_CROP_RECT },\n};\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/** The aspect ratio value (width / height). 0 = free / original. */\n\tvalue: number;\n}\n\n/**\n * Default aspect ratio presets. Consumers can use these as-is, override\n * with their own list, or extend with additional presets.\n *\n * @example\n * // Use defaults:\n * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />\n *\n * // Custom presets:\n * const socialPresets = [\n * { label: 'Instagram Post', value: 1 },\n * { label: 'Instagram Story', value: 9 / 16 },\n * { label: 'YouTube Thumbnail', value: 16 / 9 },\n * ];\n *\n * // Extend defaults:\n * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];\n */\n/**\n * Sentinel value for \"Original\" aspect ratio \u2014 resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label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AAE,WAAO,gBAAI,iBAAkB,GAAG,OAAO,IAAI,GAAG;AAAA,EAChD,EAAE,WAAO,gBAAI,eAAgB,GAAG,OAAO,IAAI,EAAE;AAAA,EAC7C,EAAE,WAAO,gBAAI,wBAAyB,GAAG,OAAO,IAAI,EAAE;AAAA,EACtD,EAAE,WAAO,gBAAI,aAAc,GAAG,OAAO,IAAI,EAAE;AAAA,EAC3C,EAAE,WAAO,gBAAI,sBAAuB,GAAG,OAAO,IAAI,EAAE;AACrD;",
6
6
  "names": []
7
7
  }
@@ -23,9 +23,17 @@ __export(stencil_math_exports, {
23
23
  DEFAULT_MIN_CROP_SIZE: () => DEFAULT_MIN_CROP_SIZE,
24
24
  computeFreeResizeRect: () => computeFreeResizeRect,
25
25
  computeLockedResizeRect: () => computeLockedResizeRect,
26
- computeShiftLockedResizeRect: () => computeShiftLockedResizeRect
26
+ computeShiftLockedResizeRect: () => computeShiftLockedResizeRect,
27
+ getMinCropPixels: () => getMinCropPixels
27
28
  });
28
29
  module.exports = __toCommonJS(stencil_math_exports);
30
+ var import_constants = require("./constants.cjs");
31
+ function getMinCropPixels(displayScale) {
32
+ if (displayScale <= 0) {
33
+ return import_constants.MIN_CROP_PIXELS;
34
+ }
35
+ return Math.max(import_constants.MIN_CROP_PIXELS, import_constants.MIN_CROP_SCREEN_PX / displayScale);
36
+ }
29
37
  var DEFAULT_MIN_CROP_SIZE = { width: 0.05, height: 0.05 };
30
38
  function computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds, minCropSize = DEFAULT_MIN_CROP_SIZE) {
31
39
  const dx = imageSize.width > 0 ? (clientX - drag.startX) / imageSize.width : 0;
@@ -203,6 +211,7 @@ function computeShiftLockedResizeRect(drag, clientX, clientY, imageSize, bounds,
203
211
  DEFAULT_MIN_CROP_SIZE,
204
212
  computeFreeResizeRect,
205
213
  computeLockedResizeRect,
206
- computeShiftLockedResizeRect
214
+ computeShiftLockedResizeRect,
215
+ getMinCropPixels
207
216
  });
208
217
  //# sourceMappingURL=stencil-math.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/stencil-math.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { HandlePosition, NormalizedRect, Size } from './types';\n\nexport type { HandlePosition };\n\n/**\n * Default minimum crop rect dimension in normalized space, used when no\n * explicit per-axis minimum is supplied (e.g. before the source image\n * has loaded). Real usage derives a pixel-based min from the source\n * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.\n */\nexport const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };\n\n/**\n * Bounds within which the crop rect must stay.\n */\nexport interface CropBounds {\n\tminX: number;\n\tminY: number;\n\tmaxX: number;\n\tmaxY: number;\n}\n\n/**\n * Drag state for tracking a resize interaction.\n */\nexport interface ResizeDragState {\n\t/** Which handle is being dragged. */\n\thandle: HandlePosition;\n\t/** The mouse position (pixels) when the drag started. */\n\tstartX: number;\n\tstartY: number;\n\t/** The crop rect (normalized) when the drag started. */\n\tstartRect: NormalizedRect;\n}\n\n/**\n * Compute the new crop rect for a free (no aspect ratio) resize.\n *\n * Each edge moves independently based on the handle being dragged.\n * Edges are clamped to the provided bounds and maintain a minimum size.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeFreeResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst dx =\n\t\timageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;\n\tconst dy =\n\t\timageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\tlet edgeTop = s.y;\n\tlet edgeBottom = s.y + s.height;\n\tlet edgeLeft = s.x;\n\tlet edgeRight = s.x + s.width;\n\n\tif ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {\n\t\tedgeTop = Math.max(\n\t\t\tbounds.minY,\n\t\t\tMath.min( s.y + dy, edgeBottom - minCropSize.height )\n\t\t);\n\t}\n\tif ( handle === 's' || handle === 'sw' || handle === 'se' ) {\n\t\tedgeBottom = Math.max(\n\t\t\tedgeTop + minCropSize.height,\n\t\t\tMath.min( s.y + s.height + dy, bounds.maxY )\n\t\t);\n\t}\n\tif ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {\n\t\tedgeLeft = Math.max(\n\t\t\tbounds.minX,\n\t\t\tMath.min( s.x + dx, edgeRight - minCropSize.width )\n\t\t);\n\t}\n\tif ( handle === 'e' || handle === 'ne' || handle === 'se' ) {\n\t\tedgeRight = Math.max(\n\t\t\tedgeLeft + minCropSize.width,\n\t\t\tMath.min( s.x + s.width + dx, bounds.maxX )\n\t\t);\n\t}\n\n\treturn {\n\t\tx: edgeLeft,\n\t\ty: edgeTop,\n\t\twidth: edgeRight - edgeLeft,\n\t\theight: edgeBottom - edgeTop,\n\t};\n}\n\n/**\n * Compute the new crop rect for a locked-aspect-ratio corner resize.\n *\n * The opposite corner is the anchor. The dragged corner moves freely\n * but the result is clamped to maintain the aspect ratio and stay\n * within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param normalizedRatio The locked aspect ratio (width / height in normalized space).\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tnormalizedRatio: number,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\t// The math below divides by `normalizedRatio` and `imageSize`, so\n\t// bail out with the start rect when any of them is zero. This can\n\t// happen if a resize is triggered (e.g. via keyboard arrows on a\n\t// focused handle) before the image has loaded.\n\tif (\n\t\tnormalizedRatio <= 0 ||\n\t\timageSize.width <= 0 ||\n\t\timageSize.height <= 0\n\t) {\n\t\treturn { ...drag.startRect };\n\t}\n\n\tconst dx = ( clientX - drag.startX ) / imageSize.width;\n\tconst dy = ( clientY - drag.startY ) / imageSize.height;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\t// Determine the anchor corner (opposite to the dragged corner).\n\tconst anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;\n\tconst anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;\n\n\t// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).\n\tconst dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;\n\tconst dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;\n\n\t// Desired new position of the dragged corner.\n\tconst draggedX =\n\t\t( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;\n\tconst draggedY =\n\t\t( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;\n\n\t// Raw distances from anchor to dragged corner.\n\tlet distW = ( draggedX - anchorX ) * dirX;\n\tlet distH = ( draggedY - anchorY ) * dirY;\n\n\t// Enforce minimum size on both axes, projecting through the ratio so\n\t// neither axis falls below its per-axis floor.\n\tconst minDistW = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tconst minDistH = minDistW / normalizedRatio;\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Determine which axis \"drives\" \u2014 whichever the user moved more\n\t// (in pixel space) determines the size, the other follows. The\n\t// `normalizedRatio` is w/h in normalized space; the equivalent\n\t// pixel-space ratio is `normalizedRatio * imageW / imageH`. We\n\t// compare the pixel motion ratio against that pixel-space ratio\n\t// so the units line up (was a unit mismatch on non-square images).\n\tconst pixelDistW = distW * imageSize.width;\n\tconst pixelDistH = distH * imageSize.height;\n\tconst pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;\n\tif ( pixelDistW / pixelDistH > pixelRatio ) {\n\t\t// Width is the driver \u2014 compute height from ratio.\n\t\tdistH = distW / normalizedRatio;\n\t} else {\n\t\t// Height is the driver \u2014 compute width from ratio.\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Clamp to image coverage bounds. If the rect would exceed,\n\t// shrink it (maintaining ratio) to fit.\n\tconst maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;\n\tconst maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;\n\n\tif ( distW > maxW ) {\n\t\tdistW = maxW;\n\t\tdistH = distW / normalizedRatio;\n\t}\n\tif ( distH > maxH ) {\n\t\tdistH = maxH;\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Enforce minimum after clamping.\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Compute the final rect position from the anchor.\n\tconst newX = dirX > 0 ? anchorX : anchorX - distW;\n\tconst newY = dirY > 0 ? anchorY : anchorY - distH;\n\n\treturn { x: newX, y: newY, width: distW, height: distH };\n}\n\n/**\n * Compute the new crop rect for a resize that temporarily locks the\n * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).\n *\n * Corner handles delegate to {@link computeLockedResizeRect}. Edge\n * handles size the dragged axis freely, then expand the perpendicular\n * axis symmetrically around the rect's center to preserve the ratio,\n * clamping symmetrically so the rect stays within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeShiftLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst s = drag.startRect;\n\tconst pixelW = s.width * imageSize.width;\n\tconst pixelH = s.height * imageSize.height;\n\tif ( pixelH <= 0 || pixelW <= 0 ) {\n\t\treturn computeFreeResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tminCropSize\n\t\t);\n\t}\n\tconst normalizedRatio = s.width / s.height;\n\n\tconst handle = drag.handle;\n\tif (\n\t\thandle === 'nw' ||\n\t\thandle === 'ne' ||\n\t\thandle === 'sw' ||\n\t\thandle === 'se'\n\t) {\n\t\treturn computeLockedResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tnormalizedRatio,\n\t\t\tminCropSize\n\t\t);\n\t}\n\n\t// Edge handle: size the dragged axis with free-resize logic, then\n\t// expand the perpendicular axis symmetrically around the rect's center.\n\tconst free = computeFreeResizeRect(\n\t\tdrag,\n\t\tclientX,\n\t\tclientY,\n\t\timageSize,\n\t\tbounds,\n\t\tminCropSize\n\t);\n\n\tif ( handle === 'n' || handle === 's' ) {\n\t\t// Height is the driver; derive width from ratio.\n\t\tlet newHeight = free.height;\n\t\tlet newWidth = newHeight * normalizedRatio;\n\t\tconst centerX = s.x + s.width / 2;\n\t\t// Symmetric clamp: limit by the smaller of the two side gaps so\n\t\t// the rect stays centered around centerX.\n\t\tconst maxWidth =\n\t\t\tMath.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;\n\t\tif ( newWidth > maxWidth ) {\n\t\t\tnewWidth = maxWidth;\n\t\t\tnewHeight = newWidth / normalizedRatio;\n\t\t}\n\t\t// Enforce the minimum on the driving axis, then derive the\n\t\t// other axis from the ratio so it stays consistent. The\n\t\t// effective minimum height has to satisfy the per-axis floor\n\t\t// on both axes simultaneously.\n\t\tconst minHeight = Math.max(\n\t\t\tminCropSize.height,\n\t\t\tminCropSize.width / normalizedRatio\n\t\t);\n\t\tif ( newHeight < minHeight ) {\n\t\t\tnewHeight = minHeight;\n\t\t\tnewWidth = newHeight * normalizedRatio;\n\t\t}\n\t\t// Re-anchor the dragged axis to the opposite edge so the\n\t\t// height adjustment after clamping keeps that edge fixed.\n\t\tconst newY = handle === 'n' ? s.y + s.height - newHeight : s.y;\n\t\treturn {\n\t\t\tx: centerX - newWidth / 2,\n\t\t\ty: newY,\n\t\t\twidth: newWidth,\n\t\t\theight: newHeight,\n\t\t};\n\t}\n\n\t// 'e' or 'w': width is the driver; derive height from ratio.\n\tlet newWidth = free.width;\n\tlet newHeight = newWidth / normalizedRatio;\n\tconst centerY = s.y + s.height / 2;\n\tconst maxHeight =\n\t\tMath.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;\n\tif ( newHeight > maxHeight ) {\n\t\tnewHeight = maxHeight;\n\t\tnewWidth = newHeight * normalizedRatio;\n\t}\n\tconst minWidth = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tif ( newWidth < minWidth ) {\n\t\tnewWidth = minWidth;\n\t\tnewHeight = newWidth / normalizedRatio;\n\t}\n\tconst newX = handle === 'w' ? s.x + s.width - newWidth : s.x;\n\treturn {\n\t\tx: newX,\n\t\ty: centerY - newHeight / 2,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,IAAM,wBAA8B,EAAE,OAAO,MAAM,QAAQ,KAAK;AAuChE,SAAS,sBACf,MACA,SACA,SACA,WACA,QACA,cAAoB,uBACH;AACjB,QAAM,KACL,UAAU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,MACZ,YAAY,QAAQ;AAAA,IACrB;AACA,QAAKD,aAAY,WAAY;AAC5B,MAAAA,aAAY;AACZ,MAAAC,YAAWD,aAAY;AAAA,IACxB;AAGA,UAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,SAASA,aAAY,EAAE;AAC7D,WAAO;AAAA,MACN,GAAG,UAAUC,YAAW;AAAA,MACxB,GAAG;AAAA,MACH,OAAOA;AAAA,MACP,QAAQD;AAAA,IACT;AAAA,EACD;AAGA,MAAI,WAAW,KAAK;AACpB,MAAI,YAAY,WAAW;AAC3B,QAAM,UAAU,EAAE,IAAI,EAAE,SAAS;AACjC,QAAM,YACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;AAC5D,MAAK,YAAY,WAAY;AAC5B,gBAAY;AACZ,eAAW,YAAY;AAAA,EACxB;AACA,QAAM,WAAW,KAAK;AAAA,IACrB,YAAY;AAAA,IACZ,YAAY,SAAS;AAAA,EACtB;AACA,MAAK,WAAW,UAAW;AAC1B,eAAW;AACX,gBAAY,WAAW;AAAA,EACxB;AACA,QAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,WAAW,EAAE;AAC3D,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG,UAAU,YAAY;AAAA,IACzB,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AACD;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';\nimport type { HandlePosition, NormalizedRect, Size } from './types';\n\nexport type { HandlePosition };\n\n/**\n * Resolve the minimum crop dimension, in source-image pixels, for the current\n * display scale.\n *\n * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that\n * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that\n * keeps the crop large enough to grab. The on-screen floor converted to source\n * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the\n * larger of the two. When zoomed out (small `displayScale`) the on-screen floor\n * dominates; once the image is shown large enough the source-pixel floor takes\n * over.\n *\n * @param displayScale CSS pixels rendered per source pixel (fit scale \u00D7 zoom).\n * @return Minimum crop dimension in source-image pixels.\n */\nexport function getMinCropPixels( displayScale: number ): number {\n\tif ( displayScale <= 0 ) {\n\t\treturn MIN_CROP_PIXELS;\n\t}\n\treturn Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );\n}\n\n/**\n * Default minimum crop rect dimension in normalized space, used when no\n * explicit per-axis minimum is supplied (e.g. before the source image\n * has loaded). Real usage derives a pixel-based min from the source\n * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.\n */\nexport const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };\n\n/**\n * Bounds within which the crop rect must stay.\n */\nexport interface CropBounds {\n\tminX: number;\n\tminY: number;\n\tmaxX: number;\n\tmaxY: number;\n}\n\n/**\n * Drag state for tracking a resize interaction.\n */\nexport interface ResizeDragState {\n\t/** Which handle is being dragged. */\n\thandle: HandlePosition;\n\t/** The mouse position (pixels) when the drag started. */\n\tstartX: number;\n\tstartY: number;\n\t/** The crop rect (normalized) when the drag started. */\n\tstartRect: NormalizedRect;\n}\n\n/**\n * Compute the new crop rect for a free (no aspect ratio) resize.\n *\n * Each edge moves independently based on the handle being dragged.\n * Edges are clamped to the provided bounds and maintain a minimum size.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeFreeResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst dx =\n\t\timageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;\n\tconst dy =\n\t\timageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\tlet edgeTop = s.y;\n\tlet edgeBottom = s.y + s.height;\n\tlet edgeLeft = s.x;\n\tlet edgeRight = s.x + s.width;\n\n\tif ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {\n\t\tedgeTop = Math.max(\n\t\t\tbounds.minY,\n\t\t\tMath.min( s.y + dy, edgeBottom - minCropSize.height )\n\t\t);\n\t}\n\tif ( handle === 's' || handle === 'sw' || handle === 'se' ) {\n\t\tedgeBottom = Math.max(\n\t\t\tedgeTop + minCropSize.height,\n\t\t\tMath.min( s.y + s.height + dy, bounds.maxY )\n\t\t);\n\t}\n\tif ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {\n\t\tedgeLeft = Math.max(\n\t\t\tbounds.minX,\n\t\t\tMath.min( s.x + dx, edgeRight - minCropSize.width )\n\t\t);\n\t}\n\tif ( handle === 'e' || handle === 'ne' || handle === 'se' ) {\n\t\tedgeRight = Math.max(\n\t\t\tedgeLeft + minCropSize.width,\n\t\t\tMath.min( s.x + s.width + dx, bounds.maxX )\n\t\t);\n\t}\n\n\treturn {\n\t\tx: edgeLeft,\n\t\ty: edgeTop,\n\t\twidth: edgeRight - edgeLeft,\n\t\theight: edgeBottom - edgeTop,\n\t};\n}\n\n/**\n * Compute the new crop rect for a locked-aspect-ratio corner resize.\n *\n * The opposite corner is the anchor. The dragged corner moves freely\n * but the result is clamped to maintain the aspect ratio and stay\n * within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param normalizedRatio The locked aspect ratio (width / height in normalized space).\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tnormalizedRatio: number,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\t// The math below divides by `normalizedRatio` and `imageSize`, so\n\t// bail out with the start rect when any of them is zero. This can\n\t// happen if a resize is triggered (e.g. via keyboard arrows on a\n\t// focused handle) before the image has loaded.\n\tif (\n\t\tnormalizedRatio <= 0 ||\n\t\timageSize.width <= 0 ||\n\t\timageSize.height <= 0\n\t) {\n\t\treturn { ...drag.startRect };\n\t}\n\n\tconst dx = ( clientX - drag.startX ) / imageSize.width;\n\tconst dy = ( clientY - drag.startY ) / imageSize.height;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\t// Determine the anchor corner (opposite to the dragged corner).\n\tconst anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;\n\tconst anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;\n\n\t// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).\n\tconst dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;\n\tconst dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;\n\n\t// Desired new position of the dragged corner.\n\tconst draggedX =\n\t\t( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;\n\tconst draggedY =\n\t\t( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;\n\n\t// Raw distances from anchor to dragged corner.\n\tlet distW = ( draggedX - anchorX ) * dirX;\n\tlet distH = ( draggedY - anchorY ) * dirY;\n\n\t// Enforce minimum size on both axes, projecting through the ratio so\n\t// neither axis falls below its per-axis floor.\n\tconst minDistW = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tconst minDistH = minDistW / normalizedRatio;\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Determine which axis \"drives\" \u2014 whichever the user moved more\n\t// (in pixel space) determines the size, the other follows. The\n\t// `normalizedRatio` is w/h in normalized space; the equivalent\n\t// pixel-space ratio is `normalizedRatio * imageW / imageH`. We\n\t// compare the pixel motion ratio against that pixel-space ratio\n\t// so the units line up (was a unit mismatch on non-square images).\n\tconst pixelDistW = distW * imageSize.width;\n\tconst pixelDistH = distH * imageSize.height;\n\tconst pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;\n\tif ( pixelDistW / pixelDistH > pixelRatio ) {\n\t\t// Width is the driver \u2014 compute height from ratio.\n\t\tdistH = distW / normalizedRatio;\n\t} else {\n\t\t// Height is the driver \u2014 compute width from ratio.\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Clamp to image coverage bounds. If the rect would exceed,\n\t// shrink it (maintaining ratio) to fit.\n\tconst maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;\n\tconst maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;\n\n\tif ( distW > maxW ) {\n\t\tdistW = maxW;\n\t\tdistH = distW / normalizedRatio;\n\t}\n\tif ( distH > maxH ) {\n\t\tdistH = maxH;\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Enforce minimum after clamping.\n\tdistW = Math.max( distW, minDistW );\n\tdistH = Math.max( distH, minDistH );\n\n\t// Compute the final rect position from the anchor.\n\tconst newX = dirX > 0 ? anchorX : anchorX - distW;\n\tconst newY = dirY > 0 ? anchorY : anchorY - distH;\n\n\treturn { x: newX, y: newY, width: distW, height: distH };\n}\n\n/**\n * Compute the new crop rect for a resize that temporarily locks the\n * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).\n *\n * Corner handles delegate to {@link computeLockedResizeRect}. Edge\n * handles size the dragged axis freely, then expand the perpendicular\n * axis symmetrically around the rect's center to preserve the ratio,\n * clamping symmetrically so the rect stays within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeShiftLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tminCropSize: Size = DEFAULT_MIN_CROP_SIZE\n): NormalizedRect {\n\tconst s = drag.startRect;\n\tconst pixelW = s.width * imageSize.width;\n\tconst pixelH = s.height * imageSize.height;\n\tif ( pixelH <= 0 || pixelW <= 0 ) {\n\t\treturn computeFreeResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tminCropSize\n\t\t);\n\t}\n\tconst normalizedRatio = s.width / s.height;\n\n\tconst handle = drag.handle;\n\tif (\n\t\thandle === 'nw' ||\n\t\thandle === 'ne' ||\n\t\thandle === 'sw' ||\n\t\thandle === 'se'\n\t) {\n\t\treturn computeLockedResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tnormalizedRatio,\n\t\t\tminCropSize\n\t\t);\n\t}\n\n\t// Edge handle: size the dragged axis with free-resize logic, then\n\t// expand the perpendicular axis symmetrically around the rect's center.\n\tconst free = computeFreeResizeRect(\n\t\tdrag,\n\t\tclientX,\n\t\tclientY,\n\t\timageSize,\n\t\tbounds,\n\t\tminCropSize\n\t);\n\n\tif ( handle === 'n' || handle === 's' ) {\n\t\t// Height is the driver; derive width from ratio.\n\t\tlet newHeight = free.height;\n\t\tlet newWidth = newHeight * normalizedRatio;\n\t\tconst centerX = s.x + s.width / 2;\n\t\t// Symmetric clamp: limit by the smaller of the two side gaps so\n\t\t// the rect stays centered around centerX.\n\t\tconst maxWidth =\n\t\t\tMath.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;\n\t\tif ( newWidth > maxWidth ) {\n\t\t\tnewWidth = maxWidth;\n\t\t\tnewHeight = newWidth / normalizedRatio;\n\t\t}\n\t\t// Enforce the minimum on the driving axis, then derive the\n\t\t// other axis from the ratio so it stays consistent. The\n\t\t// effective minimum height has to satisfy the per-axis floor\n\t\t// on both axes simultaneously.\n\t\tconst minHeight = Math.max(\n\t\t\tminCropSize.height,\n\t\t\tminCropSize.width / normalizedRatio\n\t\t);\n\t\tif ( newHeight < minHeight ) {\n\t\t\tnewHeight = minHeight;\n\t\t\tnewWidth = newHeight * normalizedRatio;\n\t\t}\n\t\t// Re-anchor the dragged axis to the opposite edge so the\n\t\t// height adjustment after clamping keeps that edge fixed.\n\t\tconst newY = handle === 'n' ? s.y + s.height - newHeight : s.y;\n\t\treturn {\n\t\t\tx: centerX - newWidth / 2,\n\t\t\ty: newY,\n\t\t\twidth: newWidth,\n\t\t\theight: newHeight,\n\t\t};\n\t}\n\n\t// 'e' or 'w': width is the driver; derive height from ratio.\n\tlet newWidth = free.width;\n\tlet newHeight = newWidth / normalizedRatio;\n\tconst centerY = s.y + s.height / 2;\n\tconst maxHeight =\n\t\tMath.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;\n\tif ( newHeight > maxHeight ) {\n\t\tnewHeight = maxHeight;\n\t\tnewWidth = newHeight * normalizedRatio;\n\t}\n\tconst minWidth = Math.max(\n\t\tminCropSize.width,\n\t\tminCropSize.height * normalizedRatio\n\t);\n\tif ( newWidth < minWidth ) {\n\t\tnewWidth = minWidth;\n\t\tnewHeight = newWidth / normalizedRatio;\n\t}\n\tconst newX = handle === 'w' ? s.x + s.width - newWidth : s.x;\n\treturn {\n\t\tx: newX,\n\t\ty: centerY - newHeight / 2,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAoD;AAoB7C,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AY;AAC3B,UAAM,UAAU,EAAE,IAAI,EAAE,QAAQ;AAGhC,UAAM,WACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;AAC5D,QAAKC,YAAW,UAAW;AAC1B,MAAAA,YAAW;AACX,MAAAD,aAAYC,YAAW;AAAA,IACxB;AAKA,UAAM,YAAY,KAAK;AAAA,MACtB,YAAY;AAAA,MACZ,YAAY,QAAQ;AAAA,IACrB;AACA,QAAKD,aAAY,WAAY;AAC5B,MAAAA,aAAY;AACZ,MAAAC,YAAWD,aAAY;AAAA,IACxB;AAGA,UAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,SAASA,aAAY,EAAE;AAC7D,WAAO;AAAA,MACN,GAAG,UAAUC,YAAW;AAAA,MACxB,GAAG;AAAA,MACH,OAAOA;AAAA,MACP,QAAQD;AAAA,IACT;AAAA,EACD;AAGA,MAAI,WAAW,KAAK;AACpB,MAAI,YAAY,WAAW;AAC3B,QAAM,UAAU,EAAE,IAAI,EAAE,SAAS;AACjC,QAAM,YACL,KAAK,IAAK,UAAU,OAAO,MAAM,OAAO,OAAO,OAAQ,IAAI;AAC5D,MAAK,YAAY,WAAY;AAC5B,gBAAY;AACZ,eAAW,YAAY;AAAA,EACxB;AACA,QAAM,WAAW,KAAK;AAAA,IACrB,YAAY;AAAA,IACZ,YAAY,SAAS;AAAA,EACtB;AACA,MAAK,WAAW,UAAW;AAC1B,eAAW;AACX,gBAAY,WAAW;AAAA,EACxB;AACA,QAAM,OAAO,WAAW,MAAM,EAAE,IAAI,EAAE,QAAQ,WAAW,EAAE;AAC3D,SAAO;AAAA,IACN,GAAG;AAAA,IACH,GAAG,UAAU,YAAY;AAAA,IACzB,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AACD;",
6
6
  "names": ["newHeight", "newWidth"]
7
7
  }
@@ -38,7 +38,7 @@ var import_element = require("@wordpress/element");
38
38
  var import_i18n = require("@wordpress/i18n");
39
39
  var import_camera = require("../../core/camera.cjs");
40
40
  var import_containment = require("../../core/containment.cjs");
41
- var import_constants = require("../../core/constants.cjs");
41
+ var import_stencil_math = require("../../core/stencil-math.cjs");
42
42
  var import_crop_rect = require("../../core/crop-rect.cjs");
43
43
  var import_use_interaction = require("../hooks/use-interaction.cjs");
44
44
  var import_use_transform_style = require("../hooks/use-transform-style.cjs");
@@ -167,14 +167,19 @@ function CropperInner({
167
167
  naturalHeight,
168
168
  snapRotation
169
169
  );
170
+ const displayScale = elementSize.width / naturalWidth * state.zoom;
171
+ const minPixels = (0, import_stencil_math.getMinCropPixels)(displayScale);
170
172
  return {
171
- width: Math.min(1, import_constants.MIN_CROP_PIXELS * state.zoom / bbox.width),
172
- height: Math.min(
173
- 1,
174
- import_constants.MIN_CROP_PIXELS * state.zoom / bbox.height
175
- )
173
+ width: Math.min(1, minPixels * state.zoom / bbox.width),
174
+ height: Math.min(1, minPixels * state.zoom / bbox.height)
176
175
  };
177
- }, [naturalWidth, naturalHeight, state.rotation, state.zoom]);
176
+ }, [
177
+ naturalWidth,
178
+ naturalHeight,
179
+ state.rotation,
180
+ state.zoom,
181
+ elementSize.width
182
+ ]);
178
183
  (0, import_element.useEffect)(() => {
179
184
  setVisualSize(visualSize);
180
185
  }, [visualSize, setVisualSize]);