@wordpress/media-editor 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/build/components/media-editor/index.cjs +157 -107
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +18 -8
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +9 -7
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +9 -7
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +9 -7
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +32 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-preview/index.cjs +143 -36
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +2 -2
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +9 -7
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +142 -95
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +9 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +32 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-preview/index.mjs +123 -40
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +2 -2
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +18 -30
- package/build-style/style.css +18 -30
- package/build-types/components/media-editor/index.d.ts +8 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +7 -2
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +26 -22
- package/src/components/media-editor/index.tsx +209 -114
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +55 -63
- package/src/components/media-editor-modal/index.tsx +3 -0
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-preview/index.tsx +195 -36
- package/src/components/media-preview/style.scss +11 -32
- package/src/state/README.md +3 -1
- package/src/state/use-media-editor-state.ts +7 -2
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
|
@@ -3,35 +3,125 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
__esModule: { value: true },
|
|
4
4
|
[Symbol.toStringTag]: { value: "Module" }
|
|
5
5
|
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
let clsx = require("clsx");
|
|
30
|
+
let _wordpress_a11y = require("@wordpress/a11y");
|
|
6
31
|
let _wordpress_components = require("@wordpress/components");
|
|
32
|
+
let _wordpress_compose = require("@wordpress/compose");
|
|
7
33
|
let _wordpress_element = require("@wordpress/element");
|
|
8
34
|
let _wordpress_i18n = require("@wordpress/i18n");
|
|
35
|
+
let _wordpress_icons = require("@wordpress/icons");
|
|
36
|
+
let _wordpress_ui = require("@wordpress/ui");
|
|
9
37
|
let ___media_editor_provider_index_tsx = require("../media-editor-provider/index.cjs");
|
|
10
38
|
let ______utils_index_ts = require("../../utils/index.cjs");
|
|
11
39
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
clsx = __toESM(clsx);
|
|
12
41
|
// packages/media-editor/src/components/media-preview/index.tsx
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Returns the value of one of the attachment fields for the media, or an
|
|
44
|
+
* empty string if the field isn't available.
|
|
45
|
+
*
|
|
46
|
+
* @param fields The attachment fields.
|
|
47
|
+
* @param fieldId The id of the field to read.
|
|
48
|
+
* @param media The media record.
|
|
49
|
+
*/
|
|
50
|
+
function getFieldValue(fields, fieldId, media) {
|
|
51
|
+
const value = fields.find(({ id }) => id === fieldId)?.getValue?.({ item: media });
|
|
52
|
+
return typeof value === "string" ? value : "";
|
|
53
|
+
}
|
|
54
|
+
const COPY_FEEDBACK_TIMEOUT = 2e3;
|
|
55
|
+
const COPY_RESULT_ICONS = {
|
|
56
|
+
idle: _wordpress_icons.copy,
|
|
57
|
+
copied: _wordpress_icons.check,
|
|
58
|
+
error: _wordpress_icons.error
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Copies the text and shows the result on the copy button, following the
|
|
62
|
+
* Copy to Clipboard design system pattern.
|
|
63
|
+
*
|
|
64
|
+
* @param text The text to copy.
|
|
65
|
+
*/
|
|
66
|
+
function useCopyWithFeedback(text) {
|
|
67
|
+
const [feedback, setFeedback] = (0, _wordpress_element.useState)({
|
|
68
|
+
result: "idle",
|
|
69
|
+
id: 0
|
|
32
70
|
});
|
|
71
|
+
(0, _wordpress_element.useEffect)(() => {
|
|
72
|
+
if (feedback.result === "idle") return;
|
|
73
|
+
const timeoutId = setTimeout(() => setFeedback({
|
|
74
|
+
result: "idle",
|
|
75
|
+
id: 0
|
|
76
|
+
}), COPY_FEEDBACK_TIMEOUT);
|
|
77
|
+
return () => clearTimeout(timeoutId);
|
|
78
|
+
}, [feedback]);
|
|
79
|
+
function report(result, message) {
|
|
80
|
+
setFeedback((current) => ({
|
|
81
|
+
result,
|
|
82
|
+
id: current.id + 1
|
|
83
|
+
}));
|
|
84
|
+
(0, _wordpress_a11y.speak)(message);
|
|
85
|
+
}
|
|
86
|
+
const ref = (0, _wordpress_compose.useCopyToClipboard)(text, () => report("copied", (0, _wordpress_i18n.__)("Copied URL to clipboard.")), () => report("error", (0, _wordpress_i18n.__)("Couldn't copy URL to clipboard.")));
|
|
87
|
+
return {
|
|
88
|
+
result: feedback.result,
|
|
89
|
+
ref
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function MediaPreviewFileActions({ mediaUrl }) {
|
|
93
|
+
const { result, ref } = useCopyWithFeedback(mediaUrl);
|
|
94
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
|
|
95
|
+
__next40pxDefaultSize: true,
|
|
96
|
+
variant: "primary",
|
|
97
|
+
href: mediaUrl,
|
|
98
|
+
target: "_blank",
|
|
99
|
+
download: true,
|
|
100
|
+
icon: _wordpress_icons.download,
|
|
101
|
+
children: (0, _wordpress_i18n.__)("Download")
|
|
102
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
|
|
103
|
+
__next40pxDefaultSize: true,
|
|
104
|
+
variant: "secondary",
|
|
105
|
+
ref,
|
|
106
|
+
icon: COPY_RESULT_ICONS[result],
|
|
107
|
+
children: (0, _wordpress_i18n.__)("Copy URL")
|
|
108
|
+
})] });
|
|
33
109
|
}
|
|
34
|
-
function
|
|
110
|
+
function MediaPreviewFileInfo({ mediaUrl, fileName, fileDetails }) {
|
|
111
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.EmptyState.Root, { children: [
|
|
112
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Icon, { icon: _wordpress_icons.folder }),
|
|
113
|
+
!!fileName && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Title, {
|
|
114
|
+
className: "media-editor-preview__file-name",
|
|
115
|
+
children: fileName
|
|
116
|
+
}),
|
|
117
|
+
!!fileDetails && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Description, { children: fileDetails }),
|
|
118
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Actions, {
|
|
119
|
+
className: "media-editor-preview__actions",
|
|
120
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaPreviewFileActions, { mediaUrl })
|
|
121
|
+
})
|
|
122
|
+
] });
|
|
123
|
+
}
|
|
124
|
+
function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, fileName, fileDetails, onLoad, onError, loadingState }) {
|
|
35
125
|
switch (previewType) {
|
|
36
126
|
case "image": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
37
127
|
className: loadingState === "loaded" ? "loaded" : "",
|
|
@@ -59,14 +149,14 @@ function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, mim
|
|
|
59
149
|
"aria-label": (0, _wordpress_i18n.__)("Embed of the selected PDF file."),
|
|
60
150
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaPreviewFileInfo, {
|
|
61
151
|
mediaUrl,
|
|
62
|
-
|
|
63
|
-
|
|
152
|
+
fileName,
|
|
153
|
+
fileDetails
|
|
64
154
|
})
|
|
65
155
|
});
|
|
66
156
|
default: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaPreviewFileInfo, {
|
|
67
157
|
mediaUrl,
|
|
68
|
-
|
|
69
|
-
|
|
158
|
+
fileName,
|
|
159
|
+
fileDetails
|
|
70
160
|
});
|
|
71
161
|
}
|
|
72
162
|
}
|
|
@@ -79,25 +169,41 @@ function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, mim
|
|
|
79
169
|
*/
|
|
80
170
|
function MediaPreview(props) {
|
|
81
171
|
const [loadingState, setLoadingState] = (0, _wordpress_element.useState)("loading");
|
|
82
|
-
const { media } = (0, ___media_editor_provider_index_tsx.useMediaEditorContext)();
|
|
172
|
+
const { media, fields } = (0, ___media_editor_provider_index_tsx.useMediaEditorContext)();
|
|
83
173
|
const { source_url: mediaUrl, mime_type: mimeType, alt_text: altText, title } = media || {};
|
|
84
174
|
const mediaType = (0, ______utils_index_ts.getMediaTypeFromMimeType)(mimeType);
|
|
85
175
|
const previewType = mimeType === "application/pdf" && window.navigator.pdfViewerEnabled ? "pdf" : mediaType.type;
|
|
86
176
|
if (!mediaUrl) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
87
|
-
className: "media-editor-preview media-editor-preview--empty",
|
|
88
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
89
|
-
});
|
|
90
|
-
if (loadingState === "error") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
91
|
-
className: "media-editor-preview media-editor-preview--error",
|
|
92
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: (0, _wordpress_i18n.__)("Failed to load media file.") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
93
|
-
className: "media-editor-preview__url",
|
|
94
|
-
children: mediaUrl
|
|
95
|
-
})]
|
|
177
|
+
className: "media-editor-preview media-editor-preview--empty is-placeholder",
|
|
178
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.EmptyState.Root, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Icon, { icon: _wordpress_icons.folder }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Title, { children: (0, _wordpress_i18n.__)("No media file available.") })] })
|
|
96
179
|
});
|
|
97
180
|
const displayTitle = typeof title === "string" ? title : title?.rendered || title?.raw;
|
|
181
|
+
const fileName = media && getFieldValue(fields, "filename", media) || displayTitle;
|
|
182
|
+
const fileSize = media ? getFieldValue(fields, "filesize", media) : "";
|
|
183
|
+
const fileDetails = mimeType && fileSize ? (0, _wordpress_i18n.sprintf)(
|
|
184
|
+
/** translators: 1: File type, e.g. "application/zip". 2: File size, e.g. "2.4 MB". */
|
|
185
|
+
(0, _wordpress_i18n._x)("%1$s · %2$s", "file type and size"),
|
|
186
|
+
mimeType,
|
|
187
|
+
fileSize
|
|
188
|
+
) : mimeType || fileSize;
|
|
189
|
+
if (loadingState === "error") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
190
|
+
className: "media-editor-preview media-editor-preview--error is-placeholder",
|
|
191
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.EmptyState.Root, { children: [
|
|
192
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Icon, { icon: _wordpress_icons.folder }),
|
|
193
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Title, { children: (0, _wordpress_i18n.__)("Failed to load media file.") }),
|
|
194
|
+
!!fileName && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Description, {
|
|
195
|
+
className: "media-editor-preview__file-name",
|
|
196
|
+
children: fileName
|
|
197
|
+
}),
|
|
198
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Actions, {
|
|
199
|
+
className: "media-editor-preview__actions",
|
|
200
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaPreviewFileActions, { mediaUrl })
|
|
201
|
+
})
|
|
202
|
+
] })
|
|
203
|
+
});
|
|
98
204
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
99
205
|
...props,
|
|
100
|
-
className:
|
|
206
|
+
className: (0, clsx.default)("media-editor-preview", `media-editor-preview--${previewType}`, { "is-placeholder": previewType === "application" }),
|
|
101
207
|
children: [previewType === "image" && loadingState === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
102
208
|
className: "media-editor-preview__spinner",
|
|
103
209
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Spinner, {})
|
|
@@ -106,7 +212,8 @@ function MediaPreview(props) {
|
|
|
106
212
|
mediaUrl,
|
|
107
213
|
altText,
|
|
108
214
|
displayTitle,
|
|
109
|
-
|
|
215
|
+
fileName,
|
|
216
|
+
fileDetails,
|
|
110
217
|
onLoad: () => setLoadingState("loaded"),
|
|
111
218
|
onError: () => setLoadingState("error"),
|
|
112
219
|
loadingState
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["__","useState","useMediaEditorContext","getMediaTypeFromMimeType","WCSpinner"],"sources":["../../../src/components/media-preview/index.tsx"],"sourcesContent":["import { Spinner as WCSpinner } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tpreviewType: string;\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\ninterface MediaPreviewFileInfoProps {\n\tmediaUrl: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n}\n\nfunction MediaPreviewFileInfo( {\n\tmediaUrl,\n\tdisplayTitle,\n\tmimeType,\n}: MediaPreviewFileInfoProps ) {\n\treturn (\n\t\t<div className=\"media-editor-preview__file-info\">\n\t\t\t<p className=\"media-editor-preview__file-name\">{ displayTitle }</p>\n\t\t\t<p className=\"media-editor-preview__mime-type\">{ mimeType }</p>\n\t\t\t{ /* eslint-disable-next-line react/jsx-no-target-blank */ }\n\t\t\t<a\n\t\t\t\thref={ mediaUrl }\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\tclassName=\"media-editor-preview__download-link\"\n\t\t\t>\n\t\t\t\t{ __( 'View file' ) }\n\t\t\t</a>\n\t\t</div>\n\t);\n}\n\nfunction MediaPreviewContent( {\n\tpreviewType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tmimeType,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( previewType ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tcase 'pdf':\n\t\t\t// The browser renders the children instead of the PDF when it\n\t\t\t// can't display it, e.g. when the request fails.\n\t\t\treturn (\n\t\t\t\t<object\n\t\t\t\t\tclassName=\"media-editor-preview__pdf\"\n\t\t\t\t\t// Ask the viewer to fit the whole page rather than the\n\t\t\t\t\t// width. Chrome reads `view`, Firefox reads `zoom`, and\n\t\t\t\t\t// Safari ignores both.\n\t\t\t\t\tdata={ `${ mediaUrl }#view=Fit&zoom=page-fit` }\n\t\t\t\t\ttype=\"application/pdf\"\n\t\t\t\t\taria-label={ __( 'Embed of the selected PDF file.' ) }\n\t\t\t\t>\n\t\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\t\t\tmimeType={ mimeType }\n\t\t\t\t\t/>\n\t\t\t\t</object>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\t\tmimeType={ mimeType }\n\t\t\t\t/>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\t// Without a built-in PDF viewer (e.g. on most mobile browsers), show\n\t// the file info instead of an embed that can't render.\n\tconst previewType =\n\t\tmimeType === 'application/pdf' && window.navigator.pdfViewerEnabled\n\t\t\t? 'pdf'\n\t\t\t: mediaType.type;\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty\">\n\t\t\t\t<p>{ __( 'No media file available.' ) }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error\">\n\t\t\t\t<p>{ __( 'Failed to load media file.' ) }</p>\n\t\t\t\t<p className=\"media-editor-preview__url\">{ mediaUrl }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ `media-editor-preview media-editor-preview--${ previewType }` }\n\t\t>\n\t\t\t{ previewType === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tpreviewType={ previewType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tmimeType={ mimeType }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' 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R,CAAA,GAEN,iBAAA,GAAA,kBAAA,IAAA,CAAC,qBAAD;GACe;GACH;GACD;GACK;GACJ;GACX,cAAe,gBAAiB,QAAS;GACzC,eAAgB,gBAAiB,OAAQ;GAC1B;EACf,CAAA,CACG;;AAEP"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["copy","check","errorIcon","useState","useEffect","speak","useCopyToClipboard","__","Button","download","EmptyState","folder","useMediaEditorContext","getMediaTypeFromMimeType","sprintf","_x","clsx","WCSpinner"],"sources":["../../../src/components/media-preview/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { speak } from '@wordpress/a11y';\nimport { Button, Spinner as WCSpinner } from '@wordpress/components';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tcopy,\n\tdownload,\n\terror as errorIcon,\n\tfolder,\n} from '@wordpress/icons';\nimport { EmptyState } from '@wordpress/ui';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tpreviewType: string;\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tfileName?: string;\n\tfileDetails?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\n/**\n * Returns the value of one of the attachment fields for the media, or an\n * empty string if the field isn't available.\n *\n * @param fields The attachment fields.\n * @param fieldId The id of the field to read.\n * @param media The media record.\n */\nfunction getFieldValue(\n\tfields: Array< {\n\t\tid: string;\n\t\tgetValue?: ( args: { item: Media } ) => unknown;\n\t} >,\n\tfieldId: string,\n\tmedia: Media\n): string {\n\tconst field = fields.find( ( { id } ) => id === fieldId );\n\tconst value = field?.getValue?.( { item: media } );\n\treturn typeof value === 'string' ? value : '';\n}\n\nconst COPY_FEEDBACK_TIMEOUT = 2000;\n\ntype CopyResult = 'idle' | 'copied' | 'error';\n\nconst COPY_RESULT_ICONS = {\n\tidle: copy,\n\tcopied: check,\n\terror: errorIcon,\n};\n\n/**\n * Copies the text and shows the result on the copy button, following the\n * Copy to Clipboard design system pattern.\n *\n * @param text The text to copy.\n */\nfunction useCopyWithFeedback( text: string ) {\n\t// Bump the id on every result, so a repeat of the same result restarts\n\t// the time the icon stays visible.\n\tconst [ feedback, setFeedback ] = useState< {\n\t\tresult: CopyResult;\n\t\tid: number;\n\t} >( { result: 'idle', id: 0 } );\n\n\tuseEffect( () => {\n\t\tif ( feedback.result === 'idle' ) {\n\t\t\treturn;\n\t\t}\n\t\tconst timeoutId = setTimeout(\n\t\t\t() => setFeedback( { result: 'idle', id: 0 } ),\n\t\t\tCOPY_FEEDBACK_TIMEOUT\n\t\t);\n\t\treturn () => clearTimeout( timeoutId );\n\t}, [ feedback ] );\n\n\tfunction report( result: Exclude< CopyResult, 'idle' >, message: string ) {\n\t\tsetFeedback( ( current ) => ( { result, id: current.id + 1 } ) );\n\t\tspeak( message );\n\t}\n\n\tconst ref = useCopyToClipboard(\n\t\ttext,\n\t\t() => report( 'copied', __( 'Copied URL to clipboard.' ) ),\n\t\t() => report( 'error', __( \"Couldn't copy URL to clipboard.\" ) )\n\t);\n\n\treturn { result: feedback.result, ref };\n}\n\nfunction MediaPreviewFileActions( { mediaUrl }: { mediaUrl: string } ) {\n\tconst { result, ref } = useCopyWithFeedback( mediaUrl );\n\n\treturn (\n\t\t<>\n\t\t\t{ /*\n\t\t\t * Browsers ignore `download` for cross-origin URLs, e.g. media\n\t\t\t * offloaded to a CDN, and show the file instead. Open it in a new\n\t\t\t * tab so it doesn't replace the editor.\n\t\t\t */ }\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvariant=\"primary\"\n\t\t\t\thref={ mediaUrl }\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\tdownload\n\t\t\t\ticon={ download }\n\t\t\t>\n\t\t\t\t{ __( 'Download' ) }\n\t\t\t</Button>\n\t\t\t{ /* The label stays the same, and the icon shows the result. */ }\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\tref={ ref }\n\t\t\t\ticon={ COPY_RESULT_ICONS[ result ] }\n\t\t\t>\n\t\t\t\t{ __( 'Copy URL' ) }\n\t\t\t</Button>\n\t\t</>\n\t);\n}\n\ninterface MediaPreviewFileInfoProps {\n\tmediaUrl: string;\n\tfileName?: string;\n\tfileDetails?: string;\n}\n\nfunction MediaPreviewFileInfo( {\n\tmediaUrl,\n\tfileName,\n\tfileDetails,\n}: MediaPreviewFileInfoProps ) {\n\treturn (\n\t\t<EmptyState.Root>\n\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t{ !! fileName && (\n\t\t\t\t<EmptyState.Title className=\"media-editor-preview__file-name\">\n\t\t\t\t\t{ fileName }\n\t\t\t\t</EmptyState.Title>\n\t\t\t) }\n\t\t\t{ !! fileDetails && (\n\t\t\t\t<EmptyState.Description>{ fileDetails }</EmptyState.Description>\n\t\t\t) }\n\t\t\t<EmptyState.Actions className=\"media-editor-preview__actions\">\n\t\t\t\t<MediaPreviewFileActions mediaUrl={ mediaUrl } />\n\t\t\t</EmptyState.Actions>\n\t\t</EmptyState.Root>\n\t);\n}\n\nfunction MediaPreviewContent( {\n\tpreviewType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tfileName,\n\tfileDetails,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( previewType ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tcase 'pdf':\n\t\t\t// The browser renders the children instead of the PDF when it\n\t\t\t// can't display it, e.g. when the request fails.\n\t\t\treturn (\n\t\t\t\t<object\n\t\t\t\t\tclassName=\"media-editor-preview__pdf\"\n\t\t\t\t\t// Ask the viewer to fit the whole page rather than the\n\t\t\t\t\t// width. Chrome reads `view`, Firefox reads `zoom`, and\n\t\t\t\t\t// Safari ignores both.\n\t\t\t\t\tdata={ `${ mediaUrl }#view=Fit&zoom=page-fit` }\n\t\t\t\t\ttype=\"application/pdf\"\n\t\t\t\t\taria-label={ __( 'Embed of the selected PDF file.' ) }\n\t\t\t\t>\n\t\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\t\tfileName={ fileName }\n\t\t\t\t\t\tfileDetails={ fileDetails }\n\t\t\t\t\t/>\n\t\t\t\t</object>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\tfileName={ fileName }\n\t\t\t\t\tfileDetails={ fileDetails }\n\t\t\t\t/>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media, fields } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\t// Without a built-in PDF viewer (e.g. on most mobile browsers), show\n\t// the file info instead of an embed that can't render.\n\tconst previewType =\n\t\tmimeType === 'application/pdf' && window.navigator.pdfViewerEnabled\n\t\t\t? 'pdf'\n\t\t\t: mediaType.type;\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty is-placeholder\">\n\t\t\t\t<EmptyState.Root>\n\t\t\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t\t\t<EmptyState.Title>\n\t\t\t\t\t\t{ __( 'No media file available.' ) }\n\t\t\t\t\t</EmptyState.Title>\n\t\t\t\t</EmptyState.Root>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\t// Read through the attachment fields, so the values match the Details\n\t// panel. Without a filename field, fall back to the title.\n\tconst fileName =\n\t\t( media && getFieldValue( fields, 'filename', media ) ) || displayTitle;\n\tconst fileSize = media ? getFieldValue( fields, 'filesize', media ) : '';\n\tconst fileDetails =\n\t\tmimeType && fileSize\n\t\t\t? sprintf(\n\t\t\t\t\t/* translators: 1: File type, e.g. \"application/zip\". 2: File size, e.g. \"2.4 MB\". */\n\t\t\t\t\t_x( '%1$s · %2$s', 'file type and size' ),\n\t\t\t\t\tmimeType,\n\t\t\t\t\tfileSize\n\t\t\t\t)\n\t\t\t: mimeType || fileSize;\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error is-placeholder\">\n\t\t\t\t<EmptyState.Root>\n\t\t\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t\t\t<EmptyState.Title>\n\t\t\t\t\t\t{ __( 'Failed to load media file.' ) }\n\t\t\t\t\t</EmptyState.Title>\n\t\t\t\t\t{ !! fileName && (\n\t\t\t\t\t\t<EmptyState.Description className=\"media-editor-preview__file-name\">\n\t\t\t\t\t\t\t{ fileName }\n\t\t\t\t\t\t</EmptyState.Description>\n\t\t\t\t\t) }\n\t\t\t\t\t<EmptyState.Actions className=\"media-editor-preview__actions\">\n\t\t\t\t\t\t<MediaPreviewFileActions mediaUrl={ mediaUrl } />\n\t\t\t\t\t</EmptyState.Actions>\n\t\t\t\t</EmptyState.Root>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ clsx(\n\t\t\t\t'media-editor-preview',\n\t\t\t\t`media-editor-preview--${ previewType }`,\n\t\t\t\t{\n\t\t\t\t\t// Media with no preview of its own shows the file info.\n\t\t\t\t\t'is-placeholder': previewType === 'application',\n\t\t\t\t}\n\t\t\t) }\n\t\t>\n\t\t\t{ previewType === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tpreviewType={ previewType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tfileName={ fileName }\n\t\t\t\tfileDetails={ fileDetails }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' ) }\n\t\t\t\tloadingState={ loadingState }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAS,cACR,QAIA,SACA,OACS;CAET,MAAM,QADQ,OAAO,MAAQ,EAAE,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AAA,GAEN,iBAAA,GAAA,kBAAA,IAAA,CAAC,qBAAD;GACe;GACH;GACD;GACK;GACJ;GACG;GACd,cAAe,gBAAiB,QAAS;GACzC,eAAgB,gBAAiB,OAAQ;GAC1B;EACf,CAAA,CACG;;AAEP"}
|
|
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
11
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
12
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
15
|
-
key
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
return to;
|
|
22
24
|
};
|
|
@@ -25,10 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
27
|
enumerable: true
|
|
26
28
|
}) : target, mod));
|
|
27
29
|
let clsx = require("clsx");
|
|
28
|
-
clsx = __toESM(clsx);
|
|
29
30
|
let _wordpress_element = require("@wordpress/element");
|
|
30
31
|
let __use_ruler_drag_ts = require("./use-ruler-drag.cjs");
|
|
31
32
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
clsx = __toESM(clsx);
|
|
32
34
|
// packages/media-editor/src/components/rotation-ruler/index.tsx
|
|
33
35
|
const STRIP_HEIGHT = 32;
|
|
34
36
|
const LABEL_BASELINE_Y = 11;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMemo","useRef","useId","useRulerDrag","clampValue"],"sources":["../../../src/components/rotation-ruler/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\nimport { useId, useMemo, useRef } from '@wordpress/element';\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-testid=\"rotation-ruler\"\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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eAAe,KAAK,GAAI,CAClD;IAED,WAAY;GACZ,CAAA;GACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAAwB,eAAY;IAClD,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;KACC,WAAU;KACV,OAAQ;KACR,QAAU,MAAM,OAAQ;KACxB,QAAS;KACT,SAAU,GAAI,MAAM,UAAW,MAC5B,MAAM,OAAQ,UAChB,GAAI;KACL,qBAAoB;KARrB,UAAA,CAUG,MAAM,KAAO,SACd,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;MAEC,IAAK,KAAK,QAAQ;MAClB,IAAK,KAAK,QAAQ;MAClB,IAAK,eAAe,KAAK;MACzB,IAAK;MACL,WAAY,8CAA+C,KAAK;KAChE,GANM,KAAK,KAMX,CACA,GACA,WAAW,KAAO,SACnB,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;MAEC,GAAI,KAAK,QAAQ;MACjB,GAAI;MACJ,YAAW;MACX,WAAU;MALX,UAAA,CAOG,KAAK,OACL,IACG;KARC,GAAA,KAAK,KAQN,CACL,CACE;;GACD,CAAA;GACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAA+B,eAAY;IACzD,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;KAAM,WAAU;KAAhB,UAAA;MACG,cACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;OAAM,WAAU;OAAoC,UAAA;MAE9C,CAAA;MAEL;MACF,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;OAAM,WAAU;OACb,UAAA;MACG,CAAA;KACD;;GACF,CAAA;GACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAA0B,eAAY;GAAQ,CAAA;EACzD;;AAEP"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMemo","useRef","useId","useRulerDrag","clampValue","clsx"],"sources":["../../../src/components/rotation-ruler/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\nimport { useId, useMemo, useRef } from '@wordpress/element';\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-testid=\"rotation-ruler\"\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAM,eAAe;AACrB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,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AAA,CAAC,OAAD;IAAK,WAAU;IAAwB,eAAY;IAClD,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;KACC,WAAU;KACV,OAAQ;KACR,QAAU,MAAM,OAAQ;KACxB,QAAS;KACT,SAAU,GAAI,MAAM,UAAW,MAC5B,MAAM,OAAQ,UAChB,GAAI;KACL,qBAAoB;KARrB,UAAA,CAUG,MAAM,KAAO,SACd,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;MAEC,IAAK,KAAK,QAAQ;MAClB,IAAK,KAAK,QAAQ;MAClB,IAAK,eAAe,KAAK;MACzB,IAAK;MACL,WAAY,8CAA+C,KAAK;KAChE,GANM,KAAK,KAMX,CACA,GACA,WAAW,KAAO,SACnB,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;MAEC,GAAI,KAAK,QAAQ;MACjB,GAAI;MACJ,YAAW;MACX,WAAU;MALX,UAAA,CAOG,KAAK,OACL,IACG;KARC,GAAA,KAAK,KAQN,CACL,CACE;;GACD,CAAA;GACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAA+B,eAAY;IACzD,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;KAAM,WAAU;KAAhB,UAAA;MACG,cACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;OAAM,WAAU;OAAoC,UAAA;MAE9C,CAAA;MAEL;MACF,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;OAAM,WAAU;OACb,UAAA;MACG,CAAA;KACD;;GACF,CAAA;GACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAA0B,eAAY;GAAQ,CAAA;EACzD;;AAEP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-ruler-drag.cjs","names":["useRef","useCallback"],"sources":["../../../src/components/rotation-ruler/use-ruler-drag.ts"],"sourcesContent":["import { 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// Per-drag state, including the last emitted value. Pointermove\n\t// handlers fire far faster than React commits, so they cannot read\n\t// `value` from closure. Pointerdown seeds it from the 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\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\t// Becoming disabled mid-drag ends it, so a rotation cannot keep\n\t// changing after a save has read it.\n\tuseEffect( () => {\n\t\tif ( disabled ) {\n\t\t\tendDrag();\n\t\t}\n\t}, [ disabled, 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.value = value;\n\t\t\tstate.startValue = 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, value ]\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 ( disabled || ! 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[ disabled, 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"],"mappings":";;;;;;;;;;;;;;;;;;AAaA,SAAgB,eACf,SACA,eACA,MACS;CACT,OAAS,CAAC,UAAU,gBAAkB;AACvC;;;;;;;;AASA,SAAgB,WAAY,OAAe,KAAa,KAAsB;CAC7E,IAAK,QAAQ,KACZ,OAAO;CAER,IAAK,QAAQ,KACZ,OAAO;CAER,OAAO;AACR;;;;;;;AAQA,SAAgB,SAAU,OAAe,MAAuB;CAC/D,OAAO,KAAK,MAAO,QAAQ,IAAK,IAAI;AACrC;;;;;;;;;;;;;;;;AAoCA,SAAgB,aACf,SACoB;CACpB,MAAM,EACL,OACA,UACA,KACA,KACA,MACA,eACA,UACA,uBACG;CAKJ,MAAM,aAAA,GAAYA,mBAAAA,OAAAA,CASb;EACJ;EACA,QAAQ;EACR,YAAY;EACZ,YAAY;EACZ,UAAU;EACV,gBAAgB;EAChB,kBAAkB;EAClB,iBAAiB;CAClB,CAAE;CAEF,MAAM,WAAA,GAAUC,mBAAAA,YAAAA,OAAmB;EAClC,MAAM,QAAQ,UAAU;EACxB,IAAK,CAAE,MAAM,UACZ;EAED,MAAM,WAAW;EACjB,IACC,MAAM,kBACN,MAAM,eAAe,kBAAmB,MAAM,gBAAiB,GAE/D,MAAM,eAAe,sBACpB,MAAM,gBACP;EAED,MAAM,iBAAiB;EACvB,IAAK,MAAM,iBAAkB;GAC5B,OAAO,oBAAqB,aAAa,MAAM,eAAgB;GAC/D,OAAO,oBACN,iBACA,MAAM,eACP;GACA,MAAM,kBAAkB;EACzB;CACD,GAAG,CAAC,CAAE;
|
|
1
|
+
{"version":3,"file":"use-ruler-drag.cjs","names":["useRef","useCallback","useEffect"],"sources":["../../../src/components/rotation-ruler/use-ruler-drag.ts"],"sourcesContent":["import { 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// Per-drag state, including the last emitted value. Pointermove\n\t// handlers fire far faster than React commits, so they cannot read\n\t// `value` from closure. Pointerdown seeds it from the 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\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\t// Becoming disabled mid-drag ends it, so a rotation cannot keep\n\t// changing after a save has read it.\n\tuseEffect( () => {\n\t\tif ( disabled ) {\n\t\t\tendDrag();\n\t\t}\n\t}, [ disabled, 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.value = value;\n\t\t\tstate.startValue = 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, value ]\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 ( disabled || ! 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[ disabled, 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"],"mappings":";;;;;;;;;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AAU;GACxB,MAAM,cAAc,kBAAmB,MAAM,SAAU;GACvD,MAAM,iBAAiB,MAAM;GAC7B,MAAM,mBAAmB,MAAM;GAC/B,MAAM,SAAS,MAAM;GACrB,MAAM,QAAQ;GACd,MAAM,aAAa;GACnB,MAAM,aAAa,MAAM,WAAW,OAAO,IAAI;GAC/C,MAAM,WAAW;GACjB,qBAAqB;GAQrB,MAAM,mBAAmB,QAAQ;GACjC,MAAM,kBAAkB;GACxB,OAAO,iBAAkB,aAAa,UAAW;GACjD,OAAO,iBAAkB,iBAAiB,UAAW;EACtD,GACA;GAAE;GAAU;GAAoB;GAAS;GAAM;EAAM,CAyCzC;EACZ,gBAAA,GAvCqBA,mBAAAA,YAAAA,EACnB,UAA8C;GAC/C,MAAM,QAAQ,UAAU;GACxB,IAAK,YAAY,CAAE,MAAM,UACxB;GAOD,MAAM,gBAAgB,MAAM,WAAW,OAAO,IAAI;GAClD,IAAK,kBAAkB,MAAM,YAAa;IACzC,MAAM,SAAS,MAAM;IACrB,MAAM,aAAa,MAAM;IACzB,MAAM,aAAa;GACpB;GAEA,MAAM,aAAa,eADH,MAAM,UAAU,MAAM,QAGrC,eACA,MAAM,UACP;GAGA,MAAM,OAAO,WADG,SADJ,MAAM,aAAa,YACA,MAAM,UACN,GAAG,KAAK,GAAI;GAC3C,IAAK,SAAS,MAAM,OAAQ;IAI3B,MAAM,QAAQ;IACd,SAAU,IAAK;GAChB;EACD,GACA;GAAE;GAAU;GAAU;GAAK;GAAK;GAAM;EAAc,CAKxC;EACZ,aAAa;EACb,iBAAiB;CAClB;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-crop-gesture-handlers.cjs","names":["useMediaEditor","useRef","useCallback"],"sources":["../../src/hooks/use-crop-gesture-handlers.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { useMediaEditor } from '../state';\n\n/**\n * Data attribute applied to crop control wrappers. The modal's keyboard\n * shortcut handler uses this to distinguish crop controls (where custom\n * undo/redo should fire) from metadata text fields (where the browser's\n * native undo should be preserved).\n */\nexport const CROP_CONTROL_ATTR = 'data-crop-control';\n\n/** Idle window used to group repeated keyboard input into one gesture. */\nconst KEYBOARD_GESTURE_IDLE_MS = 300;\n\nexport interface UseCropGestureHandlersOptions {\n\t/**\n\t * When `true` (default), key-up closes the gesture so each\n\t * discrete keypress becomes its own undo step. Set to `false` for\n\t * continuous-input controls (e.g. the rotation ruler) where rapid\n\t * keypresses should coalesce into a single history entry across\n\t * the whole gesture.\n\t */\n\tcommitOnKeyUp?: boolean;\n}\n\n/**\n * Event handler props to spread onto a wrapper element around a crop\n * control. Marks the wrapper as a crop control (via `data-crop-control`)\n * so the modal's Cmd+Z handler can identify it, and wires gesture\n * boundaries on the composite store so a slider drag becomes a single\n * undo entry rather than one per tick.\n *\n * Usage:\n * const gestureHandlers = useCropGestureHandlers();\n * <div role=\"presentation\" { ...gestureHandlers }>\n * <RangeControl ... />\n * </div>\n *\n * @param options Optional behavior flags.\n */\nexport function useCropGestureHandlers(\n\toptions: UseCropGestureHandlersOptions = {}\n) {\n\tconst { commitOnKeyUp = true } = options;\n\tconst { beginGesture, endGesture } = useMediaEditor();\n\tconst keyboardTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\tconst clearKeyboardTimer = useCallback( () => {\n\t\tclearTimeout( keyboardTimerRef.current );\n\t}, [] );\n\n\tconst scheduleKeyboardEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tkeyboardTimerRef.current = setTimeout( () => {\n\t\t\tendGesture();\n\t\t}, KEYBOARD_GESTURE_IDLE_MS );\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tuseEffect( () => clearKeyboardTimer, [ clearKeyboardTimer ] );\n\n\tconst handlePointerDownCapture = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tbeginGesture();\n\t}, [ beginGesture, clearKeyboardTimer ] );\n\n\tconst handlePointerEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tendGesture();\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tconst handleKeyDownCapture = useCallback( () => {\n\t\tbeginGesture();\n\t\tif ( ! commitOnKeyUp ) {\n\t\t\tscheduleKeyboardEnd();\n\t\t}\n\t}, [ beginGesture, commitOnKeyUp, scheduleKeyboardEnd ] );\n\n\tconst handleKeyUp = useCallback( () => {\n\t\tif ( commitOnKeyUp ) {\n\t\t\tendGesture();\n\t\t\treturn;\n\t\t}\n\t\tscheduleKeyboardEnd();\n\t}, [ commitOnKeyUp, endGesture, scheduleKeyboardEnd ] );\n\n\treturn {\n\t\t[ CROP_CONTROL_ATTR ]: true,\n\t\tonPointerDownCapture: handlePointerDownCapture,\n\t\tonPointerUp: handlePointerEnd,\n\t\tonPointerCancel: handlePointerEnd,\n\t\tonKeyDownCapture: handleKeyDownCapture,\n\t\tonKeyUp: handleKeyUp,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAa,oBAAoB;;AAGjC,MAAM,2BAA2B;;;;;;;;;;;;;;;;AA4BjC,SAAgB,uBACf,UAAyC,CAAC,GACzC;CACD,MAAM,EAAE,gBAAgB,SAAS;CACjC,MAAM,EAAE,cAAc,gBAAA,GAAeA,kBAAAA,eAAAA,CAAe;CACpD,MAAM,oBAAA,GAAmBC,mBAAAA,OAAAA,CAEtB,KAAA,CAAU;CAEb,MAAM,sBAAA,GAAqBC,mBAAAA,YAAAA,OAAmB;EAC7C,aAAc,iBAAiB,OAAQ;CACxC,GAAG,CAAC,CAAE;CAEN,MAAM,uBAAA,GAAsBA,mBAAAA,YAAAA,OAAmB;EAC9C,mBAAmB;EACnB,iBAAiB,UAAU,iBAAkB;GAC5C,WAAW;EACZ,GAAG,wBAAyB;CAC7B,GAAG,CAAE,oBAAoB,UAAW,CAAE;
|
|
1
|
+
{"version":3,"file":"use-crop-gesture-handlers.cjs","names":["useMediaEditor","useRef","useCallback","useEffect"],"sources":["../../src/hooks/use-crop-gesture-handlers.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { useMediaEditor } from '../state';\n\n/**\n * Data attribute applied to crop control wrappers. The modal's keyboard\n * shortcut handler uses this to distinguish crop controls (where custom\n * undo/redo should fire) from metadata text fields (where the browser's\n * native undo should be preserved).\n */\nexport const CROP_CONTROL_ATTR = 'data-crop-control';\n\n/** Idle window used to group repeated keyboard input into one gesture. */\nconst KEYBOARD_GESTURE_IDLE_MS = 300;\n\nexport interface UseCropGestureHandlersOptions {\n\t/**\n\t * When `true` (default), key-up closes the gesture so each\n\t * discrete keypress becomes its own undo step. Set to `false` for\n\t * continuous-input controls (e.g. the rotation ruler) where rapid\n\t * keypresses should coalesce into a single history entry across\n\t * the whole gesture.\n\t */\n\tcommitOnKeyUp?: boolean;\n}\n\n/**\n * Event handler props to spread onto a wrapper element around a crop\n * control. Marks the wrapper as a crop control (via `data-crop-control`)\n * so the modal's Cmd+Z handler can identify it, and wires gesture\n * boundaries on the composite store so a slider drag becomes a single\n * undo entry rather than one per tick.\n *\n * Usage:\n * const gestureHandlers = useCropGestureHandlers();\n * <div role=\"presentation\" { ...gestureHandlers }>\n * <RangeControl ... />\n * </div>\n *\n * @param options Optional behavior flags.\n */\nexport function useCropGestureHandlers(\n\toptions: UseCropGestureHandlersOptions = {}\n) {\n\tconst { commitOnKeyUp = true } = options;\n\tconst { beginGesture, endGesture } = useMediaEditor();\n\tconst keyboardTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\n\tconst clearKeyboardTimer = useCallback( () => {\n\t\tclearTimeout( keyboardTimerRef.current );\n\t}, [] );\n\n\tconst scheduleKeyboardEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tkeyboardTimerRef.current = setTimeout( () => {\n\t\t\tendGesture();\n\t\t}, KEYBOARD_GESTURE_IDLE_MS );\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tuseEffect( () => clearKeyboardTimer, [ clearKeyboardTimer ] );\n\n\tconst handlePointerDownCapture = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tbeginGesture();\n\t}, [ beginGesture, clearKeyboardTimer ] );\n\n\tconst handlePointerEnd = useCallback( () => {\n\t\tclearKeyboardTimer();\n\t\tendGesture();\n\t}, [ clearKeyboardTimer, endGesture ] );\n\n\tconst handleKeyDownCapture = useCallback( () => {\n\t\tbeginGesture();\n\t\tif ( ! commitOnKeyUp ) {\n\t\t\tscheduleKeyboardEnd();\n\t\t}\n\t}, [ beginGesture, commitOnKeyUp, scheduleKeyboardEnd ] );\n\n\tconst handleKeyUp = useCallback( () => {\n\t\tif ( commitOnKeyUp ) {\n\t\t\tendGesture();\n\t\t\treturn;\n\t\t}\n\t\tscheduleKeyboardEnd();\n\t}, [ commitOnKeyUp, endGesture, scheduleKeyboardEnd ] );\n\n\treturn {\n\t\t[ CROP_CONTROL_ATTR ]: true,\n\t\tonPointerDownCapture: handlePointerDownCapture,\n\t\tonPointerUp: handlePointerEnd,\n\t\tonPointerCancel: handlePointerEnd,\n\t\tonKeyDownCapture: handleKeyDownCapture,\n\t\tonKeyUp: handleKeyUp,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAa,oBAAoB;;AAGjC,MAAM,2BAA2B;;;;;;;;;;;;;;;;AA4BjC,SAAgB,uBACf,UAAyC,CAAC,GACzC;CACD,MAAM,EAAE,gBAAgB,SAAS;CACjC,MAAM,EAAE,cAAc,gBAAA,GAAeA,kBAAAA,eAAAA,CAAe;CACpD,MAAM,oBAAA,GAAmBC,mBAAAA,OAAAA,CAEtB,KAAA,CAAU;CAEb,MAAM,sBAAA,GAAqBC,mBAAAA,YAAAA,OAAmB;EAC7C,aAAc,iBAAiB,OAAQ;CACxC,GAAG,CAAC,CAAE;CAEN,MAAM,uBAAA,GAAsBA,mBAAAA,YAAAA,OAAmB;EAC9C,mBAAmB;EACnB,iBAAiB,UAAU,iBAAkB;GAC5C,WAAW;EACZ,GAAG,wBAAyB;CAC7B,GAAG,CAAE,oBAAoB,UAAW,CAAE;CAEtCC,CAAAA,GAAAA,mBAAAA,UAAAA,OAAiB,oBAAoB,CAAE,kBAAmB,CAAE;CAE5D,MAAM,4BAAA,GAA2BD,mBAAAA,YAAAA,OAAmB;EACnD,mBAAmB;EACnB,aAAa;CACd,GAAG,CAAE,cAAc,kBAAmB,CAAE;CAExC,MAAM,oBAAA,GAAmBA,mBAAAA,YAAAA,OAAmB;EAC3C,mBAAmB;EACnB,WAAW;CACZ,GAAG,CAAE,oBAAoB,UAAW,CAAE;CAEtC,MAAM,wBAAA,GAAuBA,mBAAAA,YAAAA,OAAmB;EAC/C,aAAa;EACb,IAAK,CAAE,eACN,oBAAoB;CAEtB,GAAG;EAAE;EAAc;EAAe;CAAoB,CAAE;CAExD,MAAM,eAAA,GAAcA,mBAAAA,YAAAA,OAAmB;EACtC,IAAK,eAAgB;GACpB,WAAW;GACX;EACD;EACA,oBAAoB;CACrB,GAAG;EAAE;EAAe;EAAY;CAAoB,CAAE;CAEtD,OAAO;GACJ,oBAAqB;EACvB,sBAAsB;EACtB,aAAa;EACb,iBAAiB;EACjB,kBAAkB;EAClB,SAAS;CACV;AACD"}
|
package/build/index.cjs
CHANGED
|
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
11
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
12
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
15
|
-
key
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
return to;
|
|
22
24
|
};
|
|
@@ -26,10 +28,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
28
|
}) : target, mod));
|
|
27
29
|
let __components_media_editor_provider_index_tsx = require("./components/media-editor-provider/index.cjs");
|
|
28
30
|
let __components_media_preview_index_tsx = require("./components/media-preview/index.cjs");
|
|
29
|
-
__components_media_preview_index_tsx = __toESM(__components_media_preview_index_tsx);
|
|
30
31
|
let __components_media_form_index_tsx = require("./components/media-form/index.cjs");
|
|
31
|
-
__components_media_form_index_tsx = __toESM(__components_media_form_index_tsx);
|
|
32
32
|
let __private_apis_ts = require("./private-apis.cjs");
|
|
33
|
+
__components_media_preview_index_tsx = __toESM(__components_media_preview_index_tsx);
|
|
34
|
+
__components_media_form_index_tsx = __toESM(__components_media_form_index_tsx);
|
|
33
35
|
Object.defineProperty(exports, "MediaEditorProvider", {
|
|
34
36
|
enumerable: true,
|
|
35
37
|
get: function() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-apis.cjs","names":["lock"],"sources":["../src/private-apis.ts"],"sourcesContent":["import { lock } from './lock-unlock';\nimport { store } from './store';\nimport { MediaEditorModal } from './components/media-editor-modal';\nimport { MediaEditor } from './components/media-editor';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tstore,\n\tMediaEditor,\n\tMediaEditorModal,\n} );\n"],"mappings":";;;;;;;;;;AAKA,MAAa,cAAc,CAAC;CAC5BA,GAAAA,iBAAAA,KAAAA,CAAM,aAAa;
|
|
1
|
+
{"version":3,"file":"private-apis.cjs","names":["lock","store","MediaEditor","MediaEditorModal"],"sources":["../src/private-apis.ts"],"sourcesContent":["import { lock } from './lock-unlock';\nimport { store } from './store';\nimport { MediaEditorModal } from './components/media-editor-modal';\nimport { MediaEditor } from './components/media-editor';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tstore,\n\tMediaEditor,\n\tMediaEditorModal,\n} );\n"],"mappings":";;;;;;;;;;AAKA,MAAa,cAAc,CAAC;CAC5BA,GAAAA,iBAAAA,KAAAA,CAAM,aAAa;CAClBC,OAAAA,iBAAAA;CACAC,aAAAA,oCAAAA;CACAC,kBAAAA,0CAAAA;AACD,CAAE"}
|
|
@@ -42,11 +42,11 @@ const DEFAULT_ASPECT_RATIOS = [
|
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
label: (0, _wordpress_i18n.__)("Classic portrait (3:4)"),
|
|
45
|
-
value:
|
|
45
|
+
value: .75
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
label: (0, _wordpress_i18n.__)("Photo (3:2)"),
|
|
49
|
-
value:
|
|
49
|
+
value: 1.5
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
label: (0, _wordpress_i18n.__)("Photo portrait (2:3)"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aspect-ratio-presets.cjs","names":["__"],"sources":["../../src/state/aspect-ratio-presets.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\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/**\n\t * The aspect ratio value (width / height). 0 = free,\n\t * `ORIGINAL_ASPECT_RATIO` = the image's own ratio.\n\t */\n\tvalue: number;\n}\n\n/**\n * Sentinel value for \"Original\" aspect ratio — resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\n/**\n * The presets the editor offers by default. They live here rather than\n * in the image editor package, because which ratios to offer, and what\n * to call them, is a product choice. The package takes a plain number.\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"],"mappings":";;;;;;;;;;;AAmBA,MAAa,wBAAwB;;;;;;AAOrC,MAAa,wBAA6C;CACzD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,MAAO;EAAG,OAAO;CAAE;CAChC;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,UAAW;EAAG,OAAA;CAA6B;CACxD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,cAAe;EAAG,OAAO;CAAE;CACxC;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,kBAAmB;EAAG,OAAO,KAAK;CAAE;CACjD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,iBAAkB;EAAG,OAAO,IAAI;CAAG;CAChD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,eAAgB;EAAG,OAAO,IAAI;CAAE;CAC7C;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,wBAAyB;EAAG,OAAO
|
|
1
|
+
{"version":3,"file":"aspect-ratio-presets.cjs","names":["__"],"sources":["../../src/state/aspect-ratio-presets.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\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/**\n\t * The aspect ratio value (width / height). 0 = free,\n\t * `ORIGINAL_ASPECT_RATIO` = the image's own ratio.\n\t */\n\tvalue: number;\n}\n\n/**\n * Sentinel value for \"Original\" aspect ratio — resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\n/**\n * The presets the editor offers by default. They live here rather than\n * in the image editor package, because which ratios to offer, and what\n * to call them, is a product choice. The package takes a plain number.\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"],"mappings":";;;;;;;;;;;AAmBA,MAAa,wBAAwB;;;;;;AAOrC,MAAa,wBAA6C;CACzD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,MAAO;EAAG,OAAO;CAAE;CAChC;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,UAAW;EAAG,OAAA;CAA6B;CACxD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,cAAe;EAAG,OAAO;CAAE;CACxC;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,kBAAmB;EAAG,OAAO,KAAK;CAAE;CACjD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,iBAAkB;EAAG,OAAO,IAAI;CAAG;CAChD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,eAAgB;EAAG,OAAO,IAAI;CAAE;CAC7C;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,wBAAyB;EAAG,OAAO;CAAM;CACtD;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,aAAc;EAAG,OAAO;CAAM;CAC3C;EAAE,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,sBAAuB;EAAG,OAAO,IAAI;CAAE;AACrD"}
|
|
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
11
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
12
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
15
|
-
key
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
return to;
|
|
22
24
|
};
|
|
@@ -25,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
27
|
enumerable: true
|
|
26
28
|
}) : target, mod));
|
|
27
29
|
let fast_deep_equal_es6_index_js = require("fast-deep-equal/es6/index.js");
|
|
28
|
-
fast_deep_equal_es6_index_js = __toESM(fast_deep_equal_es6_index_js);
|
|
29
30
|
let _wordpress_image_editor = require("@wordpress/image-editor");
|
|
30
31
|
let __types_ts = require("./types.cjs");
|
|
32
|
+
fast_deep_equal_es6_index_js = __toESM(fast_deep_equal_es6_index_js);
|
|
31
33
|
// packages/media-editor/src/state/composite-reducer.ts
|
|
32
34
|
/**
|
|
33
35
|
* Pure reducer for the media editor.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composite-reducer.cjs","names":["fastDeepEqual","createImageEditorState","areImageEditorStatesEqual","DEFAULT_CROP_OPTIONS"],"sources":["../../src/state/composite-reducer.ts"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport {\n\tareImageEditorStatesEqual,\n\tcreateImageEditorState,\n\ttype ImageEditorState,\n} from '@wordpress/image-editor';\nimport {\n\tDEFAULT_CROP_OPTIONS,\n\ttype MediaEditorAction,\n\ttype MediaEditorState,\n} from './types';\n\n/**\n * Pure reducer for the media editor.\n *\n * The image editor works out its own next state (through the controller from\n * `@wordpress/image-editor`) and this reducer stores it. The reducer\n * also owns the sidebar crop options and the named edits.\n *\n * This reducer keeps no history; `useMediaEditorState` does.\n *\n * @param state Current state.\n * @param action Action to apply.\n * @return Next state.\n */\nexport function mediaEditorReducer(\n\tstate: MediaEditorState,\n\taction: MediaEditorAction\n): MediaEditorState {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IMAGE_EDITOR':\n\t\t\treturn action.payload === state.imageEditor\n\t\t\t\t? state\n\t\t\t\t: { ...state, imageEditor: action.payload };\n\t\tcase 'SET_ASPECT_RATIO_VALUE':\n\t\t\treturn state.cropOptions.aspectRatioValue === action.payload\n\t\t\t\t? state\n\t\t\t\t: {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tcropOptions: {\n\t\t\t\t\t\t\t...state.cropOptions,\n\t\t\t\t\t\t\taspectRatioValue: action.payload,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\tcase 'SET_EDIT': {\n\t\t\tconst { name, value } = action.payload;\n\t\t\tif ( value === undefined ) {\n\t\t\t\tif ( ! Object.hasOwn( state.edits, name ) ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\tconst edits = { ...state.edits };\n\t\t\t\tdelete edits[ name ];\n\t\t\t\treturn { ...state, edits };\n\t\t\t}\n\t\t\tif ( fastDeepEqual( state.edits[ name ], value ) ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, edits: { ...state.edits, [ name ]: value } };\n\t\t}\n\t\tcase 'RESET': {\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcreateImageEditorState( { image: state.imageEditor.image } )\n\t\t\t);\n\t\t\treturn areMediaEditorStatesEqual( state, next ) ? state : next;\n\t\t}\n\t\tcase 'RESTORE_SNAPSHOT':\n\t\t\treturn action.payload;\n\t}\n}\n\n/**\n * Value-equality check for two media editor states. The history uses it\n * to skip snapshots when an action turned out to be a no-op.\n *\n * @param a First state.\n * @param b Second state.\n * @return Whether `a` and `b` are value-equal across all slices.\n */\nexport function areMediaEditorStatesEqual(\n\ta: MediaEditorState,\n\tb: MediaEditorState\n): boolean {\n\tif ( a === b ) {\n\t\treturn true;\n\t}\n\treturn (\n\t\tareImageEditorStatesEqual( a.imageEditor, b.imageEditor ) &&\n\t\ta.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&\n\t\tfastDeepEqual( a.edits, b.edits )\n\t);\n}\n\n/**\n * Build the state a session starts from: the given image editor state,\n * default crop options, and no edits.\n *\n * @param imageEditor The image editor state.\n * @return Initial state.\n */\nexport function buildInitialMediaEditorState(\n\timageEditor: ImageEditorState\n): MediaEditorState {\n\treturn {\n\t\timageEditor,\n\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS },\n\t\tedits: {},\n\t};\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"composite-reducer.cjs","names":["fastDeepEqual","createImageEditorState","areImageEditorStatesEqual","DEFAULT_CROP_OPTIONS"],"sources":["../../src/state/composite-reducer.ts"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport {\n\tareImageEditorStatesEqual,\n\tcreateImageEditorState,\n\ttype ImageEditorState,\n} from '@wordpress/image-editor';\nimport {\n\tDEFAULT_CROP_OPTIONS,\n\ttype MediaEditorAction,\n\ttype MediaEditorState,\n} from './types';\n\n/**\n * Pure reducer for the media editor.\n *\n * The image editor works out its own next state (through the controller from\n * `@wordpress/image-editor`) and this reducer stores it. The reducer\n * also owns the sidebar crop options and the named edits.\n *\n * This reducer keeps no history; `useMediaEditorState` does.\n *\n * @param state Current state.\n * @param action Action to apply.\n * @return Next state.\n */\nexport function mediaEditorReducer(\n\tstate: MediaEditorState,\n\taction: MediaEditorAction\n): MediaEditorState {\n\tswitch ( action.type ) {\n\t\tcase 'SET_IMAGE_EDITOR':\n\t\t\treturn action.payload === state.imageEditor\n\t\t\t\t? state\n\t\t\t\t: { ...state, imageEditor: action.payload };\n\t\tcase 'SET_ASPECT_RATIO_VALUE':\n\t\t\treturn state.cropOptions.aspectRatioValue === action.payload\n\t\t\t\t? state\n\t\t\t\t: {\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\tcropOptions: {\n\t\t\t\t\t\t\t...state.cropOptions,\n\t\t\t\t\t\t\taspectRatioValue: action.payload,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\tcase 'SET_EDIT': {\n\t\t\tconst { name, value } = action.payload;\n\t\t\tif ( value === undefined ) {\n\t\t\t\tif ( ! Object.hasOwn( state.edits, name ) ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\tconst edits = { ...state.edits };\n\t\t\t\tdelete edits[ name ];\n\t\t\t\treturn { ...state, edits };\n\t\t\t}\n\t\t\tif ( fastDeepEqual( state.edits[ name ], value ) ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, edits: { ...state.edits, [ name ]: value } };\n\t\t}\n\t\tcase 'RESET': {\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcreateImageEditorState( { image: state.imageEditor.image } )\n\t\t\t);\n\t\t\treturn areMediaEditorStatesEqual( state, next ) ? state : next;\n\t\t}\n\t\tcase 'RESTORE_SNAPSHOT':\n\t\t\treturn action.payload;\n\t}\n}\n\n/**\n * Value-equality check for two media editor states. The history uses it\n * to skip snapshots when an action turned out to be a no-op.\n *\n * @param a First state.\n * @param b Second state.\n * @return Whether `a` and `b` are value-equal across all slices.\n */\nexport function areMediaEditorStatesEqual(\n\ta: MediaEditorState,\n\tb: MediaEditorState\n): boolean {\n\tif ( a === b ) {\n\t\treturn true;\n\t}\n\treturn (\n\t\tareImageEditorStatesEqual( a.imageEditor, b.imageEditor ) &&\n\t\ta.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&\n\t\tfastDeepEqual( a.edits, b.edits )\n\t);\n}\n\n/**\n * Build the state a session starts from: the given image editor state,\n * default crop options, and no edits.\n *\n * @param imageEditor The image editor state.\n * @return Initial state.\n */\nexport function buildInitialMediaEditorState(\n\timageEditor: ImageEditorState\n): MediaEditorState {\n\treturn {\n\t\timageEditor,\n\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS },\n\t\tedits: {},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,mBACf,OACA,QACmB;CACnB,QAAS,OAAO,MAAhB;EACC,KAAK,oBACJ,OAAO,OAAO,YAAY,MAAM,cAC7B,QACA;GAAE,GAAG;GAAO,aAAa,OAAO;EAAQ;EAC5C,KAAK,0BACJ,OAAO,MAAM,YAAY,qBAAqB,OAAO,UAClD,QACA;GACA,GAAG;GACH,aAAa;IACZ,GAAG,MAAM;IACT,kBAAkB,OAAO;GAC1B;EACD;EACH,KAAK,YAAY;GAChB,MAAM,EAAE,MAAM,UAAU,OAAO;GAC/B,IAAK,UAAU,KAAA,GAAY;IAC1B,IAAK,CAAE,OAAO,OAAQ,MAAM,OAAO,IAAK,GACvC,OAAO;IAER,MAAM,QAAQ,EAAE,GAAG,MAAM,MAAM;IAC/B,OAAO,MAAO;IACd,OAAO;KAAE,GAAG;KAAO;IAAM;GAC1B;GACA,KAAA,GAAKA,6BAAAA,QAAAA,CAAe,MAAM,MAAO,OAAQ,KAAM,GAC9C,OAAO;GAER,OAAO;IAAE,GAAG;IAAO,OAAO;KAAE,GAAG,MAAM;MAAS,OAAQ;IAAM;GAAE;EAC/D;EACA,KAAK,SAAS;GACb,MAAM,OAAO,8BAAA,GACZC,wBAAAA,uBAAA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