@wordpress/media-editor 0.7.1-next.v.202604201441.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/media-editor-canvas/index.cjs +54 -0
- package/build/components/media-editor-canvas/index.cjs.map +7 -0
- package/build/components/media-editor-crop-panel/index.cjs +116 -0
- package/build/components/media-editor-crop-panel/index.cjs.map +7 -0
- package/build/components/media-editor-modal/build-modifiers.cjs +91 -0
- package/build/components/media-editor-modal/build-modifiers.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +497 -0
- package/build/components/media-editor-modal/index.cjs.map +7 -0
- package/build/components/media-editor-toolbar/index.cjs +146 -0
- package/build/components/media-editor-toolbar/index.cjs.map +7 -0
- package/build/image-editor/core/camera.cjs +194 -0
- package/build/image-editor/core/camera.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +81 -0
- package/build/image-editor/core/constants.cjs.map +7 -0
- package/build/image-editor/core/containment.cjs +245 -0
- package/build/image-editor/core/containment.cjs.map +7 -0
- package/build/image-editor/core/export/canvas-renderer.cjs +151 -0
- package/build/image-editor/core/export/canvas-renderer.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +50 -0
- package/build/image-editor/core/index.cjs.map +7 -0
- package/build/image-editor/core/interaction-controller.cjs +608 -0
- package/build/image-editor/core/interaction-controller.cjs.map +7 -0
- package/build/image-editor/core/math/rotation.cjs +41 -0
- package/build/image-editor/core/math/rotation.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +95 -0
- package/build/image-editor/core/source-region.cjs.map +7 -0
- package/build/image-editor/core/state.cjs +269 -0
- package/build/image-editor/core/state.cjs.map +7 -0
- package/build/image-editor/core/stencil-math.cjs +197 -0
- package/build/image-editor/core/stencil-math.cjs.map +7 -0
- package/build/image-editor/core/transform-style.cjs +46 -0
- package/build/image-editor/core/transform-style.cjs.map +7 -0
- package/build/image-editor/core/transforms/pipeline.cjs +43 -0
- package/build/image-editor/core/transforms/pipeline.cjs.map +7 -0
- package/build/image-editor/core/types.cjs +19 -0
- package/build/image-editor/core/types.cjs.map +7 -0
- package/build/image-editor/index.cjs +57 -0
- package/build/image-editor/index.cjs.map +7 -0
- package/build/image-editor/react/components/cropper-provider.cjs +50 -0
- package/build/image-editor/react/components/cropper-provider.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +365 -0
- package/build/image-editor/react/components/cropper.cjs.map +7 -0
- package/build/image-editor/react/components/index.cjs +36 -0
- package/build/image-editor/react/components/index.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +58 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +91 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +351 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +31 -0
- package/build/image-editor/react/hooks/index.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +68 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs +158 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +161 -0
- package/build/image-editor/react/hooks/use-interaction.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs +38 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +7 -0
- package/build/index.cjs +5 -2
- package/build/index.cjs.map +2 -2
- package/build/lock-unlock.cjs +37 -0
- package/build/lock-unlock.cjs.map +7 -0
- package/build/private-apis.cjs +38 -0
- package/build/private-apis.cjs.map +7 -0
- package/build/store/actions.cjs +45 -0
- package/build/store/actions.cjs.map +7 -0
- package/build/store/constants.cjs +31 -0
- package/build/store/constants.cjs.map +7 -0
- package/build/store/index.cjs +51 -0
- package/build/store/index.cjs.map +7 -0
- package/build/store/reducer.cjs +51 -0
- package/build/store/reducer.cjs.map +7 -0
- package/build/store/selectors.cjs +43 -0
- package/build/store/selectors.cjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +33 -0
- package/build-module/components/media-editor-canvas/index.mjs.map +7 -0
- package/build-module/components/media-editor-crop-panel/index.mjs +100 -0
- package/build-module/components/media-editor-crop-panel/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs +66 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +483 -0
- package/build-module/components/media-editor-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-toolbar/index.mjs +130 -0
- package/build-module/components/media-editor-toolbar/index.mjs.map +7 -0
- package/build-module/image-editor/core/camera.mjs +163 -0
- package/build-module/image-editor/core/camera.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +51 -0
- package/build-module/image-editor/core/constants.mjs.map +7 -0
- package/build-module/image-editor/core/containment.mjs +218 -0
- package/build-module/image-editor/core/containment.mjs.map +7 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs +120 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +24 -0
- package/build-module/image-editor/core/index.mjs.map +7 -0
- package/build-module/image-editor/core/interaction-controller.mjs +583 -0
- package/build-module/image-editor/core/interaction-controller.mjs.map +7 -0
- package/build-module/image-editor/core/math/rotation.mjs +15 -0
- package/build-module/image-editor/core/math/rotation.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +69 -0
- package/build-module/image-editor/core/source-region.mjs.map +7 -0
- package/build-module/image-editor/core/state.mjs +242 -0
- package/build-module/image-editor/core/state.mjs.map +7 -0
- package/build-module/image-editor/core/stencil-math.mjs +169 -0
- package/build-module/image-editor/core/stencil-math.mjs.map +7 -0
- package/build-module/image-editor/core/transform-style.mjs +21 -0
- package/build-module/image-editor/core/transform-style.mjs.map +7 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs +17 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +7 -0
- package/build-module/image-editor/core/types.mjs +1 -0
- package/build-module/image-editor/core/types.mjs.map +7 -0
- package/build-module/image-editor/index.mjs +30 -0
- package/build-module/image-editor/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs +26 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +337 -0
- package/build-module/image-editor/react/components/cropper.mjs.map +7 -0
- package/build-module/image-editor/react/components/index.mjs +9 -0
- package/build-module/image-editor/react/components/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +33 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +66 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +330 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +6 -0
- package/build-module/image-editor/react/hooks/index.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +43 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +137 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +138 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +13 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +7 -0
- package/build-module/index.mjs +3 -1
- package/build-module/index.mjs.map +2 -2
- package/build-module/lock-unlock.mjs +11 -0
- package/build-module/lock-unlock.mjs.map +7 -0
- package/build-module/private-apis.mjs +13 -0
- package/build-module/private-apis.mjs.map +7 -0
- package/build-module/store/actions.mjs +19 -0
- package/build-module/store/actions.mjs.map +7 -0
- package/build-module/store/constants.mjs +6 -0
- package/build-module/store/constants.mjs.map +7 -0
- package/build-module/store/index.mjs +16 -0
- package/build-module/store/index.mjs.map +7 -0
- package/build-module/store/reducer.mjs +26 -0
- package/build-module/store/reducer.mjs.map +7 -0
- package/build-module/store/selectors.mjs +16 -0
- package/build-module/store/selectors.mjs.map +7 -0
- package/build-style/style-rtl.css +315 -0
- package/build-style/style.css +315 -0
- package/build-types/components/media-editor-canvas/index.d.ts +22 -0
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts +45 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +20 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-toolbar/index.d.ts +21 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/image-editor/core/camera.d.ts +107 -0
- package/build-types/image-editor/core/camera.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +46 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -0
- package/build-types/image-editor/core/containment.d.ts +61 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +106 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +8 -0
- package/build-types/image-editor/core/index.d.ts.map +1 -0
- package/build-types/image-editor/core/interaction-controller.d.ts +178 -0
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
- package/build-types/image-editor/core/math/rotation.d.ts +18 -0
- package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts +75 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -0
- package/build-types/image-editor/core/state.d.ts +42 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -0
- package/build-types/image-editor/core/stencil-math.d.ts +79 -0
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
- package/build-types/image-editor/core/transform-style.d.ts +23 -0
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
- package/build-types/image-editor/core/types.d.ts +211 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -0
- package/build-types/image-editor/index.d.ts +16 -0
- package/build-types/image-editor/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +37 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper.d.ts +59 -0
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
- package/build-types/image-editor/react/components/index.d.ts +4 -0
- package/build-types/image-editor/react/components/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +32 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +3 -0
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +68 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +60 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +2 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +27 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +2 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +4 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +23 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +8 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/package.json +21 -7
- package/src/components/media-editor-canvas/index.tsx +56 -0
- package/src/components/media-editor-canvas/style.scss +9 -0
- package/src/components/media-editor-crop-panel/index.tsx +143 -0
- package/src/components/media-editor-modal/build-modifiers.ts +164 -0
- package/src/components/media-editor-modal/index.tsx +639 -0
- package/src/components/media-editor-modal/style.scss +139 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +343 -0
- package/src/components/media-editor-toolbar/index.tsx +150 -0
- package/src/components/media-editor-toolbar/style.scss +21 -0
- package/src/image-editor/README.md +162 -0
- package/src/image-editor/core/camera.ts +352 -0
- package/src/image-editor/core/constants.ts +93 -0
- package/src/image-editor/core/containment.ts +435 -0
- package/src/image-editor/core/export/canvas-renderer.ts +253 -0
- package/src/image-editor/core/export/test/canvas-renderer.ts +813 -0
- package/src/image-editor/core/index.ts +35 -0
- package/src/image-editor/core/interaction-controller.ts +889 -0
- package/src/image-editor/core/math/rotation.ts +26 -0
- package/src/image-editor/core/source-region.ts +166 -0
- package/src/image-editor/core/state.ts +428 -0
- package/src/image-editor/core/stencil-math.ts +330 -0
- package/src/image-editor/core/test/camera.ts +593 -0
- package/src/image-editor/core/test/interaction-controller.ts +996 -0
- package/src/image-editor/core/test/preview-export-parity.ts +242 -0
- package/src/image-editor/core/test/render-camera-bridge.ts +348 -0
- package/src/image-editor/core/test/state.ts +762 -0
- package/src/image-editor/core/test/stencil-math.ts +321 -0
- package/src/image-editor/core/transform-style.ts +44 -0
- package/src/image-editor/core/transforms/pipeline.ts +43 -0
- package/src/image-editor/core/transforms/test/pipeline.ts +269 -0
- package/src/image-editor/core/types.ts +177 -0
- package/src/image-editor/docs/architecture.md +96 -0
- package/src/image-editor/docs/recipes.md +720 -0
- package/src/image-editor/docs/roadmap.md +66 -0
- package/src/image-editor/index.ts +43 -0
- package/src/image-editor/react/components/cropper-provider.tsx +73 -0
- package/src/image-editor/react/components/cropper.scss +195 -0
- package/src/image-editor/react/components/cropper.tsx +534 -0
- package/src/image-editor/react/components/index.ts +3 -0
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +57 -0
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +80 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +513 -0
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +265 -0
- package/src/image-editor/react/components/test/cropper.tsx +140 -0
- package/src/image-editor/react/hooks/index.ts +2 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +913 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +218 -0
- package/src/image-editor/react/hooks/test/use-transform-style.ts +146 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +64 -0
- package/src/image-editor/react/hooks/use-cropper-state.ts +238 -0
- package/src/image-editor/react/hooks/use-interaction.ts +223 -0
- package/src/image-editor/react/hooks/use-transform-style.ts +30 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +1085 -0
- package/src/image-editor/stories/style.css +94 -0
- package/src/image-editor/style.scss +1 -0
- package/src/index.ts +3 -0
- package/src/lock-unlock.ts +10 -0
- package/src/private-apis.ts +12 -0
- package/src/store/actions.ts +33 -0
- package/src/store/constants.ts +1 -0
- package/src/store/index.ts +20 -0
- package/src/store/reducer.ts +48 -0
- package/src/store/selectors.ts +16 -0
- package/src/store/test/reducer.ts +57 -0
- package/src/style.scss +4 -0
- package/tsconfig.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/components/media-editor-canvas/index.tsx
|
|
21
|
+
var media_editor_canvas_exports = {};
|
|
22
|
+
__export(media_editor_canvas_exports, {
|
|
23
|
+
default: () => MediaEditorCanvas
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(media_editor_canvas_exports);
|
|
26
|
+
var import_media_editor_provider = require("../media-editor-provider/index.cjs");
|
|
27
|
+
var import_utils = require("../../utils/index.cjs");
|
|
28
|
+
var import_image_editor = require("../../image-editor/index.cjs");
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
function MediaEditorCanvas({
|
|
31
|
+
aspectRatio,
|
|
32
|
+
freeformCrop,
|
|
33
|
+
isPlacementActive = false
|
|
34
|
+
}) {
|
|
35
|
+
const { media } = (0, import_media_editor_provider.useMediaEditorContext)();
|
|
36
|
+
const controller = (0, import_image_editor.useCropper)();
|
|
37
|
+
const mediaUrl = media?.source_url;
|
|
38
|
+
const mediaType = (0, import_utils.getMediaTypeFromMimeType)(media?.mime_type);
|
|
39
|
+
if (!mediaUrl || mediaType.type !== "image") {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "media-editor-canvas", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
43
|
+
import_image_editor.Cropper,
|
|
44
|
+
{
|
|
45
|
+
src: mediaUrl,
|
|
46
|
+
controller,
|
|
47
|
+
aspectRatio,
|
|
48
|
+
freeformCrop,
|
|
49
|
+
showGrid: "interactive",
|
|
50
|
+
isPlacementActive
|
|
51
|
+
}
|
|
52
|
+
) });
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/media-editor-canvas/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { Cropper, useCropper } from '../../image-editor';\n\nexport interface MediaEditorCanvasProps {\n\t/** Fixed aspect ratio (width / height). `undefined` means free. */\n\taspectRatio?: number;\n\t/** Enable freeform crop mode (resize handles). */\n\tfreeformCrop?: boolean;\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls its\n * cropper controller from the surrounding `<CropperProvider>` so the\n * bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n * @param props\n * @param props.aspectRatio\n * @param props.freeformCrop\n * @param props.isPlacementActive\n */\nexport default function MediaEditorCanvas( {\n\taspectRatio,\n\tfreeformCrop,\n\tisPlacementActive = false,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst controller = useCropper();\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\n\tif ( ! mediaUrl || mediaType.type !== 'image' ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t<Cropper\n\t\t\t\tsrc={ mediaUrl }\n\t\t\t\tcontroller={ controller }\n\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\tfreeformCrop={ freeformCrop }\n\t\t\t\tshowGrid=\"interactive\"\n\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mCAAsC;AACtC,mBAAyC;AACzC,0BAAoC;AAwCjC;AAjBY,SAAR,kBAAoC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA,oBAAoB;AACrB,GAA4B;AAC3B,QAAM,EAAE,MAAM,QAAI,oDAAsB;AACxC,QAAM,iBAAa,gCAAW;AAE9B,QAAM,WAAW,OAAO;AACxB,QAAM,gBAAY,uCAA0B,OAAO,SAAU;AAE7D,MAAK,CAAE,YAAY,UAAU,SAAS,SAAU;AAC/C,WAAO;AAAA,EACR;AAEA,SACC,4CAAC,SAAI,WAAU,uBACd;AAAA,IAAC;AAAA;AAAA,MACA,KAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAS;AAAA,MACT;AAAA;AAAA,EACD,GACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/components/media-editor-crop-panel/index.tsx
|
|
21
|
+
var media_editor_crop_panel_exports = {};
|
|
22
|
+
__export(media_editor_crop_panel_exports, {
|
|
23
|
+
default: () => MediaEditorCropPanel,
|
|
24
|
+
resolveAspectRatio: () => resolveAspectRatio
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(media_editor_crop_panel_exports);
|
|
27
|
+
var import_components = require("@wordpress/components");
|
|
28
|
+
var import_ui = require("@wordpress/ui");
|
|
29
|
+
var import_i18n = require("@wordpress/i18n");
|
|
30
|
+
var import_image_editor = require("../../image-editor/index.cjs");
|
|
31
|
+
var import_constants = require("../../image-editor/core/constants.cjs");
|
|
32
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
function resolveAspectRatio(value, imageAspectRatio) {
|
|
34
|
+
const num = parseFloat(value);
|
|
35
|
+
if (num === 0) {
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
if (num === import_constants.ORIGINAL_ASPECT_RATIO && imageAspectRatio) {
|
|
39
|
+
return imageAspectRatio;
|
|
40
|
+
}
|
|
41
|
+
if (num > 0) {
|
|
42
|
+
return num;
|
|
43
|
+
}
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
function MediaEditorCropPanel({
|
|
47
|
+
aspectRatioValue,
|
|
48
|
+
onAspectRatioChange,
|
|
49
|
+
freeformCrop,
|
|
50
|
+
onFreeformChange,
|
|
51
|
+
onPlacementControlInteraction,
|
|
52
|
+
aspectRatioPresets
|
|
53
|
+
}) {
|
|
54
|
+
const { state, setZoom } = (0, import_image_editor.useCropper)();
|
|
55
|
+
const aspectRatioOptions = [
|
|
56
|
+
...import_constants.DEFAULT_ASPECT_RATIOS.filter((preset) => preset.value <= 0),
|
|
57
|
+
...aspectRatioPresets ?? import_constants.DEFAULT_ASPECT_RATIOS.filter((preset) => preset.value > 0)
|
|
58
|
+
];
|
|
59
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui.Stack, { direction: "column", gap: "md", children: [
|
|
60
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
61
|
+
import_components.RangeControl,
|
|
62
|
+
{
|
|
63
|
+
__next40pxDefaultSize: true,
|
|
64
|
+
__nextHasNoMarginBottom: true,
|
|
65
|
+
label: (0, import_i18n.__)("Zoom"),
|
|
66
|
+
min: import_constants.MIN_ZOOM,
|
|
67
|
+
max: import_constants.MAX_ZOOM,
|
|
68
|
+
step: 0.1,
|
|
69
|
+
value: state.zoom,
|
|
70
|
+
onChange: (value) => {
|
|
71
|
+
onPlacementControlInteraction?.();
|
|
72
|
+
setZoom(typeof value === "number" ? value : import_constants.MIN_ZOOM);
|
|
73
|
+
},
|
|
74
|
+
renderTooltipContent: (value) => {
|
|
75
|
+
const zoom = typeof value === "number" ? value : import_constants.MIN_ZOOM;
|
|
76
|
+
return (0, import_i18n.sprintf)(
|
|
77
|
+
/* translators: %d: zoom level as a percentage. */
|
|
78
|
+
(0, import_i18n.__)("%d%%"),
|
|
79
|
+
Math.round(zoom * 100)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
),
|
|
84
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
85
|
+
import_components.SelectControl,
|
|
86
|
+
{
|
|
87
|
+
__next40pxDefaultSize: true,
|
|
88
|
+
__nextHasNoMarginBottom: true,
|
|
89
|
+
label: (0, import_i18n.__)("Aspect ratio"),
|
|
90
|
+
value: aspectRatioValue,
|
|
91
|
+
onChange: onAspectRatioChange,
|
|
92
|
+
options: aspectRatioOptions.map((preset) => ({
|
|
93
|
+
label: preset.label,
|
|
94
|
+
value: preset.value.toString()
|
|
95
|
+
}))
|
|
96
|
+
}
|
|
97
|
+
),
|
|
98
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
99
|
+
import_components.ToggleControl,
|
|
100
|
+
{
|
|
101
|
+
__nextHasNoMarginBottom: true,
|
|
102
|
+
label: (0, import_i18n.__)("Freeform crop"),
|
|
103
|
+
help: (0, import_i18n.__)(
|
|
104
|
+
"Drag the crop edges to resize freely. When off, the crop is fixed to the selected ratio."
|
|
105
|
+
),
|
|
106
|
+
checked: freeformCrop,
|
|
107
|
+
onChange: onFreeformChange
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
] });
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
resolveAspectRatio
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/media-editor-crop-panel/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tRangeControl,\n\tSelectControl,\n\tToggleControl,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useCropper } from '../../image-editor';\nimport {\n\tDEFAULT_ASPECT_RATIOS,\n\tMAX_ZOOM,\n\tMIN_ZOOM,\n\tORIGINAL_ASPECT_RATIO,\n} from '../../image-editor/core/constants';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\n\nexport interface MediaEditorCropPanelProps {\n\t/**\n\t * Selected aspect-ratio preset value as a string (so it round-trips\n\t * through `<SelectControl>`). `'0'` = free, `'-1'` = original, any\n\t * positive number = fixed ratio.\n\t */\n\taspectRatioValue: string;\n\t/** Setter for the aspect-ratio preset value. */\n\tonAspectRatioChange: ( value: string ) => void;\n\t/** Whether the cropper is in freeform (resize-handle) mode. */\n\tfreeformCrop: boolean;\n\t/** Setter for freeform mode. */\n\tonFreeformChange: ( value: boolean ) => void;\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Fixed aspect-ratio presets to display after Free and Original. When\n\t * omitted, the media editor's default fixed-ratio presets are used.\n\t */\n\taspectRatioPresets?: AspectRatioPreset[];\n}\n\n/**\n * Resolve an aspect-ratio preset value into a number suitable for\n * `<Cropper aspectRatio=...>`. Returns `undefined` for Free (no lock).\n *\n * @param value Preset value as a string.\n * @param imageAspectRatio Image's natural width / height \u2014 used for\n * the Original preset.\n */\nexport function resolveAspectRatio(\n\tvalue: string,\n\timageAspectRatio: number | null\n): number | undefined {\n\tconst num = parseFloat( value );\n\tif ( num === 0 ) {\n\t\treturn undefined;\n\t}\n\tif ( num === ORIGINAL_ASPECT_RATIO && imageAspectRatio ) {\n\t\treturn imageAspectRatio;\n\t}\n\tif ( num > 0 ) {\n\t\treturn num;\n\t}\n\treturn undefined;\n}\n\n/**\n * Sidebar panel for crop-shape controls \u2014 aspect-ratio presets and\n * freeform toggle. The tactile verbs (rotate, flip) live in the\n * bottom toolbar instead.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.freeformCrop\n * @param props.onFreeformChange\n * @param props.onPlacementControlInteraction\n * @param props.aspectRatioPresets\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\tfreeformCrop,\n\tonFreeformChange,\n\tonPlacementControlInteraction,\n\taspectRatioPresets,\n}: MediaEditorCropPanelProps ) {\n\tconst { state, setZoom } = useCropper();\n\tconst aspectRatioOptions = [\n\t\t...DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value <= 0 ),\n\t\t...( aspectRatioPresets ??\n\t\t\tDEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value > 0 ) ),\n\t];\n\n\treturn (\n\t\t<Stack direction=\"column\" gap=\"md\">\n\t\t\t<RangeControl\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tlabel={ __( 'Zoom' ) }\n\t\t\t\tmin={ MIN_ZOOM }\n\t\t\t\tmax={ MAX_ZOOM }\n\t\t\t\tstep={ 0.1 }\n\t\t\t\tvalue={ state.zoom }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tonPlacementControlInteraction?.();\n\t\t\t\t\tsetZoom( typeof value === 'number' ? value : MIN_ZOOM );\n\t\t\t\t} }\n\t\t\t\trenderTooltipContent={ ( value ) => {\n\t\t\t\t\tconst zoom = typeof value === 'number' ? value : MIN_ZOOM;\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t/* translators: %d: zoom level as a percentage. */\n\t\t\t\t\t\t__( '%d%%' ),\n\t\t\t\t\t\tMath.round( zoom * 100 )\n\t\t\t\t\t);\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t<SelectControl\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\tonChange={ onAspectRatioChange }\n\t\t\t\toptions={ aspectRatioOptions.map( ( preset ) => ( {\n\t\t\t\t\tlabel: preset.label,\n\t\t\t\t\tvalue: preset.value.toString(),\n\t\t\t\t} ) ) }\n\t\t\t/>\n\t\t\t<ToggleControl\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tlabel={ __( 'Freeform crop' ) }\n\t\t\t\thelp={ __(\n\t\t\t\t\t'Drag the crop edges to resize freely. When off, the crop is fixed to the selected ratio.'\n\t\t\t\t) }\n\t\t\t\tchecked={ freeformCrop }\n\t\t\t\tonChange={ onFreeformChange }\n\t\t\t/>\n\t\t</Stack>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAIO;AACP,gBAAsB;AACtB,kBAA4B;AAK5B,0BAA2B;AAC3B,uBAKO;AA8EL;AA7CK,SAAS,mBACf,OACA,kBACqB;AACrB,QAAM,MAAM,WAAY,KAAM;AAC9B,MAAK,QAAQ,GAAI;AAChB,WAAO;AAAA,EACR;AACA,MAAK,QAAQ,0CAAyB,kBAAmB;AACxD,WAAO;AAAA,EACR;AACA,MAAK,MAAM,GAAI;AACd,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAce,SAAR,qBAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA+B;AAC9B,QAAM,EAAE,OAAO,QAAQ,QAAI,gCAAW;AACtC,QAAM,qBAAqB;AAAA,IAC1B,GAAG,uCAAsB,OAAQ,CAAE,WAAY,OAAO,SAAS,CAAE;AAAA,IACjE,GAAK,sBACJ,uCAAsB,OAAQ,CAAE,WAAY,OAAO,QAAQ,CAAE;AAAA,EAC/D;AAEA,SACC,6CAAC,mBAAM,WAAU,UAAS,KAAI,MAC7B;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,uBAAqB;AAAA,QACrB,yBAAuB;AAAA,QACvB,WAAQ,gBAAI,MAAO;AAAA,QACnB,KAAM;AAAA,QACN,KAAM;AAAA,QACN,MAAO;AAAA,QACP,OAAQ,MAAM;AAAA,QACd,UAAW,CAAE,UAAW;AACvB,0CAAgC;AAChC,kBAAS,OAAO,UAAU,WAAW,QAAQ,yBAAS;AAAA,QACvD;AAAA,QACA,sBAAuB,CAAE,UAAW;AACnC,gBAAM,OAAO,OAAO,UAAU,WAAW,QAAQ;AACjD,qBAAO;AAAA;AAAA,gBAEN,gBAAI,MAAO;AAAA,YACX,KAAK,MAAO,OAAO,GAAI;AAAA,UACxB;AAAA,QACD;AAAA;AAAA,IACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,uBAAqB;AAAA,QACrB,yBAAuB;AAAA,QACvB,WAAQ,gBAAI,cAAe;AAAA,QAC3B,OAAQ;AAAA,QACR,UAAW;AAAA,QACX,SAAU,mBAAmB,IAAK,CAAE,YAAc;AAAA,UACjD,OAAO,OAAO;AAAA,UACd,OAAO,OAAO,MAAM,SAAS;AAAA,QAC9B,EAAI;AAAA;AAAA,IACL;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,yBAAuB;AAAA,QACvB,WAAQ,gBAAI,eAAgB;AAAA,QAC5B,UAAO;AAAA,UACN;AAAA,QACD;AAAA,QACA,SAAU;AAAA,QACV,UAAW;AAAA;AAAA,IACZ;AAAA,KACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/components/media-editor-modal/build-modifiers.ts
|
|
21
|
+
var build_modifiers_exports = {};
|
|
22
|
+
__export(build_modifiers_exports, {
|
|
23
|
+
buildModifiers: () => buildModifiers
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(build_modifiers_exports);
|
|
26
|
+
var import_camera = require("../../image-editor/core/camera.cjs");
|
|
27
|
+
var CROP_TOLERANCE = 0.1;
|
|
28
|
+
function buildModifiers(state, imageSize) {
|
|
29
|
+
const modifiers = [];
|
|
30
|
+
if (imageSize.width === 0 || imageSize.height === 0) {
|
|
31
|
+
return modifiers;
|
|
32
|
+
}
|
|
33
|
+
const { cropRect, pan, zoom, flip } = state;
|
|
34
|
+
const hasFlipH = flip.horizontal;
|
|
35
|
+
const hasFlipV = flip.vertical;
|
|
36
|
+
if (hasFlipH || hasFlipV) {
|
|
37
|
+
modifiers.push({
|
|
38
|
+
type: "flip",
|
|
39
|
+
args: { flip: { horizontal: hasFlipH, vertical: hasFlipV } }
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const rawAngle = (state.rotation % 360 + 360) % 360;
|
|
43
|
+
const singleAxisFlip = hasFlipH !== hasFlipV;
|
|
44
|
+
const signedAngle = singleAxisFlip ? (360 - rawAngle) % 360 : rawAngle;
|
|
45
|
+
if (signedAngle !== 0) {
|
|
46
|
+
modifiers.push({ type: "rotate", args: { angle: signedAngle } });
|
|
47
|
+
}
|
|
48
|
+
const snapRotation = Math.round(state.rotation / 90) * 90;
|
|
49
|
+
const { width: snapW, height: snapH } = (0, import_camera.getRotatedBBox)(
|
|
50
|
+
imageSize.width,
|
|
51
|
+
imageSize.height,
|
|
52
|
+
snapRotation
|
|
53
|
+
);
|
|
54
|
+
const { width: fullW, height: fullH } = (0, import_camera.getRotatedBBox)(
|
|
55
|
+
imageSize.width,
|
|
56
|
+
imageSize.height,
|
|
57
|
+
state.rotation
|
|
58
|
+
);
|
|
59
|
+
const imgLeft = 0.5 + pan.x - zoom / 2;
|
|
60
|
+
const imgTop = 0.5 + pan.y - zoom / 2;
|
|
61
|
+
const snapX = (cropRect.x - imgLeft) / zoom * snapW;
|
|
62
|
+
const snapY = (cropRect.y - imgTop) / zoom * snapH;
|
|
63
|
+
const widthPx = cropRect.width / zoom * snapW;
|
|
64
|
+
const heightPx = cropRect.height / zoom * snapH;
|
|
65
|
+
const offsetX = (fullW - snapW) / 2;
|
|
66
|
+
const offsetY = (fullH - snapH) / 2;
|
|
67
|
+
const fullX = snapX + offsetX;
|
|
68
|
+
const fullY = snapY + offsetY;
|
|
69
|
+
const leftPct = fullX / fullW * 100;
|
|
70
|
+
const topPct = fullY / fullH * 100;
|
|
71
|
+
const widthPct = widthPx / fullW * 100;
|
|
72
|
+
const heightPct = heightPx / fullH * 100;
|
|
73
|
+
const coversFullFrame = leftPct <= CROP_TOLERANCE && topPct <= CROP_TOLERANCE && widthPct >= 100 - CROP_TOLERANCE && heightPct >= 100 - CROP_TOLERANCE;
|
|
74
|
+
if (!coversFullFrame) {
|
|
75
|
+
modifiers.push({
|
|
76
|
+
type: "crop",
|
|
77
|
+
args: {
|
|
78
|
+
left: leftPct,
|
|
79
|
+
top: topPct,
|
|
80
|
+
width: widthPct,
|
|
81
|
+
height: heightPct
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return modifiers;
|
|
86
|
+
}
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
buildModifiers
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=build-modifiers.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/media-editor-modal/build-modifiers.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../image-editor';\nimport { getRotatedBBox } from '../../image-editor/core/camera';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant \u2014 the server applies modifiers sequentially (see\n * `WP_REST_Attachments_Controller::edit_media_item`).\n *\n * Shape/units:\n * - `flip`: booleans per axis. Applied first in this module's output.\n * - `rotate`: `angle` in degrees, clockwise-positive (matches the\n * cropper's own convention; Core negates it internally for\n * `WP_Image_Editor::rotate`, which is counterclockwise-positive).\n * - `crop`: percentages (0\u2013100) of the image's dimensions **at the\n * moment the crop is applied**. Because modifiers are applied in\n * order, after a preceding `rotate` the server's\n * `WP_Image_Editor::get_size()` reports the full post-rotate AABB,\n * so the percentages are of that AABB. Origin is top-left.\n */\nexport type Modifier =\n\t| {\n\t\t\ttype: 'flip';\n\t\t\targs: { flip: { horizontal: boolean; vertical: boolean } };\n\t }\n\t| { type: 'rotate'; args: { angle: number } }\n\t| {\n\t\t\ttype: 'crop';\n\t\t\targs: { left: number; top: number; width: number; height: number };\n\t };\n\n/**\n * Tolerance (percent) used to decide whether a crop rect is effectively\n * full-frame. Sub-pixel / float-ulp deltas below this value are treated\n * as no crop. Matches the historical threshold used by the legacy\n * `use-save-image.js` (which compared against `99.9`).\n */\nconst CROP_TOLERANCE = 0.1;\n\n/**\n * Build a Core-compatible modifiers array from the cropper state.\n *\n * Emits `[flip, rotate, crop]` in that order. Identity operations are\n * pruned \u2014 an absent flip, a rotation that normalizes to 0\u00B0, and a crop\n * rect that covers (within tolerance) the full post-rotate AABB each\n * produce no modifier. An identity state (fresh image, no edits) returns\n * an empty array; callers can use that to skip the `/edit` call.\n *\n * Frames and math:\n *\n * The cropper's `cropRect` is stored as fractions of the **snap-rotation**\n * bounding box (the stencil-reference frame \u2014 see `createCamera` /\n * `createExportCamera`). Pan is in that frame; zoom scales the image\n * beneath a fixed stencil. Two conversions are needed to reach the frame\n * Core's crop modifier applies against:\n *\n * 1. Express the stencil rect in snap-AABB **pixels**:\n * Image screen-normalized top-left with zoom/pan is\n * `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the\n * inverse of that transform applied to `cropRect`.\n *\n * 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs\n * share the source-image center, so the conversion is a pure\n * translation by `(fullCenter - snapCenter)`. Finally, express the\n * translated rect as percentages of the full AABB.\n *\n * Rotation sign: the cropper composes `flip \u00B7 R(\u03B8)` on the source (see\n * `createExportCamera` \u2014 rotate then flip). Core's `[flip, rotate]`\n * applies the opposite order: `R(\u03B8') \u00B7 flip`. For both to land on the\n * same pixels we invert the rotation sign when exactly one flip axis\n * is set (`flip_h \u00B7 R(\u03B8) = R(-\u03B8) \u00B7 flip_h`). Both-or-neither flips\n * leave the sign alone because `flip_h \u00B7 flip_v = -I` commutes with\n * rotation.\n *\n * @param state Current cropper state.\n * @param imageSize Natural dimensions of the source image.\n * @return Ordered modifier array; empty when nothing is server-relevant.\n */\nexport function buildModifiers(\n\tstate: CropperState,\n\timageSize: Size\n): Modifier[] {\n\tconst modifiers: Modifier[] = [];\n\n\tif ( imageSize.width === 0 || imageSize.height === 0 ) {\n\t\treturn modifiers;\n\t}\n\n\tconst { cropRect, pan, zoom, flip } = state;\n\tconst hasFlipH = flip.horizontal;\n\tconst hasFlipV = flip.vertical;\n\n\tif ( hasFlipH || hasFlipV ) {\n\t\tmodifiers.push( {\n\t\t\ttype: 'flip',\n\t\t\targs: { flip: { horizontal: hasFlipH, vertical: hasFlipV } },\n\t\t} );\n\t}\n\n\tconst rawAngle = ( ( state.rotation % 360 ) + 360 ) % 360;\n\t// Invert the sign for single-axis flips so Core's `flip \u2192 rotate`\n\t// pipeline matches the cropper's `rotate \u2192 flip` composition.\n\tconst singleAxisFlip = hasFlipH !== hasFlipV;\n\tconst signedAngle = singleAxisFlip ? ( 360 - rawAngle ) % 360 : rawAngle;\n\tif ( signedAngle !== 0 ) {\n\t\tmodifiers.push( { type: 'rotate', args: { angle: signedAngle } } );\n\t}\n\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst { width: snapW, height: snapH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\tconst { width: fullW, height: fullH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tstate.rotation\n\t);\n\n\t// Stencil rect in snap-AABB pixels. Inverts `createExportCamera`'s\n\t// pan/zoom composition to recover the pixel rectangle the stencil\n\t// framed in that frame.\n\tconst imgLeft = 0.5 + pan.x - zoom / 2;\n\tconst imgTop = 0.5 + pan.y - zoom / 2;\n\tconst snapX = ( ( cropRect.x - imgLeft ) / zoom ) * snapW;\n\tconst snapY = ( ( cropRect.y - imgTop ) / zoom ) * snapH;\n\tconst widthPx = ( cropRect.width / zoom ) * snapW;\n\tconst heightPx = ( cropRect.height / zoom ) * snapH;\n\n\t// Translate to the full AABB (both centered on source).\n\tconst offsetX = ( fullW - snapW ) / 2;\n\tconst offsetY = ( fullH - snapH ) / 2;\n\tconst fullX = snapX + offsetX;\n\tconst fullY = snapY + offsetY;\n\n\t// Percentages of the full AABB \u2014 Core's crop frame after rotate.\n\tconst leftPct = ( fullX / fullW ) * 100;\n\tconst topPct = ( fullY / fullH ) * 100;\n\tconst widthPct = ( widthPx / fullW ) * 100;\n\tconst heightPct = ( heightPx / fullH ) * 100;\n\n\tconst coversFullFrame =\n\t\tleftPct <= CROP_TOLERANCE &&\n\t\ttopPct <= CROP_TOLERANCE &&\n\t\twidthPct >= 100 - CROP_TOLERANCE &&\n\t\theightPct >= 100 - CROP_TOLERANCE;\n\n\tif ( ! coversFullFrame ) {\n\t\tmodifiers.push( {\n\t\t\ttype: 'crop',\n\t\t\targs: {\n\t\t\t\tleft: leftPct,\n\t\t\t\ttop: topPct,\n\t\t\t\twidth: widthPct,\n\t\t\t\theight: heightPct,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn modifiers;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA+B;AAmC/B,IAAM,iBAAiB;AAyChB,SAAS,eACf,OACA,WACa;AACb,QAAM,YAAwB,CAAC;AAE/B,MAAK,UAAU,UAAU,KAAK,UAAU,WAAW,GAAI;AACtD,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,UAAU,KAAK,MAAM,KAAK,IAAI;AACtC,QAAM,WAAW,KAAK;AACtB,QAAM,WAAW,KAAK;AAEtB,MAAK,YAAY,UAAW;AAC3B,cAAU,KAAM;AAAA,MACf,MAAM;AAAA,MACN,MAAM,EAAE,MAAM,EAAE,YAAY,UAAU,UAAU,SAAS,EAAE;AAAA,IAC5D,CAAE;AAAA,EACH;AAEA,QAAM,YAAe,MAAM,WAAW,MAAQ,OAAQ;AAGtD,QAAM,iBAAiB,aAAa;AACpC,QAAM,cAAc,kBAAmB,MAAM,YAAa,MAAM;AAChE,MAAK,gBAAgB,GAAI;AACxB,cAAU,KAAM,EAAE,MAAM,UAAU,MAAM,EAAE,OAAO,YAAY,EAAE,CAAE;AAAA,EAClE;AAEA,QAAM,eAAe,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;AACzD,QAAM,EAAE,OAAO,OAAO,QAAQ,MAAM,QAAI;AAAA,IACvC,UAAU;AAAA,IACV,UAAU;AAAA,IACV;AAAA,EACD;AACA,QAAM,EAAE,OAAO,OAAO,QAAQ,MAAM,QAAI;AAAA,IACvC,UAAU;AAAA,IACV,UAAU;AAAA,IACV,MAAM;AAAA,EACP;AAKA,QAAM,UAAU,MAAM,IAAI,IAAI,OAAO;AACrC,QAAM,SAAS,MAAM,IAAI,IAAI,OAAO;AACpC,QAAM,SAAY,SAAS,IAAI,WAAY,OAAS;AACpD,QAAM,SAAY,SAAS,IAAI,UAAW,OAAS;AACnD,QAAM,UAAY,SAAS,QAAQ,OAAS;AAC5C,QAAM,WAAa,SAAS,SAAS,OAAS;AAG9C,QAAM,WAAY,QAAQ,SAAU;AACpC,QAAM,WAAY,QAAQ,SAAU;AACpC,QAAM,QAAQ,QAAQ;AACtB,QAAM,QAAQ,QAAQ;AAGtB,QAAM,UAAY,QAAQ,QAAU;AACpC,QAAM,SAAW,QAAQ,QAAU;AACnC,QAAM,WAAa,UAAU,QAAU;AACvC,QAAM,YAAc,WAAW,QAAU;AAEzC,QAAM,kBACL,WAAW,kBACX,UAAU,kBACV,YAAY,MAAM,kBAClB,aAAa,MAAM;AAEpB,MAAK,CAAE,iBAAkB;AACxB,cAAU,KAAM;AAAA,MACf,MAAM;AAAA,MACN,MAAM;AAAA,QACL,MAAM;AAAA,QACN,KAAK;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,MACT;AAAA,IACD,CAAE;AAAA,EACH;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|