@wordpress/media-editor 0.11.1 → 0.11.2-next.v.202606191442.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +63 -15
- package/build/components/media-editor-canvas/index.cjs.map +3 -3
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +2 -2
- package/build/components/media-editor-image-controls/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +4 -4
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +1 -1
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/image-editor/core/camera.cjs +13 -0
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs +12 -3
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs.map +1 -1
- package/build/image-editor/core/crop-rect.cjs.map +1 -1
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -1
- package/build/image-editor/core/interaction-controller.cjs +9 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs.map +1 -1
- package/build/image-editor/core/setter-helpers.cjs.map +1 -1
- package/build/image-editor/core/source-region.cjs +111 -2
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs.map +1 -1
- package/build/image-editor/core/stencil-math.cjs +3 -4
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs.map +1 -1
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/react/components/cropper.cjs +232 -55
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +1 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +65 -19
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -1
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +1 -1
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -1
- package/build/index.cjs.map +1 -1
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +1 -1
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +55 -17
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +4 -4
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -1
- package/build-module/components/rotation-ruler/index.mjs +1 -1
- package/build-module/components/rotation-ruler/index.mjs.map +1 -1
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -1
- package/build-module/image-editor/core/camera.mjs +12 -0
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +8 -2
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs.map +1 -1
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -1
- package/build-module/image-editor/core/interaction-controller.mjs +9 -7
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -1
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -1
- package/build-module/image-editor/core/source-region.mjs +108 -1
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs.map +1 -1
- package/build-module/image-editor/core/stencil-math.mjs +3 -4
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/react/components/cropper.mjs +242 -57
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +1 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +65 -19
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -1
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +1 -1
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +1 -1
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-style/style-rtl.css +49 -6
- package/build-style/style.css +49 -6
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts +25 -1
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +20 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/source-region.d.ts +23 -1
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +10 -5
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/types.d.ts +14 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +17 -14
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/package.json +25 -20
- package/src/components/media-editor/style.scss +21 -9
- package/src/components/media-editor-canvas/index.tsx +82 -13
- package/src/components/media-editor-canvas/style.scss +41 -0
- package/src/image-editor/core/camera.ts +60 -1
- package/src/image-editor/core/constants.ts +23 -1
- package/src/image-editor/core/interaction-controller.ts +25 -11
- package/src/image-editor/core/source-region.ts +202 -1
- package/src/image-editor/core/stencil-math.ts +23 -14
- package/src/image-editor/core/test/camera.ts +272 -1
- package/src/image-editor/core/test/interaction-controller.ts +100 -0
- package/src/image-editor/core/test/stencil-math.ts +120 -6
- package/src/image-editor/core/types.ts +17 -0
- package/src/image-editor/react/components/cropper.tsx +362 -72
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +1 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +101 -32
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +169 -17
- package/src/image-editor/react/components/test/cropper.tsx +689 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +0 -21
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -108
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor/use-crop-options.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_ASPECT_RATIOS } from '../../image-editor/core/constants';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\nimport { useMediaEditor, resolveAspectRatio } from '../../state';\n\ninterface UseCropOptionsArgs {\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\ninterface UseCropOptionsReturn {\n\taspectRatioValue: string;\n\tsetAspectRatioValue: ( value: string ) => void;\n\taspectRatioOptions: AspectRatioPreset[];\n\tresolvedAspectRatio: number | undefined;\n\tresetCropOptions: () => void;\n}\n\n/**\n * Build the preset list shown in the dropdown
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_ASPECT_RATIOS } from '../../image-editor/core/constants';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\nimport { useMediaEditor, resolveAspectRatio } from '../../state';\n\ninterface UseCropOptionsArgs {\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\ninterface UseCropOptionsReturn {\n\taspectRatioValue: string;\n\tsetAspectRatioValue: ( value: string ) => void;\n\taspectRatioOptions: AspectRatioPreset[];\n\tresolvedAspectRatio: number | undefined;\n\tresetCropOptions: () => void;\n}\n\n/**\n * Build the preset list shown in the dropdown — always include the\n * non-numeric presets (Free, Original) and append either the\n * caller-supplied set or the defaults.\n *\n * @param aspectRatioPresets Optional caller-supplied presets.\n * @return The full preset list to render.\n */\nexport function getAspectRatioOptions(\n\taspectRatioPresets?: AspectRatioPreset[]\n): AspectRatioPreset[] {\n\treturn [\n\t\t...DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value <= 0 ),\n\t\t...( aspectRatioPresets ??\n\t\t\tDEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value > 0 ) ),\n\t];\n}\n\n/**\n * Thin selector over the composite media-editor store for the Crop\n * sidebar tab. Reads the cropOptions slice (preset key) and exposes\n * the corresponding setters plus a render-time `resolvedAspectRatio`\n * derivation.\n *\n * No local React state, no refs, no synchronization effects — the\n * composite store is the single source of truth.\n *\n * @param args\n * @param args.aspectRatioPresets Optional caller-supplied aspect-ratio presets.\n */\nexport function useCropOptions( {\n\taspectRatioPresets,\n}: UseCropOptionsArgs = {} ): UseCropOptionsReturn {\n\tconst controller = useMediaEditor();\n\tconst { aspectRatioValue } = controller.cropOptions;\n\tconst cropperImage = controller.state.image;\n\n\tconst aspectRatioOptions = useMemo(\n\t\t() => getAspectRatioOptions( aspectRatioPresets ),\n\t\t[ aspectRatioPresets ]\n\t);\n\n\tconst resolvedAspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\n\t);\n\n\treturn {\n\t\taspectRatioValue,\n\t\tsetAspectRatioValue: controller.setAspectRatioValue,\n\t\taspectRatioOptions,\n\t\tresolvedAspectRatio,\n\t\tresetCropOptions: controller.resetCropOptions,\n\t};\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,eAAe;AAKxB,SAAS,6BAA6B;AAEtC,SAAS,gBAAgB,0BAA0B;AAsB5C,SAAS,sBACf,oBACsB;AACtB,SAAO;AAAA,IACN,GAAG,sBAAsB,OAAQ,CAAE,WAAY,OAAO,SAAS,CAAE;AAAA,IACjE,GAAK,sBACJ,sBAAsB,OAAQ,CAAE,WAAY,OAAO,QAAQ,CAAE;AAAA,EAC/D;AACD;AAcO,SAAS,eAAgB;AAAA,EAC/B;AACD,IAAwB,CAAC,GAA0B;AAClD,QAAM,aAAa,eAAe;AAClC,QAAM,EAAE,iBAAiB,IAAI,WAAW;AACxC,QAAM,eAAe,WAAW,MAAM;AAEtC,QAAM,qBAAqB;AAAA,IAC1B,MAAM,sBAAuB,kBAAmB;AAAA,IAChD,CAAE,kBAAmB;AAAA,EACtB;AAEA,QAAM,sBAAsB;AAAA,IAC3B,MAAM,mBAAoB,kBAAkB,YAAa;AAAA,IACzD,CAAE,kBAAkB,YAAa;AAAA,EAClC;AAEA,SAAO;AAAA,IACN;AAAA,IACA,qBAAqB,WAAW;AAAA,IAChC;AAAA,IACA;AAAA,IACA,kBAAkB,WAAW;AAAA,EAC9B;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// packages/media-editor/src/components/media-editor-canvas/index.tsx
|
|
2
|
-
import
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "@wordpress/element";
|
|
4
|
+
import { Spinner } from "@wordpress/components";
|
|
5
|
+
import { __ } from "@wordpress/i18n";
|
|
3
6
|
import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
|
|
4
7
|
import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
|
|
5
8
|
import { Cropper } from "../../image-editor/index.mjs";
|
|
6
9
|
import { useMediaEditor, resolveAspectRatio } from "../../state/index.mjs";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
11
|
function MediaEditorCanvas({
|
|
9
12
|
focusOnMount,
|
|
10
13
|
isPlacementActive = false,
|
|
@@ -16,6 +19,9 @@ function MediaEditorCanvas({
|
|
|
16
19
|
const { aspectRatioValue } = controller.cropOptions;
|
|
17
20
|
const cropperImage = controller.state.image;
|
|
18
21
|
const { beginGesture, endGesture, setImage } = controller;
|
|
22
|
+
const [status, setStatus] = useState(
|
|
23
|
+
"loading"
|
|
24
|
+
);
|
|
19
25
|
const aspectRatio = useMemo(
|
|
20
26
|
() => resolveAspectRatio(aspectRatioValue, cropperImage),
|
|
21
27
|
[aspectRatioValue, cropperImage]
|
|
@@ -42,23 +48,55 @@ function MediaEditorCanvas({
|
|
|
42
48
|
naturalHeight: mediaHeight
|
|
43
49
|
});
|
|
44
50
|
}, [cropperImage, mediaUrl, mediaWidth, mediaHeight, setImage]);
|
|
45
|
-
|
|
51
|
+
const isImage = mediaType.type === "image";
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!mediaUrl || !isImage) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
setStatus("loading");
|
|
57
|
+
const probe = new window.Image();
|
|
58
|
+
probe.onload = () => setStatus("loaded");
|
|
59
|
+
probe.onerror = () => setStatus("error");
|
|
60
|
+
probe.src = mediaUrl;
|
|
61
|
+
if (probe.complete) {
|
|
62
|
+
setStatus(probe.naturalWidth > 0 ? "loaded" : "error");
|
|
63
|
+
}
|
|
64
|
+
return () => {
|
|
65
|
+
probe.onload = null;
|
|
66
|
+
probe.onerror = null;
|
|
67
|
+
};
|
|
68
|
+
}, [mediaUrl, isImage]);
|
|
69
|
+
if (!mediaUrl || !isImage) {
|
|
46
70
|
return null;
|
|
47
71
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
if (status === "error") {
|
|
73
|
+
return /* @__PURE__ */ jsx("div", { className: "media-editor-canvas", children: /* @__PURE__ */ jsx("div", { className: "media-editor-canvas__error", role: "alert", children: /* @__PURE__ */ jsx("p", { children: __("Failed to load image.") }) }) });
|
|
74
|
+
}
|
|
75
|
+
return /* @__PURE__ */ jsxs("div", { className: "media-editor-canvas", children: [
|
|
76
|
+
status === "loading" && /* @__PURE__ */ jsx("div", { className: "media-editor-canvas__spinner", children: /* @__PURE__ */ jsx(Spinner, {}) }),
|
|
77
|
+
/* @__PURE__ */ jsx(
|
|
78
|
+
"div",
|
|
79
|
+
{
|
|
80
|
+
className: clsx("media-editor-canvas__cropper", {
|
|
81
|
+
"is-loaded": status === "loaded"
|
|
82
|
+
}),
|
|
83
|
+
children: /* @__PURE__ */ jsx(
|
|
84
|
+
Cropper,
|
|
85
|
+
{
|
|
86
|
+
src: mediaUrl,
|
|
87
|
+
controller,
|
|
88
|
+
aspectRatio,
|
|
89
|
+
freeformCrop: true,
|
|
90
|
+
focusOnMount: focusOnMount && status === "loaded",
|
|
91
|
+
showGrid: "interactive",
|
|
92
|
+
isPlacementActive,
|
|
93
|
+
onGestureStart: handleGestureStart,
|
|
94
|
+
onGestureEnd: handleGestureEnd
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
] });
|
|
62
100
|
}
|
|
63
101
|
export {
|
|
64
102
|
MediaEditorCanvas as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor-canvas/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { Cropper } from '../../image-editor';\nimport { useMediaEditor, resolveAspectRatio } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Focus the crop area when the canvas mounts. */\n\tfocusOnMount?: boolean;\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas cropper gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas cropper gesture ends. */\n\tonGestureEnd?: () => void;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its cropper controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.focusOnMount\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n */\nexport default function MediaEditorCanvas( {\n\tfocusOnMount,\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst controller = useMediaEditor();\n\tconst { aspectRatioValue } = controller.cropOptions;\n\tconst cropperImage = controller.state.image;\n\tconst { beginGesture, endGesture, setImage } = controller;\n\n\t// Resolved aspect ratio is derived from the preset key + the\n\t// loaded image (for the \"Original\" preset). The reducer doesn't\n\t// store this number
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa,WAAW,eAAe;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useMemo, useState } from '@wordpress/element';\nimport { Spinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { Cropper } from '../../image-editor';\nimport { useMediaEditor, resolveAspectRatio } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Focus the crop area when the canvas mounts. */\n\tfocusOnMount?: boolean;\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas cropper gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas cropper gesture ends. */\n\tonGestureEnd?: () => void;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its cropper controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.focusOnMount\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n */\nexport default function MediaEditorCanvas( {\n\tfocusOnMount,\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst controller = useMediaEditor();\n\tconst { aspectRatioValue } = controller.cropOptions;\n\tconst cropperImage = controller.state.image;\n\tconst { beginGesture, endGesture, setImage } = controller;\n\n\t// Tracks whether the image pixels have actually loaded. The cropper's\n\t// geometry is driven by the known media dimensions, so its handles and\n\t// overlays would otherwise appear before the image finishes streaming in.\n\tconst [ status, setStatus ] = useState< 'loading' | 'loaded' | 'error' >(\n\t\t'loading'\n\t);\n\n\t// Resolved aspect ratio is derived from the preset key + the\n\t// loaded image (for the \"Original\" preset). The reducer doesn't\n\t// store this number — only the preset key — so it's a render-time\n\t// derivation here.\n\tconst aspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\n\t);\n\n\tconst handleGestureStart = useCallback( () => {\n\t\tbeginGesture();\n\t\tonGestureStart?.();\n\t}, [ beginGesture, onGestureStart ] );\n\n\tconst handleGestureEnd = useCallback( () => {\n\t\tendGesture();\n\t\tonGestureEnd?.();\n\t}, [ endGesture, onGestureEnd ] );\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\tconst mediaWidth = Number( media?.media_details?.width );\n\tconst mediaHeight = Number( media?.media_details?.height );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tcropperImage ||\n\t\t\t! mediaUrl ||\n\t\t\t! Number.isFinite( mediaWidth ) ||\n\t\t\t! Number.isFinite( mediaHeight ) ||\n\t\t\tmediaWidth <= 0 ||\n\t\t\tmediaHeight <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ cropperImage, mediaUrl, mediaWidth, mediaHeight, setImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\n\t// Probe the image to know when its pixels have loaded (or failed),\n\t// independent of the cropper. The browser shares one fetch/cache with the\n\t// cropper's own `<img>`, so this adds no network cost. The cropper stays\n\t// framework-pure — load/error handling lives here in the wrapper layer.\n\tuseEffect( () => {\n\t\tif ( ! mediaUrl || ! isImage ) {\n\t\t\treturn;\n\t\t}\n\t\tsetStatus( 'loading' );\n\t\tconst probe = new window.Image();\n\t\tprobe.onload = () => setStatus( 'loaded' );\n\t\tprobe.onerror = () => setStatus( 'error' );\n\t\tprobe.src = mediaUrl;\n\t\t// Cached images may already be complete before listeners attach.\n\t\tif ( probe.complete ) {\n\t\t\tsetStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );\n\t\t}\n\t\treturn () => {\n\t\t\tprobe.onload = null;\n\t\t\tprobe.onerror = null;\n\t\t};\n\t}, [ mediaUrl, isImage ] );\n\n\tif ( ! mediaUrl || ! isImage ) {\n\t\treturn null;\n\t}\n\n\tif ( status === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-canvas\">\n\t\t\t\t<div className=\"media-editor-canvas__error\" role=\"alert\">\n\t\t\t\t\t<p>{ __( 'Failed to load image.' ) }</p>\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-canvas\">\n\t\t\t{ status === 'loading' && (\n\t\t\t\t<div className=\"media-editor-canvas__spinner\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The cropper stays mounted while loading (hidden behind the\n\t\t\t * spinner) so the image decodes off-screen and reveals in one paint\n\t\t\t * instead of streaming in top-to-bottom. Until it's revealed it's\n\t\t\t * non-interactive (`pointer-events: none` in CSS), and focus is\n\t\t\t * withheld by gating `focusOnMount` on the loaded state — the\n\t\t\t * cropper's focus effect keys off that prop, so focus lands on the\n\t\t\t * crop area only once it's visible.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'media-editor-canvas__cropper', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<Cropper\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ controller }\n\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\tfocusOnMount={ focusOnMount && status === 'loaded' }\n\t\t\t\t\tshowGrid=\"interactive\"\n\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,aAAa,WAAW,SAAS,gBAAgB;AAC1D,SAAS,eAAe;AACxB,SAAS,UAAU;AAKnB,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,SAAS,eAAe;AACxB,SAAS,gBAAgB,0BAA0B;AAyH9C,cAOH,YAPG;AA9FU,SAAR,kBAAoC;AAAA,EAC1C;AAAA,EACA,oBAAoB;AAAA,EACpB;AAAA,EACA;AACD,GAA4B;AAC3B,QAAM,EAAE,MAAM,IAAI,sBAAsB;AACxC,QAAM,aAAa,eAAe;AAClC,QAAM,EAAE,iBAAiB,IAAI,WAAW;AACxC,QAAM,eAAe,WAAW,MAAM;AACtC,QAAM,EAAE,cAAc,YAAY,SAAS,IAAI;AAK/C,QAAM,CAAE,QAAQ,SAAU,IA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AY,CAAE,SAAU;AAC9B,WAAO;AAAA,EACR;AAEA,MAAK,WAAW,SAAU;AACzB,WACC,oBAAC,SAAI,WAAU,uBACd,8BAAC,SAAI,WAAU,8BAA6B,MAAK,SAChD,8BAAC,OAAI,aAAI,uBAAwB,GAAG,GACrC,GACD;AAAA,EAEF;AAEA,SACC,qBAAC,SAAI,WAAU,uBACZ;AAAA,eAAW,aACZ,oBAAC,SAAI,WAAU,gCACd,8BAAC,WAAQ,GACV;AAAA,IAWD;AAAA,MAAC;AAAA;AAAA,QACA,WAAY,KAAM,gCAAgC;AAAA,UACjD,aAAa,WAAW;AAAA,QACzB,CAAE;AAAA,QAEF;AAAA,UAAC;AAAA;AAAA,YACA,KAAM;AAAA,YACN;AAAA,YACA;AAAA,YACA,cAAY;AAAA,YACZ,cAAe,gBAAgB,WAAW;AAAA,YAC1C,UAAS;AAAA,YACT;AAAA,YACA,gBAAiB;AAAA,YACjB,cAAe;AAAA;AAAA,QAChB;AAAA;AAAA,IACD;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor-fine-rotation/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation } = useMediaEditor();\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation } = useMediaEditor();\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,UAAU;AAKnB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,OAAO,mBAAmB;AAsDvB;AAtCY,SAAR,wBAA0C;AAAA,EAChD;AACD,GAAkC;AACjC,QAAM,EAAE,OAAO,YAAY,IAAI,eAAe;AAI9C,QAAM,0BAA0B,uBAAwB;AAAA,IACvD,eAAe;AAAA,EAChB,CAAE;AAKF,QAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;AACtD,QAAM,aAAa,MAAM,KAAK,eAAe,MAAM,KAAK;AACxD,QAAM,YAAY,aAAa,KAAK;AACpC,QAAM,cAAe,MAAM,WAAW,aAAc;AAEpD,QAAM,uBAAuB,CAAE,UAAmB;AAIjD,UAAM,MAAM;AACZ,UAAM,UAAU,KAAK;AAAA,MACpB,CAAC,sBAAsB;AAAA,MACvB,KAAK,IAAK,sBAAsB,KAAK,KAAM;AAAA,IAC5C;AACA,oCAAgC;AAChC,gBAAa,YAAY,UAAU,SAAU;AAAA,EAC9C;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,WAAU;AAAA,MACR,GAAG;AAAA,MAEL;AAAA,QAAC;AAAA;AAAA,UACA,OAAQ,GAAI,eAAgB;AAAA,UAC5B,KAAM,CAAC;AAAA,UACP,KAAM;AAAA,UACN,OAAQ;AAAA,UACR,UAAW;AAAA;AAAA,MACZ;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -45,7 +45,7 @@ function MediaEditorImageControls({
|
|
|
45
45
|
{
|
|
46
46
|
size: "compact",
|
|
47
47
|
icon: rotateLeft,
|
|
48
|
-
label: __("Rotate 90
|
|
48
|
+
label: __("Rotate 90° counter-clockwise"),
|
|
49
49
|
showTooltip: true,
|
|
50
50
|
onClick: () => snapRotate90(-1)
|
|
51
51
|
}
|
|
@@ -55,7 +55,7 @@ function MediaEditorImageControls({
|
|
|
55
55
|
{
|
|
56
56
|
size: "compact",
|
|
57
57
|
icon: rotateRight,
|
|
58
|
-
label: __("Rotate 90
|
|
58
|
+
label: __("Rotate 90° clockwise"),
|
|
59
59
|
showTooltip: true,
|
|
60
60
|
onClick: () => snapRotate90(1)
|
|
61
61
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB;AAAA,EACC,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,OAEM;AACP,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAiE7B,mBACC,KADD;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,IAAI,eAAe;AACjE,QAAM,EAAE,kBAAkB,qBAAqB,mBAAmB,IACjE,eAAgB,EAAE,mBAAmB,CAAE;AACxC,QAAM,wBAAwB,CAAE,cAAc;AAC9C,QAAM,UAAU,WAAY,KAAM;AAClC,QAAM,eAAe,CAAE,WAAoB;AAC1C;AAAA,MACC,KAAK,IAAK,UAAU,KAAK,IAAK,SAAS,MAAM,OAAO,MAAO,CAAE;AAAA,IAC9D;AAAA,EACD;AAEA,QAAM,gBACL,iCACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,MAAO;AAAA,QACP,OAAQ,GAAI,
|
|
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 — rather than an additive step — makes each click feel like the\n * same amount of zoom at any level (an additive `+0.1` is a 10% jump at 1× but\n * a ~1% nudge at 10×). `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 — the Crop\n\t * panel layout used on wide viewports. When `false` (default), render a\n\t * single flat row of icon buttons — 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 — 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° 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° 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": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB;AAAA,EACC,eAAe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,OAEM;AACP,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;A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AEJ,MAAK,YAAa;AACjB,WACC,qBAAC,SAAI,WAAU,0CACd;AAAA,2BAAC,SAAI,WAAU,2CACd;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,MAAK;AAAA,YACL,cAAa,GAAI,QAAS;AAAA,YAE1B;AAAA;AAAA,gBAAC;AAAA;AAAA,kBACA,WAAU;AAAA,kBACV,eAAY;AAAA,kBAEV,aAAI,QAAS;AAAA;AAAA,cAChB;AAAA,cACA,oBAAC,SAAI,WAAU,wCACZ,yBACH;AAAA;AAAA;AAAA,QACD;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,MAAK;AAAA,YACL,cAAa,GAAI,MAAO;AAAA,YAExB;AAAA;AAAA,gBAAC;AAAA;AAAA,kBACA,WAAU;AAAA,kBACV,eAAY;AAAA,kBAEV,aAAI,MAAO;AAAA;AAAA,cACd;AAAA,cACA,oBAAC,SAAI,WAAU,wCACZ,uBACH;AAAA;AAAA;AAAA,QACD;AAAA,SACD;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACA,WAAU;AAAA,UACV,MAAK;AAAA,UACL,cAAa,GAAI,MAAO;AAAA,UAExB;AAAA;AAAA,cAAC;AAAA;AAAA,gBACA,WAAU;AAAA,gBACV,eAAY;AAAA,gBAEV,aAAI,MAAO;AAAA;AAAA,YACd;AAAA,YACA,oBAAC,SAAI,WAAU,wCACZ,uBACH;AAAA;AAAA;AAAA,MACD;AAAA,OACD;AAAA,EAEF;AAEA,SACC,qBAAC,SAAI,WAAU,+BACZ;AAAA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,KACH;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,7 +19,7 @@ var SHORTCUTS = [
|
|
|
19
19
|
{
|
|
20
20
|
description: __("Pan"),
|
|
21
21
|
keyCombination: {
|
|
22
|
-
character: ["
|
|
22
|
+
character: ["↑", "↓", "←", "→"],
|
|
23
23
|
ariaLabel: __("Arrow keys")
|
|
24
24
|
}
|
|
25
25
|
},
|
|
@@ -32,11 +32,11 @@ var SHORTCUTS = [
|
|
|
32
32
|
keyCombination: { character: "-" }
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
description: __("Rotate 90
|
|
35
|
+
description: __("Rotate 90° clockwise"),
|
|
36
36
|
keyCombination: { character: "R" }
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
|
-
description: __("Rotate 90
|
|
39
|
+
description: __("Rotate 90° counter-clockwise"),
|
|
40
40
|
keyCombination: { modifier: "shift", character: "R" }
|
|
41
41
|
},
|
|
42
42
|
{
|
|
@@ -51,7 +51,7 @@ var SHORTCUTS = [
|
|
|
51
51
|
description: __("Pan or resize crop (large step)"),
|
|
52
52
|
keyCombination: {
|
|
53
53
|
modifier: "shift",
|
|
54
|
-
character: ["
|
|
54
|
+
character: ["↑", "↓", "←", "→"],
|
|
55
55
|
ariaLabel: __("Shift + Arrow keys")
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor-keyboard-shortcuts-modal/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\n\ninterface KeyCombination {\n\t/** Modifier for cross-platform display (e.g. 'primary', 'primaryShift', 'shift'). */\n\tmodifier?: WPKeycodeModifier;\n\t/** The key character(s) to display. Pass an array to render each as its own key. */\n\tcharacter: string | string[];\n\t/** Optional aria-label override (used when character is a symbol). */\n\tariaLabel?: string;\n}\n\ninterface ShortcutEntry {\n\tdescription: string;\n\tkeyCombination: KeyCombination;\n}\n\nconst SHORTCUTS: ShortcutEntry[] = [\n\t{\n\t\tdescription: __( 'Undo' ),\n\t\tkeyCombination: { modifier: 'primary', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Redo' ),\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Pan' ),\n\t\tkeyCombination: {\n\t\t\tcharacter: [ '
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AA4GF,cA0CA,YA1CA;AA5FL,IAAM,YAA6B;AAAA,EAClC;AAAA,IACC,aAAa,GAAI,MAAO;AAAA,IACxB,gBAAgB,EAAE,UAAU,WAAW,WAAW,IAAI;AAAA,EACvD;AAAA,EACA;AAAA,IACC,aAAa,GAAI,MAAO;AAAA,IACxB,gBAAgB,EAAE,UAAU,gBAAgB,WAAW,IAAI;AAAA,EAC5D;AAAA,EACA;AAAA,IACC,aAAa,GAAI,KAAM;AAAA,IACvB,gBAAgB;AAAA,MACf,WAAW,CAAE,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Modal } from '@wordpress/components';\nimport { Fragment } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tdisplayShortcutList,\n\tshortcutAriaLabel,\n\ttype WPKeycodeModifier,\n} from '@wordpress/keycodes';\n\ninterface KeyCombination {\n\t/** Modifier for cross-platform display (e.g. 'primary', 'primaryShift', 'shift'). */\n\tmodifier?: WPKeycodeModifier;\n\t/** The key character(s) to display. Pass an array to render each as its own key. */\n\tcharacter: string | string[];\n\t/** Optional aria-label override (used when character is a symbol). */\n\tariaLabel?: string;\n}\n\ninterface ShortcutEntry {\n\tdescription: string;\n\tkeyCombination: KeyCombination;\n}\n\nconst SHORTCUTS: ShortcutEntry[] = [\n\t{\n\t\tdescription: __( 'Undo' ),\n\t\tkeyCombination: { modifier: 'primary', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Redo' ),\n\t\tkeyCombination: { modifier: 'primaryShift', character: 'z' },\n\t},\n\t{\n\t\tdescription: __( 'Pan' ),\n\t\tkeyCombination: {\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t\tariaLabel: __( 'Arrow keys' ),\n\t\t},\n\t},\n\t{\n\t\tdescription: __( 'Zoom in' ),\n\t\tkeyCombination: { character: '+' },\n\t},\n\t{\n\t\tdescription: __( 'Zoom out' ),\n\t\tkeyCombination: { character: '-' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° clockwise' ),\n\t\tkeyCombination: { character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Rotate 90° counter-clockwise' ),\n\t\tkeyCombination: { modifier: 'shift', character: 'R' },\n\t},\n\t{\n\t\tdescription: __( 'Flip horizontal' ),\n\t\tkeyCombination: { character: 'H' },\n\t},\n\t{\n\t\tdescription: __( 'Flip vertical' ),\n\t\tkeyCombination: { character: 'V' },\n\t},\n\t{\n\t\tdescription: __( 'Pan or resize crop (large step)' ),\n\t\tkeyCombination: {\n\t\t\tmodifier: 'shift',\n\t\t\tcharacter: [ '↑', '↓', '←', '→' ],\n\t\t\tariaLabel: __( 'Shift + Arrow keys' ),\n\t\t},\n\t},\n];\n\nfunction KeyCombinationDisplay( {\n\tkeyCombination,\n}: {\n\tkeyCombination: KeyCombination;\n} ) {\n\tconst { modifier, character, ariaLabel } = keyCombination;\n\n\tlet keys: string[];\n\tif ( Array.isArray( character ) ) {\n\t\tif ( modifier ) {\n\t\t\t// Get the modifier prefix (e.g. ['⇧', '+']) from the first char,\n\t\t\t// then replace the last element with all the individual chars.\n\t\t\tconst sample = displayShortcutList[ modifier ]( character[ 0 ] );\n\t\t\tkeys = [ ...sample.slice( 0, -1 ), ...character ];\n\t\t} else {\n\t\t\tkeys = character;\n\t\t}\n\t} else {\n\t\tkeys = modifier\n\t\t\t? displayShortcutList[ modifier ]( character )\n\t\t\t: [ character ];\n\t}\n\n\tconst charString = Array.isArray( character )\n\t\t? character.join( '' )\n\t\t: character;\n\tlet label: string;\n\tif ( ariaLabel ) {\n\t\tlabel = ariaLabel;\n\t} else if ( modifier ) {\n\t\tlabel = shortcutAriaLabel[ modifier ]( charString );\n\t} else {\n\t\tlabel = charString;\n\t}\n\n\treturn (\n\t\t<kbd\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-term\"\n\t\t\taria-label={ label }\n\t\t>\n\t\t\t{ keys.map( ( key, index ) =>\n\t\t\t\tkey === '+' && modifier ? (\n\t\t\t\t\t<Fragment key={ index }>{ key }</Fragment>\n\t\t\t\t) : (\n\t\t\t\t\t<kbd\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-key\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ key }\n\t\t\t\t\t</kbd>\n\t\t\t\t)\n\t\t\t) }\n\t\t</kbd>\n\t);\n}\n\ninterface MediaEditorKeyboardShortcutsModalProps {\n\tonClose: () => void;\n}\n\nexport default function MediaEditorKeyboardShortcutsModal( {\n\tonClose,\n}: MediaEditorKeyboardShortcutsModalProps ) {\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal\"\n\t\t\ttitle={ __( 'Keyboard shortcuts' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t<p className=\"media-editor-keyboard-shortcuts-modal__note\">\n\t\t\t\t{ __(\n\t\t\t\t\t'These shortcuts work when the image editor has focus.'\n\t\t\t\t) }\n\t\t\t</p>\n\t\t\t{ /*\n\t\t\t * Disable reason: The `list` ARIA role is redundant but\n\t\t\t * Safari+VoiceOver won't announce the list otherwise.\n\t\t\t */ }\n\t\t\t{ /* eslint-disable jsx-a11y/no-redundant-roles */ }\n\t\t\t<ul\n\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut-list\"\n\t\t\t\trole=\"list\"\n\t\t\t>\n\t\t\t\t{ SHORTCUTS.map( ( { description, keyCombination }, index ) => (\n\t\t\t\t\t<li\n\t\t\t\t\t\tkey={ index }\n\t\t\t\t\t\tclassName=\"media-editor-keyboard-shortcuts-modal__shortcut\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"media-editor-keyboard-shortcuts-modal__shortcut-description\">\n\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t<KeyCombinationDisplay\n\t\t\t\t\t\t\tkeyCombination={ keyCombination }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</li>\n\t\t\t\t) ) }\n\t\t\t</ul>\n\t\t\t{ /* eslint-enable jsx-a11y/no-redundant-roles */ }\n\t\t</Modal>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AA4GF,cA0CA,YA1CA;AA5FL,IAAM,YAA6B;AAAA,EAClC;AAAA,IACC,aAAa,GAAI,MAAO;AAAA,IACxB,gBAAgB,EAAE,UAAU,WAAW,WAAW,IAAI;AAAA,EACvD;AAAA,EACA;AAAA,IACC,aAAa,GAAI,MAAO;AAAA,IACxB,gBAAgB,EAAE,UAAU,gBAAgB,WAAW,IAAI;AAAA,EAC5D;AAAA,EACA;AAAA,IACC,aAAa,GAAI,KAAM;AAAA,IACvB,gBAAgB;AAAA,MACf,WAAW,CAAE,KAAK,KAAK,KAAK,GAAI;AAAA,MAChC,WAAW,GAAI,YAAa;AAAA,IAC7B;AAAA,EACD;AAAA,EACA;AAAA,IACC,aAAa,GAAI,SAAU;AAAA,IAC3B,gBAAgB,EAAE,WAAW,IAAI;AAAA,EAClC;AAAA,EACA;AAAA,IACC,aAAa,GAAI,UAAW;AAAA,IAC5B,gBAAgB,EAAE,WAAW,IAAI;AAAA,EAClC;AAAA,EACA;AAAA,IACC,aAAa,GAAI,sBAAuB;AAAA,IACxC,gBAAgB,EAAE,WAAW,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AAO,WACd,oBAAC,YAAyB,iBAAV,KAAe,IAE/B;AAAA,UAAC;AAAA;AAAA,YAEA,WAAU;AAAA,YAER;AAAA;AAAA,UAHI;AAAA,QAIP;AAAA,MAEF;AAAA;AAAA,EACD;AAEF;AAMe,SAAR,kCAAoD;AAAA,EAC1D;AACD,GAA4C;AAC3C,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,OAAQ,GAAI,oBAAqB;AAAA,MACjC,gBAAiB;AAAA,MAEjB;AAAA,4BAAC,OAAE,WAAU,+CACV;AAAA,UACD;AAAA,QACD,GACD;AAAA,QAMA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,MAAK;AAAA,YAEH,oBAAU,IAAK,CAAE,EAAE,aAAa,eAAe,GAAG,UACnD;AAAA,cAAC;AAAA;AAAA,gBAEA,WAAU;AAAA,gBAEV;AAAA,sCAAC,UAAK,WAAU,+DACb,uBACH;AAAA,kBACA;AAAA,oBAAC;AAAA;AAAA,sBACA;AAAA;AAAA,kBACD;AAAA;AAAA;AAAA,cARM;AAAA,YASP,CACC;AAAA;AAAA,QACH;AAAA;AAAA;AAAA,EAED;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/media-editor-modal/build-modifiers.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../image-editor';\nimport { getRotatedBBox } from '../../image-editor/core/camera';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../image-editor';\nimport { getRotatedBBox } from '../../image-editor/core/camera';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant — the server applies modifiers sequentially (see\n * `WP_REST_Attachments_Controller::edit_media_item`).\n *\n * Shape/units:\n * - `flip`: booleans per axis. Applied first in this module's output.\n * - `rotate`: `angle` in degrees, clockwise-positive (matches the\n * cropper's own convention; Core negates it internally for\n * `WP_Image_Editor::rotate`, which is counterclockwise-positive).\n * - `crop`: percentages (0–100) of the image's dimensions **at the\n * moment the crop is applied**. Because modifiers are applied in\n * order, after a preceding `rotate` the server's\n * `WP_Image_Editor::get_size()` reports the full post-rotate AABB,\n * so the percentages are of that AABB. Origin is top-left.\n */\nexport type Modifier =\n\t| {\n\t\t\ttype: 'flip';\n\t\t\targs: { flip: { horizontal: boolean; vertical: boolean } };\n\t }\n\t| { type: 'rotate'; args: { angle: number } }\n\t| {\n\t\t\ttype: 'crop';\n\t\t\targs: { left: number; top: number; width: number; height: number };\n\t };\n\n/**\n * Tolerance (percent) used to decide whether a crop rect is effectively\n * full-frame. Sub-pixel / float-ulp deltas below this value are treated\n * as no crop. Matches the historical threshold used by the legacy\n * `use-save-image.js` (which compared against `99.9`).\n */\nconst CROP_TOLERANCE = 0.1;\n\n/**\n * Build a Core-compatible modifiers array from the cropper state.\n *\n * Emits `[flip, rotate, crop]` in that order. Identity operations are\n * pruned — an absent flip, a rotation that normalizes to 0°, and a crop\n * rect that covers (within tolerance) the full post-rotate AABB each\n * produce no modifier. An identity state (fresh image, no edits) returns\n * an empty array; callers can use that to skip the `/edit` call.\n *\n * Frames and math:\n *\n * The cropper's `cropRect` is stored as fractions of the **snap-rotation**\n * bounding box (the stencil-reference frame — see `createCamera` /\n * `createExportCamera`). Pan is in that frame; zoom scales the image\n * beneath a fixed stencil. Two conversions are needed to reach the frame\n * Core's crop modifier applies against:\n *\n * 1. Express the stencil rect in snap-AABB **pixels**:\n * Image screen-normalized top-left with zoom/pan is\n * `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the\n * inverse of that transform applied to `cropRect`.\n *\n * 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs\n * share the source-image center, so the conversion is a pure\n * translation by `(fullCenter - snapCenter)`. Finally, express the\n * translated rect as percentages of the full AABB.\n *\n * Rotation sign: the cropper composes `flip · R(θ)` on the source (see\n * `createExportCamera` — rotate then flip). Core's `[flip, rotate]`\n * applies the opposite order: `R(θ') · flip`. For both to land on the\n * same pixels we invert the rotation sign when exactly one flip axis\n * is set (`flip_h · R(θ) = R(-θ) · flip_h`). Both-or-neither flips\n * leave the sign alone because `flip_h · flip_v = -I` commutes with\n * rotation.\n *\n * @param state Current cropper state.\n * @param imageSize Natural dimensions of the source image.\n * @return Ordered modifier array; empty when nothing is server-relevant.\n */\nexport function buildModifiers(\n\tstate: CropperState,\n\timageSize: Size\n): Modifier[] {\n\tconst modifiers: Modifier[] = [];\n\n\tif ( imageSize.width === 0 || imageSize.height === 0 ) {\n\t\treturn modifiers;\n\t}\n\n\tconst { cropRect, pan, zoom, flip } = state;\n\tconst hasFlipH = flip.horizontal;\n\tconst hasFlipV = flip.vertical;\n\n\tif ( hasFlipH || hasFlipV ) {\n\t\tmodifiers.push( {\n\t\t\ttype: 'flip',\n\t\t\targs: { flip: { horizontal: hasFlipH, vertical: hasFlipV } },\n\t\t} );\n\t}\n\n\tconst rawAngle = ( ( state.rotation % 360 ) + 360 ) % 360;\n\t// Invert the sign for single-axis flips so Core's `flip → rotate`\n\t// pipeline matches the cropper's `rotate → flip` composition.\n\tconst singleAxisFlip = hasFlipH !== hasFlipV;\n\tconst signedAngle = singleAxisFlip ? ( 360 - rawAngle ) % 360 : rawAngle;\n\tif ( signedAngle !== 0 ) {\n\t\tmodifiers.push( { type: 'rotate', args: { angle: signedAngle } } );\n\t}\n\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst { width: snapW, height: snapH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\tconst { width: fullW, height: fullH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tstate.rotation\n\t);\n\n\t// Stencil rect in snap-AABB pixels. Inverts `createExportCamera`'s\n\t// pan/zoom composition to recover the pixel rectangle the stencil\n\t// framed in that frame.\n\tconst imgLeft = 0.5 + pan.x - zoom / 2;\n\tconst imgTop = 0.5 + pan.y - zoom / 2;\n\tconst snapX = ( ( cropRect.x - imgLeft ) / zoom ) * snapW;\n\tconst snapY = ( ( cropRect.y - imgTop ) / zoom ) * snapH;\n\tconst widthPx = ( cropRect.width / zoom ) * snapW;\n\tconst heightPx = ( cropRect.height / zoom ) * snapH;\n\n\t// Translate to the full AABB (both centered on source).\n\tconst offsetX = ( fullW - snapW ) / 2;\n\tconst offsetY = ( fullH - snapH ) / 2;\n\tconst fullX = snapX + offsetX;\n\tconst fullY = snapY + offsetY;\n\n\t// Percentages of the full AABB — Core's crop frame after rotate.\n\tconst leftPct = ( fullX / fullW ) * 100;\n\tconst topPct = ( fullY / fullH ) * 100;\n\tconst widthPct = ( widthPx / fullW ) * 100;\n\tconst heightPct = ( heightPx / fullH ) * 100;\n\n\tconst coversFullFrame =\n\t\tleftPct <= CROP_TOLERANCE &&\n\t\ttopPct <= CROP_TOLERANCE &&\n\t\twidthPct >= 100 - CROP_TOLERANCE &&\n\t\theightPct >= 100 - CROP_TOLERANCE;\n\n\tif ( ! coversFullFrame ) {\n\t\tmodifiers.push( {\n\t\t\ttype: 'crop',\n\t\t\targs: {\n\t\t\t\tleft: leftPct,\n\t\t\t\ttop: topPct,\n\t\t\t\twidth: widthPct,\n\t\t\t\theight: heightPct,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn modifiers;\n}\n"],
|
|
5
5
|
"mappings": ";AAIA,SAAS,sBAAsB;AAmC/B,IAAM,iBAAiB;AAyChB,SAAS,eACf,OACA,WACa;AACb,QAAM,YAAwB,CAAC;AAE/B,MAAK,UAAU,UAAU,KAAK,UAAU,WAAW,GAAI;AACtD,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,UAAU,KAAK,MAAM,KAAK,IAAI;AACtC,QAAM,WAAW,KAAK;AACtB,QAAM,WAAW,KAAK;AAEtB,MAAK,YAAY,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,KAAM;AAAA,MACf,MAAM;AAAA,MACN,MAAM;AAAA,QACL,MAAM;AAAA,QACN,KAAK;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,MACT;AAAA,IACD,CAAE;AAAA,EACH;AAEA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/rotation-ruler/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useId, useMemo, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useRulerDrag, clampValue } from './use-ruler-drag';\n\nexport interface RotationRulerProps {\n\t/** Current value. */\n\tvalue: number;\n\t/** Called with the next value on each change. */\n\tonChange: ( value: number ) => void;\n\t/** Lower bound of the range. Default: -45. */\n\tmin?: number;\n\t/** Upper bound of the range. Default: 45. */\n\tmax?: number;\n\t/**\n\t * Value step for drag and keyboard arrows. Default: 1. Drag values\n\t * are quantized to multiples of `step`. Holding Shift during drag\n\t * or with arrow keys halves the step for precision adjustment.\n\t */\n\tstep?: number;\n\t/** Accessible label for the slider input. */\n\tlabel: string;\n\t/**\n\t * Unit suffix shown in the active label and `aria-valuetext`.\n\t * Default:
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useId, useMemo, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useRulerDrag, clampValue } from './use-ruler-drag';\n\nexport interface RotationRulerProps {\n\t/** Current value. */\n\tvalue: number;\n\t/** Called with the next value on each change. */\n\tonChange: ( value: number ) => void;\n\t/** Lower bound of the range. Default: -45. */\n\tmin?: number;\n\t/** Upper bound of the range. Default: 45. */\n\tmax?: number;\n\t/**\n\t * Value step for drag and keyboard arrows. Default: 1. Drag values\n\t * are quantized to multiples of `step`. Holding Shift during drag\n\t * or with arrow keys halves the step for precision adjustment.\n\t */\n\tstep?: number;\n\t/** Accessible label for the slider input. */\n\tlabel: string;\n\t/**\n\t * Unit suffix shown in the active label and `aria-valuetext`.\n\t * Default: `°`.\n\t */\n\tunit?: string;\n\t/** CSS pixels of pointer travel per `step`. Default: 6. */\n\tpixelsPerStep?: number;\n\t/** Optional extra class for the wrapper. */\n\tclassName?: string;\n\t/**\n\t * Optional id for the underlying input; auto-generated when\n\t * omitted.\n\t */\n\tid?: string;\n\t/** When true, ignores all input. */\n\tdisabled?: boolean;\n}\n\nconst STRIP_HEIGHT = 32;\nconst LABEL_BASELINE_Y = 11;\nconst MAJOR_INTERVAL = 15;\nconst TICK_HEIGHT_MINOR = 4;\nconst TICK_HEIGHT_MID = 8;\nconst TICK_HEIGHT_MAJOR = 14;\n\ntype TickKind = 'minor' | 'mid' | 'major';\ninterface Tick {\n\tvalue: number;\n\tkind: TickKind;\n\theight: number;\n}\n\n/**\n * Build the tick list for the ruler strip.\n *\n * @param min Lower bound of the ruler in value units.\n * @param max Upper bound of the ruler in value units.\n */\nfunction useTicks( min: number, max: number ): Tick[] {\n\treturn useMemo( () => {\n\t\tconst out: Tick[] = [];\n\t\tfor ( let v = Math.ceil( min ); v <= Math.floor( max ); v += 1 ) {\n\t\t\tlet kind: TickKind = 'minor';\n\t\t\tlet height = TICK_HEIGHT_MINOR;\n\t\t\tif ( v % 15 === 0 ) {\n\t\t\t\tkind = 'major';\n\t\t\t\theight = TICK_HEIGHT_MAJOR;\n\t\t\t} else if ( v % 5 === 0 ) {\n\t\t\t\tkind = 'mid';\n\t\t\t\theight = TICK_HEIGHT_MID;\n\t\t\t}\n\t\t\tout.push( { value: v, kind, height } );\n\t\t}\n\t\treturn out;\n\t}, [ min, max ] );\n}\n\n/**\n * Format a numeric ruler value for display, trimming a trailing `.0`.\n *\n * @param value Value to format.\n */\nfunction formatValue( value: number ): string {\n\tconst rounded = Math.round( value * 10 ) / 10;\n\treturn Number.isInteger( rounded )\n\t\t? rounded.toFixed( 0 )\n\t\t: rounded.toFixed( 1 );\n}\n\n/**\n * Horizontal \"scrub-the-ruler\" slider for fine-grained numeric input\n * such as rotation in degrees.\n *\n * Renders a visually hidden `<input type=\"range\">` for assistive\n * technologies and keyboard input alongside a decorative tick strip\n * that the user can drag with a pointer.\n *\n * @param props Component props. See `RotationRulerProps`.\n */\nexport default function RotationRuler( props: RotationRulerProps ) {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin = -45,\n\t\tmax = 45,\n\t\tstep = 1,\n\t\tlabel,\n\t\tunit = '°',\n\t\tpixelsPerStep = 6,\n\t\tclassName,\n\t\tid,\n\t\tdisabled = false,\n\t} = props;\n\tconst inputRef = useRef< HTMLInputElement >( null );\n\tconst generatedId = useId();\n\tconst inputId = id ?? generatedId;\n\n\tconst dragHandlers = useRulerDrag( {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart: () => inputRef.current?.focus(),\n\t} );\n\n\tconst handleKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\t// WAI-ARIA slider keyboard pattern: Up/Right increment,\n\t\t// Down/Left decrement. Home / End / PageUp / PageDown fall\n\t\t// through to native input.\n\t\tconst isIncrement =\n\t\t\tevent.key === 'ArrowRight' || event.key === 'ArrowUp';\n\t\tconst isDecrement =\n\t\t\tevent.key === 'ArrowLeft' || event.key === 'ArrowDown';\n\t\tif ( ! isIncrement && ! isDecrement ) {\n\t\t\treturn;\n\t\t}\n\t\t// Always prevent default so the native input's own arrow-key\n\t\t// stepping doesn't double-fire `onChange` after our custom emit.\n\t\tevent.preventDefault();\n\t\tif ( disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst direction = isIncrement ? 1 : -1;\n\t\t// Shift halves the step for precision adjustment\n\t\t// (e.g. 0.5° rotation when step is 1°). Same modifier works\n\t\t// on drag — see `useRulerDrag`.\n\t\tconst magnitude = event.shiftKey ? step / 2 : step;\n\t\tconst next = clampValue( value + direction * magnitude, min, max );\n\t\tif ( next !== value ) {\n\t\t\tonChange( next );\n\t\t}\n\t};\n\n\tconst display = `${ formatValue( value ) }${ unit }`;\n\tconst ticks = useTicks( min, max );\n\t// Visual scale is locked to the gesture: 1 step of pointer travel\n\t// (`pixelsPerStep`) maps to `step` value units, so 1 value unit\n\t// renders at `pixelsPerStep / step` CSS pixels. This keeps the\n\t// ticks moving in lock-step with the pointer no matter what the\n\t// caller chooses for `pixelsPerStep` and `step`.\n\tconst pxPerUnit = pixelsPerStep / step;\n\t// `left: 50%` puts the SVG's left edge at the strip's centerline, so\n\t// without an additional `-50%` self-offset all ticks would render to\n\t// the right of the pointer. Combine the centering offset with the\n\t// value-driven offset so value=0 lands the SVG's center on the\n\t// pointer.\n\tconst stripStyle: CSSProperties = useMemo( () => {\n\t\tconst offset = -value * pxPerUnit;\n\t\treturn {\n\t\t\ttransform: `translateX(calc(-50% + ${ offset }px))`,\n\t\t};\n\t}, [ value, pxPerUnit ] );\n\n\t// Closest major (every 15°) to current value. Its normal label is\n\t// suppressed and replaced by the active label, which sits exactly\n\t// under the pointer and shows the precise current value when off-\n\t// major (e.g. \"-7°\") or the major itself when on-major (e.g. \"0°\").\n\tconst closestMajor = Math.round( value / MAJOR_INTERVAL ) * MAJOR_INTERVAL;\n\tconst onMajor = Math.abs( value - closestMajor ) < 0.01;\n\t// Split the number into sign + digits so the sign is rendered in a\n\t// separate span and excluded from the active label's centering, the\n\t// same way the unit is.\n\tconst numberText = onMajor ? `${ closestMajor }` : formatValue( value );\n\tconst isNegative = numberText.startsWith( '-' );\n\tconst digits = isNegative ? numberText.slice( 1 ) : numberText;\n\tconst majorTicks = ticks.filter( ( tick ) => tick.kind === 'major' );\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'rotation-ruler', className ) }\n\t\t\trole=\"presentation\"\n\t\t\tdata-disabled={ disabled || undefined }\n\t\t\t{ ...dragHandlers }\n\t\t>\n\t\t\t<input\n\t\t\t\tref={ inputRef }\n\t\t\t\tid={ inputId }\n\t\t\t\ttype=\"range\"\n\t\t\t\tclassName=\"rotation-ruler__input\"\n\t\t\t\tmin={ min }\n\t\t\t\tmax={ max }\n\t\t\t\tstep=\"any\"\n\t\t\t\tvalue={ value }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taria-label={ label }\n\t\t\t\taria-valuetext={ display }\n\t\t\t\tonChange={ ( event ) =>\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tclampValue( event.target.valueAsNumber, min, max )\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tonKeyDown={ handleKeyDown }\n\t\t\t/>\n\t\t\t<div className=\"rotation-ruler__strip\" aria-hidden=\"true\">\n\t\t\t\t<svg\n\t\t\t\t\tclassName=\"rotation-ruler__ticks\"\n\t\t\t\t\tstyle={ stripStyle }\n\t\t\t\t\twidth={ ( max - min ) * pxPerUnit }\n\t\t\t\t\theight={ STRIP_HEIGHT }\n\t\t\t\t\tviewBox={ `${ min * pxPerUnit } 0 ${\n\t\t\t\t\t\t( max - min ) * pxPerUnit\n\t\t\t\t\t} ${ STRIP_HEIGHT }` }\n\t\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t>\n\t\t\t\t\t{ ticks.map( ( tick ) => (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx1={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\tx2={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty1={ STRIP_HEIGHT - tick.height }\n\t\t\t\t\t\t\ty2={ STRIP_HEIGHT }\n\t\t\t\t\t\t\tclassName={ `rotation-ruler__tick rotation-ruler__tick--${ tick.kind }` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t\t{ majorTicks.map( ( tick ) => (\n\t\t\t\t\t\t<text\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty={ LABEL_BASELINE_Y }\n\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\tclassName=\"rotation-ruler__label\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ tick.value }\n\t\t\t\t\t\t\t{ unit }\n\t\t\t\t\t\t</text>\n\t\t\t\t\t) ) }\n\t\t\t\t</svg>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__active-label\" aria-hidden=\"true\">\n\t\t\t\t<span className=\"rotation-ruler__active-label-number\">\n\t\t\t\t\t{ isNegative && (\n\t\t\t\t\t\t<span className=\"rotation-ruler__active-label-sign\">\n\t\t\t\t\t\t\t-\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ digits }\n\t\t\t\t\t<span className=\"rotation-ruler__active-label-unit\">\n\t\t\t\t\t\t{ unit }\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__pointer\" aria-hidden=\"true\" />\n\t\t</div>\n\t);\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,OAAO,UAAU;AAMjB,SAAS,OAAO,SAAS,cAAc;AAKvC,SAAS,cAAc,kBAAkB;AAoMtC,cAyCG,YAzCH;AA/JH,IAAM,eAAe;AACrB,IAAM,mBAAmB;AACzB,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,kBAAkB;AACxB,IAAM,oBAAoB;AAe1B,SAAS,SAAU,KAAa,KAAsB;AACrD,SAAO,QAAS,MAAM;AACrB,UAAM,MAAc,CAAC;AACrB,aAAU,IAAI,KAAK,KAAM,GAAI,GAAG,KAAK,KAAK,MAAO,GAAI,GAAG,KAAK,GAAI;AAChE,UAAI,OAAiB;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Q;AAAA,YACR,QAAU,MAAM,OAAQ;AAAA,YACxB,QAAS;AAAA,YACT,SAAU,GAAI,MAAM,SAAU,OAC3B,MAAM,OAAQ,SACjB,IAAK,YAAa;AAAA,YAClB,qBAAoB;AAAA,YAElB;AAAA,oBAAM,IAAK,CAAE,SACd;AAAA,gBAAC;AAAA;AAAA,kBAEA,IAAK,KAAK,QAAQ;AAAA,kBAClB,IAAK,KAAK,QAAQ;AAAA,kBAClB,IAAK,eAAe,KAAK;AAAA,kBACzB,IAAK;AAAA,kBACL,WAAY,8CAA+C,KAAK,IAAK;AAAA;AAAA,gBAL/D,KAAK;AAAA,cAMZ,CACC;AAAA,cACA,WAAW,IAAK,CAAE,SACnB;AAAA,gBAAC;AAAA;AAAA,kBAEA,GAAI,KAAK,QAAQ;AAAA,kBACjB,GAAI;AAAA,kBACJ,YAAW;AAAA,kBACX,WAAU;AAAA,kBAER;AAAA,yBAAK;AAAA,oBACL;AAAA;AAAA;AAAA,gBAPI,KAAK;AAAA,cAQZ,CACC;AAAA;AAAA;AAAA,QACH,GACD;AAAA,QACA,oBAAC,SAAI,WAAU,gCAA+B,eAAY,QACzD,+BAAC,UAAK,WAAU,uCACb;AAAA,wBACD,oBAAC,UAAK,WAAU,qCAAoC,eAEpD;AAAA,UAEC;AAAA,UACF,oBAAC,UAAK,WAAU,qCACb,gBACH;AAAA,WACD,GACD;AAAA,QACA,oBAAC,SAAI,WAAU,2BAA0B,eAAY,QAAO;AAAA;AAAA;AAAA,EAC7D;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/rotation-ruler/use-ruler-drag.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Convert a horizontal pointer delta (px) into a value delta.\n *\n * Negative because dragging the ruler to the right should expose\n * smaller values to the left of the fixed center pointer (and vice\n * versa)
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Convert a horizontal pointer delta (px) into a value delta.\n *\n * Negative because dragging the ruler to the right should expose\n * smaller values to the left of the fixed center pointer (and vice\n * versa) — the ruler scrubs *under* the pointer.\n *\n * @param deltaPx Pointer movement in CSS pixels.\n * @param pixelsPerStep CSS pixels of pointer travel per `step`.\n * @param step Value units per step.\n */\nexport function pxToValueDelta(\n\tdeltaPx: number,\n\tpixelsPerStep: number,\n\tstep: number\n): number {\n\treturn ( -deltaPx / pixelsPerStep ) * step;\n}\n\n/**\n * Clamp `value` to the inclusive `[min, max]` interval.\n *\n * @param value Value to clamp.\n * @param min Lower bound (inclusive).\n * @param max Upper bound (inclusive).\n */\nexport function clampValue( value: number, min: number, max: number ): number {\n\tif ( value < min ) {\n\t\treturn min;\n\t}\n\tif ( value > max ) {\n\t\treturn max;\n\t}\n\treturn value;\n}\n\n/**\n * Round `value` to the nearest multiple of `step`.\n *\n * @param value Value to quantize.\n * @param step Step granularity (must be > 0).\n */\nexport function quantize( value: number, step: number ): number {\n\treturn Math.round( value / step ) * step;\n}\n\nexport interface UseRulerDragOptions {\n\tvalue: number;\n\tonChange: ( next: number ) => void;\n\tmin: number;\n\tmax: number;\n\tstep: number;\n\tpixelsPerStep: number;\n\tdisabled: boolean;\n\t/** Called once on pointerdown so the caller can focus the input. */\n\tonPointerDownStart?: () => void;\n}\n\nexport interface RulerDragHandlers {\n\tonPointerDown: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerMove: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerUp: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerCancel: ( event: React.PointerEvent< HTMLElement > ) => void;\n}\n\n/**\n * Drag-the-ruler gesture for a horizontal slider. Translates pointer\n * movement into value changes quantized to `step`; the caller renders\n * the visuals and holds the value.\n *\n * The hook owns no state of its own — every value change is reported\n * through the supplied `onChange`. The \"current value\" is read from a\n * ref so closure staleness during a drag is impossible. Drag continues\n * past the wrapper's bounds (standard slider behaviour); a window-level\n * `pointerup` listener guarantees the drag ends and pointer capture\n * releases even if the underlying captured event never fires on the\n * wrapper.\n *\n * @param options Ruler-drag configuration. See `UseRulerDragOptions`.\n */\nexport function useRulerDrag(\n\toptions: UseRulerDragOptions\n): RulerDragHandlers {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart,\n\t} = options;\n\n\t// Mutable mirror of the latest committed value plus per-drag state.\n\t// Pointermove handlers fire far faster than React commits, so we\n\t// cannot read `value` from closure. The `value` write happens in an\n\t// effect (not at render time) to satisfy `react-hooks/refs`; the\n\t// effect flushes after commit, so by the time any pointer handler\n\t// runs, the ref reflects the latest committed `value`.\n\tconst latestRef = useRef< {\n\t\tvalue: number;\n\t\tstartX: number;\n\t\tstartValue: number;\n\t\tactiveStep: number;\n\t\tdragging: boolean;\n\t\tcaptureElement: HTMLElement | null;\n\t\tcapturePointerId: number;\n\t\twindowPointerUp: ( () => void ) | null;\n\t} >( {\n\t\tvalue,\n\t\tstartX: 0,\n\t\tstartValue: 0,\n\t\tactiveStep: step,\n\t\tdragging: false,\n\t\tcaptureElement: null,\n\t\tcapturePointerId: 0,\n\t\twindowPointerUp: null,\n\t} );\n\tuseEffect( () => {\n\t\tlatestRef.current.value = value;\n\t}, [ value ] );\n\n\tconst endDrag = useCallback( () => {\n\t\tconst state = latestRef.current;\n\t\tif ( ! state.dragging ) {\n\t\t\treturn;\n\t\t}\n\t\tstate.dragging = false;\n\t\tif (\n\t\t\tstate.captureElement &&\n\t\t\tstate.captureElement.hasPointerCapture( state.capturePointerId )\n\t\t) {\n\t\t\tstate.captureElement.releasePointerCapture(\n\t\t\t\tstate.capturePointerId\n\t\t\t);\n\t\t}\n\t\tstate.captureElement = null;\n\t\tif ( state.windowPointerUp ) {\n\t\t\twindow.removeEventListener( 'pointerup', state.windowPointerUp );\n\t\t\twindow.removeEventListener(\n\t\t\t\t'pointercancel',\n\t\t\t\tstate.windowPointerUp\n\t\t\t);\n\t\t\tstate.windowPointerUp = null;\n\t\t}\n\t}, [] );\n\n\t// Cleanup any in-flight drag on unmount so we never leak window\n\t// listeners or stale pointer capture.\n\tuseEffect( () => endDrag, [ endDrag ] );\n\n\tconst onPointerDown = useCallback(\n\t\t( event: React.PointerEvent< HTMLElement > ) => {\n\t\t\tif ( disabled || event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst state = latestRef.current;\n\t\t\tevent.currentTarget.setPointerCapture( event.pointerId );\n\t\t\tstate.captureElement = event.currentTarget;\n\t\t\tstate.capturePointerId = event.pointerId;\n\t\t\tstate.startX = event.clientX;\n\t\t\tstate.startValue = state.value;\n\t\t\tstate.activeStep = event.shiftKey ? step / 2 : step;\n\t\t\tstate.dragging = true;\n\t\t\tonPointerDownStart?.();\n\n\t\t\t// Window-level backstop. With `setPointerCapture`, the\n\t\t\t// element should always receive `pointerup` even when the\n\t\t\t// cursor is released outside its bounds — but in practice\n\t\t\t// some browsers / window-blur sequences drop the event. The\n\t\t\t// window listener guarantees the drag ends and capture\n\t\t\t// releases.\n\t\t\tconst onWindowUp = () => endDrag();\n\t\t\tstate.windowPointerUp = onWindowUp;\n\t\t\twindow.addEventListener( 'pointerup', onWindowUp );\n\t\t\twindow.addEventListener( 'pointercancel', onWindowUp );\n\t\t},\n\t\t[ disabled, onPointerDownStart, endDrag, step ]\n\t);\n\n\tconst onPointerMove = useCallback(\n\t\t( event: React.PointerEvent< HTMLElement > ) => {\n\t\t\tconst state = latestRef.current;\n\t\t\tif ( ! state.dragging ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Shift toggles fine mode mid-drag. The drag math computes\n\t\t\t// from `startX` / `startValue`, so naively swapping `step`\n\t\t\t// would yank the value backward. Rebase to the current\n\t\t\t// pointer + value so the granularity changes without a\n\t\t\t// jump.\n\t\t\tconst requestedStep = event.shiftKey ? step / 2 : step;\n\t\t\tif ( requestedStep !== state.activeStep ) {\n\t\t\t\tstate.startX = event.clientX;\n\t\t\t\tstate.startValue = state.value;\n\t\t\t\tstate.activeStep = requestedStep;\n\t\t\t}\n\t\t\tconst deltaPx = event.clientX - state.startX;\n\t\t\tconst deltaValue = pxToValueDelta(\n\t\t\t\tdeltaPx,\n\t\t\t\tpixelsPerStep,\n\t\t\t\tstate.activeStep\n\t\t\t);\n\t\t\tconst raw = state.startValue + deltaValue;\n\t\t\tconst stepped = quantize( raw, state.activeStep );\n\t\t\tconst next = clampValue( stepped, min, max );\n\t\t\tif ( next !== state.value ) {\n\t\t\t\t// Update the ref synchronously so consecutive pointermove\n\t\t\t\t// events that fire before React commits still see the\n\t\t\t\t// last *emitted* value as `previous` for the next math.\n\t\t\t\tstate.value = next;\n\t\t\t\tonChange( next );\n\t\t\t}\n\t\t},\n\t\t[ onChange, min, max, step, pixelsPerStep ]\n\t);\n\n\treturn {\n\t\tonPointerDown,\n\t\tonPointerMove,\n\t\tonPointerUp: endDrag,\n\t\tonPointerCancel: endDrag,\n\t};\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,aAAa,WAAW,cAAc;AAaxC,SAAS,eACf,SACA,eACA,MACS;AACT,SAAS,CAAC,UAAU,gBAAkB;AACvC;AASO,SAAS,WAAY,OAAe,KAAa,KAAsB;AAC7E,MAAK,QAAQ,KAAM;AAClB,WAAO;AAAA,EACR;AACA,MAAK,QAAQ,KAAM;AAClB,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAQO,SAAS,SAAU,OAAe,MAAuB;AAC/D,SAAO,KAAK,MAAO,QAAQ,IAAK,IAAI;AACrC;AAoCO,SAAS,aACf,SACoB;AACpB,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;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,UAAW;AAAA,IACtD;AAAA,IACA,CAAE,UAAU,oBAAoB,SAAS,IAAK;AAAA,EAC/C;AAEA,QAAM,gBAAgB;AAAA,IACrB,CAAE,UAA8C;AAC/C,YAAM,QAAQ,UAAU;AACxB,UAAK,CAAE,MAAM,UAAW;AACvB;AAAA,MACD;AAMA,YAAM,gBAAgB,MAAM,WAAW,OAAO,IAAI;AAClD,UAAK,kBAAkB,MAAM,YAAa;AACzC,cAAM,SAAS,MAAM;AACrB,cAAM,aAAa,MAAM;AACzB,cAAM,aAAa;AAAA,MACpB;AACA,YAAM,UAAU,MAAM,UAAU,MAAM;AACtC,YAAM,aAAa;AAAA,QAClB;AAAA,QACA;AAAA,QACA,MAAM;AAAA,MACP;AACA,YAAM,MAAM,MAAM,aAAa;AAC/B,YAAM,UAAU,SAAU,KAAK,MAAM,UAAW;AAChD,YAAM,OAAO,WAAY,SAAS,KAAK,GAAI;AAC3C,UAAK,SAAS,MAAM,OAAQ;AAI3B,cAAM,QAAQ;AACd,iBAAU,IAAK;AAAA,MAChB;AAAA,IACD;AAAA,IACA,CAAE,UAAU,KAAK,KAAK,MAAM,aAAc;AAAA,EAC3C;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,iBAAiB;AAAA,EAClB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -53,6 +53,17 @@ function getImageFit(containerSize, imageSize, rotation) {
|
|
|
53
53
|
visualSize
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
function getViewScale(cropRect, canvasSize, visualSize, targetFill, maxScale) {
|
|
57
|
+
const cropScreenW = cropRect.width * visualSize.width;
|
|
58
|
+
const cropScreenH = cropRect.height * visualSize.height;
|
|
59
|
+
if (!isValidSize(canvasSize) || !isValidSize(visualSize) || !(cropScreenW > 0) || !(cropScreenH > 0) || !Number.isFinite(targetFill) || !Number.isFinite(maxScale) || !(targetFill > 0) || !(maxScale >= 1)) {
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
const kW = targetFill * canvasSize.width / cropScreenW;
|
|
63
|
+
const kH = targetFill * canvasSize.height / cropScreenH;
|
|
64
|
+
const k = Math.min(kW, kH);
|
|
65
|
+
return Math.min(maxScale, Math.max(1, k));
|
|
66
|
+
}
|
|
56
67
|
function createCamera(state, containerSize, imageSize) {
|
|
57
68
|
const m = mat2d.create();
|
|
58
69
|
if (!isValidSize(containerSize) || !isValidSize(imageSize)) {
|
|
@@ -179,6 +190,7 @@ export {
|
|
|
179
190
|
createExportCamera,
|
|
180
191
|
getImageFit,
|
|
181
192
|
getRotatedBBox,
|
|
193
|
+
getViewScale,
|
|
182
194
|
getVisibleBounds,
|
|
183
195
|
screenToWorld,
|
|
184
196
|
worldToScreen
|