@wordpress/media-editor 0.7.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/components/media-preview/index.cjs +1 -1
- package/build/components/media-preview/index.cjs.map +2 -2
- 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/components/media-preview/index.mjs +1 -1
- package/build-module/components/media-preview/index.mjs.map +2 -2
- 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/components/media-preview/index.d.ts.map +1 -1
- 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 -8
- 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/components/media-preview/index.tsx +2 -1
- 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,139 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/colors" as *;
|
|
2
|
+
@use "@wordpress/base-styles/mixins" as *;
|
|
3
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
4
|
+
@use "@wordpress/base-styles/z-index" as *;
|
|
5
|
+
|
|
6
|
+
// `className` on `<Modal>` is applied to `.components-modal__frame`, so the
|
|
7
|
+
// compound selector below bumps specificity over the shipped rule at
|
|
8
|
+
// `.components-modal__frame.is-full-screen :where(.components-modal__content)`
|
|
9
|
+
// and lets the InterfaceSkeleton run edge-to-edge inside the modal.
|
|
10
|
+
.media-editor-modal.components-modal__frame .components-modal__content {
|
|
11
|
+
padding: 0;
|
|
12
|
+
margin-bottom: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.media-editor-modal {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
|
|
19
|
+
// Center the loading spinner in the modal body while media data is
|
|
20
|
+
// resolving, before the InterfaceSkeleton mounts. The wrapper sits
|
|
21
|
+
// inside `.components-modal__children-container`, which isn't a flex
|
|
22
|
+
// container — `height: 100%` (rather than `flex: 1`) makes it fill
|
|
23
|
+
// the body so the inner flex can center the spinner.
|
|
24
|
+
.media-editor-modal__loading {
|
|
25
|
+
height: 100%;
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// InterfaceSkeleton defaults to position: fixed for full-viewport usage.
|
|
32
|
+
// Reset it so the skeleton flows inside the modal's content area. Stack
|
|
33
|
+
// children vertically (header/body/footer) since the default row layout
|
|
34
|
+
// assumes an absolutely positioned footer that overlays the bottom.
|
|
35
|
+
.interface-interface-skeleton {
|
|
36
|
+
position: relative;
|
|
37
|
+
top: auto;
|
|
38
|
+
right: auto;
|
|
39
|
+
bottom: auto;
|
|
40
|
+
left: auto;
|
|
41
|
+
height: 100%;
|
|
42
|
+
max-height: none;
|
|
43
|
+
flex: 1;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.interface-interface-skeleton__editor {
|
|
48
|
+
min-width: 0;
|
|
49
|
+
flex: 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// The skeleton's default footer is `position: absolute; bottom: 0` with
|
|
53
|
+
// a small fixed padding-bottom on the body to compensate. Our bottom
|
|
54
|
+
// bar is taller than that default, so it would overlap the cropper's
|
|
55
|
+
// resize handles. Put the footer in flow so it claims its own row and
|
|
56
|
+
// the canvas (and sidebar) resize to fit above it. The skeleton also
|
|
57
|
+
// hides the footer below the medium breakpoint by default; force it
|
|
58
|
+
// visible so the bottom-bar controls remain accessible on narrow
|
|
59
|
+
// viewports.
|
|
60
|
+
.interface-interface-skeleton__footer {
|
|
61
|
+
position: relative;
|
|
62
|
+
display: flex;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.interface-interface-skeleton.has-footer .interface-interface-skeleton__body {
|
|
66
|
+
padding-bottom: 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.media-editor-modal__canvas {
|
|
70
|
+
display: flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
background: $gray-100;
|
|
74
|
+
overflow: auto;
|
|
75
|
+
height: 100%;
|
|
76
|
+
|
|
77
|
+
// MediaPreview uses `min-height: 100%` so it can grow when needed in
|
|
78
|
+
// other contexts. Inside the modal canvas we need a definite height
|
|
79
|
+
// so the image/video's `max-height: 100%` resolves and the preview
|
|
80
|
+
// is contained vertically.
|
|
81
|
+
.media-editor-preview {
|
|
82
|
+
height: 100%;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
img,
|
|
86
|
+
video {
|
|
87
|
+
max-width: 100%;
|
|
88
|
+
max-height: 100%;
|
|
89
|
+
object-fit: contain;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Matches the post editor's `.editor-sidebar` container (see
|
|
94
|
+
// `packages/editor/src/components/sidebar/style.scss`): `@include reset`
|
|
95
|
+
// sets `box-sizing: border-box` and makes all descendants inherit it.
|
|
96
|
+
// Without this, descendants (notably the active-tab underline inside
|
|
97
|
+
// `<Tabs>`) fall back to `content-box` sizing that shortens the
|
|
98
|
+
// indicator under the selected tab label.
|
|
99
|
+
.media-editor-modal__sidebar {
|
|
100
|
+
@include reset;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Mirror the editor's `PostPanelSection` padding for tab body content,
|
|
104
|
+
// so the form inside the Details tab has breathing room.
|
|
105
|
+
.media-editor-modal__panel {
|
|
106
|
+
padding: $grid-unit-20;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Match the post editor's sidebar header treatment
|
|
110
|
+
// (see `packages/editor/src/components/sidebar/style.scss`): when the tab
|
|
111
|
+
// list is rendered as `ComplementaryArea`'s header, zero the default
|
|
112
|
+
// panel-header padding so tabs sit flush to the edge and the active-tab
|
|
113
|
+
// underline can span the full tab label width.
|
|
114
|
+
.components-panel__header.media-editor-modal__sidebar-header {
|
|
115
|
+
padding-left: 0;
|
|
116
|
+
padding-right: $grid-unit-10;
|
|
117
|
+
|
|
118
|
+
.components-button.has-icon {
|
|
119
|
+
padding: 0;
|
|
120
|
+
|
|
121
|
+
@include break-medium() {
|
|
122
|
+
display: flex;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// `<SnackbarNotices>` renders `.components-snackbar-list` with
|
|
129
|
+
// `position: absolute; width: 100%`. Portaled to `<body>` it has no
|
|
130
|
+
// positioned ancestor, so it collapses to a 0-size box at the document
|
|
131
|
+
// origin and would also be painted under the modal overlay since both
|
|
132
|
+
// share the default snackbar z-index. `snackbar-container` fixes the
|
|
133
|
+
// list to the viewport bottom; the elevated z-index (registered in
|
|
134
|
+
// base-styles) lifts it above the modal overlay and any popovers that
|
|
135
|
+
// may open inside the modal.
|
|
136
|
+
.media-editor-modal__snackbar {
|
|
137
|
+
@include snackbar-container();
|
|
138
|
+
z-index: z-index(".components-snackbar-list.media-editor-modal__snackbar");
|
|
139
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* buildModifiers ↔ Export-camera parity.
|
|
3
|
+
*
|
|
4
|
+
* WHAT THIS TEST GUARANTEES
|
|
5
|
+
*
|
|
6
|
+
* "What the user framed in the stencil is what the server crops from the
|
|
7
|
+
* source." The cropper shows the user a live preview via the *export
|
|
8
|
+
* camera* (`createExportCamera`); the server receives a `modifiers` array
|
|
9
|
+
* from `buildModifiers` and applies them sequentially in the order
|
|
10
|
+
* `[flip, rotate, crop]` (Core's `WP_REST_Attachments_Controller
|
|
11
|
+
* ::edit_media_item`). Both paths must land on the same source pixel for
|
|
12
|
+
* the same spot in the output, otherwise the saved image drifts from
|
|
13
|
+
* what the user framed.
|
|
14
|
+
*
|
|
15
|
+
* This test asserts that invariant holds for every combination of
|
|
16
|
+
* rotation, zoom, pan, flip, and crop rect the cropper can produce.
|
|
17
|
+
*
|
|
18
|
+
* STRATEGY
|
|
19
|
+
*
|
|
20
|
+
* For each cropper state and each probe point (u, v) ∈ [0, 1]² inside
|
|
21
|
+
* the cropped output:
|
|
22
|
+
*
|
|
23
|
+
* 1. `exportSourcePixel` — inverts the export-camera matrix to find
|
|
24
|
+
* the source pixel the cropper draws at (u, v). Ground truth:
|
|
25
|
+
* it's literally what the user sees on screen.
|
|
26
|
+
* 2. `serverSourcePixel` — simulates the Core pipeline
|
|
27
|
+
* (`flip → rotate → crop`) in reverse to find the source pixel the
|
|
28
|
+
* server would place at (u, v).
|
|
29
|
+
* 3. Assert both answers agree to within 1 source pixel (float slop).
|
|
30
|
+
*
|
|
31
|
+
* A wrong crop rect, frame, or rotation sign makes the two paths
|
|
32
|
+
* diverge and pinpoints the offending (state, probe) pair.
|
|
33
|
+
*
|
|
34
|
+
* ORDER / SIGN NOTES
|
|
35
|
+
*
|
|
36
|
+
* The cropper's export camera composes the source-to-screen chain as
|
|
37
|
+
* `flip · R(θ)` on the (centered) source — rotate first, then flip.
|
|
38
|
+
* Core's `modifiers` pipeline applies `flip` first, then `R(θ')`. For
|
|
39
|
+
* these two chains to land on the same pixel, when exactly one flip
|
|
40
|
+
* axis is set we must send `θ' = -θ` (since `flip_h · R(θ) = R(-θ) ·
|
|
41
|
+
* flip_h`). Both-or-neither flips leave `θ' = θ` because `flip_h · flip_v
|
|
42
|
+
* = -I` commutes with rotation.
|
|
43
|
+
*
|
|
44
|
+
* MAINTENANCE NOTES
|
|
45
|
+
*
|
|
46
|
+
* - If you change `buildModifiers`, this test is the primary safety net.
|
|
47
|
+
* Run it after any edit to that file or to `createExportCamera`.
|
|
48
|
+
* - If Core's pipeline operation order ever changes, update
|
|
49
|
+
* `serverSourcePixel` to match — it mirrors the server exactly.
|
|
50
|
+
* - Adding a new cropper operation (e.g. skew) means: extend
|
|
51
|
+
* `CropperState`, teach `buildModifiers` to emit it, extend
|
|
52
|
+
* `serverSourcePixel` to undo it, and add values to the grid in
|
|
53
|
+
* `buildRows`. The probes don't need to change.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* External dependencies
|
|
58
|
+
*/
|
|
59
|
+
import { mat2d, vec2 } from 'gl-matrix';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Internal dependencies
|
|
63
|
+
*/
|
|
64
|
+
import { buildModifiers } from '../build-modifiers';
|
|
65
|
+
import type { Modifier } from '../build-modifiers';
|
|
66
|
+
import {
|
|
67
|
+
createExportCamera,
|
|
68
|
+
getRotatedBBox,
|
|
69
|
+
} from '../../../image-editor/core/camera';
|
|
70
|
+
import { DEFAULT_STATE } from '../../../image-editor/core/constants';
|
|
71
|
+
import type { CropperState, Size } from '../../../image-editor/core/types';
|
|
72
|
+
|
|
73
|
+
const IMAGE: Size = { width: 1600, height: 900 };
|
|
74
|
+
|
|
75
|
+
function makeState( overrides: Partial< CropperState > = {} ): CropperState {
|
|
76
|
+
return {
|
|
77
|
+
...DEFAULT_STATE,
|
|
78
|
+
image: {
|
|
79
|
+
src: 'test.jpg',
|
|
80
|
+
naturalWidth: IMAGE.width,
|
|
81
|
+
naturalHeight: IMAGE.height,
|
|
82
|
+
},
|
|
83
|
+
...overrides,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Source pixel the cropper draws at output position (u, v). Inverts the
|
|
89
|
+
* export-camera matrix — the same one the preview uses — so whatever the
|
|
90
|
+
* user sees on-screen is exactly what this returns.
|
|
91
|
+
*
|
|
92
|
+
* @param state Cropper state (rotation/zoom/pan/flip/cropRect).
|
|
93
|
+
* @param imageSize Natural dimensions of the source image.
|
|
94
|
+
* @param outputSize Output canvas dimensions the camera renders into.
|
|
95
|
+
* @param u Horizontal probe in [0, 1] across the output.
|
|
96
|
+
* @param v Vertical probe in [0, 1] across the output.
|
|
97
|
+
*/
|
|
98
|
+
function exportSourcePixel(
|
|
99
|
+
state: CropperState,
|
|
100
|
+
imageSize: Size,
|
|
101
|
+
outputSize: Size,
|
|
102
|
+
u: number,
|
|
103
|
+
v: number
|
|
104
|
+
): { x: number; y: number } {
|
|
105
|
+
const camera = createExportCamera( state, imageSize, outputSize );
|
|
106
|
+
const inv = mat2d.create();
|
|
107
|
+
mat2d.invert( inv, camera );
|
|
108
|
+
const out = vec2.create();
|
|
109
|
+
vec2.transformMat2d(
|
|
110
|
+
out,
|
|
111
|
+
[ u * outputSize.width, v * outputSize.height ],
|
|
112
|
+
inv
|
|
113
|
+
);
|
|
114
|
+
return { x: out[ 0 ], y: out[ 1 ] };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Extract the pieces of the server pipeline we need to simulate from a
|
|
119
|
+
* modifier array. `flip` and `rotate` may be absent (identity-pruned),
|
|
120
|
+
* `crop` may also be absent when the full-frame is framed; in that case
|
|
121
|
+
* the output canvas equals the full rotated AABB.
|
|
122
|
+
*
|
|
123
|
+
* @param modifiers Ordered modifier array as emitted by `buildModifiers`.
|
|
124
|
+
*/
|
|
125
|
+
function readModifiers( modifiers: Modifier[] ): {
|
|
126
|
+
flip: { horizontal: boolean; vertical: boolean };
|
|
127
|
+
rotation: number;
|
|
128
|
+
crop: { left: number; top: number; width: number; height: number } | null;
|
|
129
|
+
} {
|
|
130
|
+
const flip = { horizontal: false, vertical: false };
|
|
131
|
+
let rotation = 0;
|
|
132
|
+
let crop: {
|
|
133
|
+
left: number;
|
|
134
|
+
top: number;
|
|
135
|
+
width: number;
|
|
136
|
+
height: number;
|
|
137
|
+
} | null = null;
|
|
138
|
+
|
|
139
|
+
for ( const m of modifiers ) {
|
|
140
|
+
if ( m.type === 'flip' ) {
|
|
141
|
+
flip.horizontal = m.args.flip.horizontal;
|
|
142
|
+
flip.vertical = m.args.flip.vertical;
|
|
143
|
+
} else if ( m.type === 'rotate' ) {
|
|
144
|
+
rotation = m.args.angle;
|
|
145
|
+
} else if ( m.type === 'crop' ) {
|
|
146
|
+
crop = {
|
|
147
|
+
left: m.args.left,
|
|
148
|
+
top: m.args.top,
|
|
149
|
+
width: m.args.width,
|
|
150
|
+
height: m.args.height,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { flip, rotation, crop };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Source pixel the server lands on for output point (u, v). Simulates
|
|
160
|
+
* Core's `[flip, rotate, crop]` pipeline in reverse:
|
|
161
|
+
* 1. Output point o = (u · outW, v · outH).
|
|
162
|
+
* 2. Canvas point c = o + (cropX, cropY) in the post-rotate full AABB.
|
|
163
|
+
* 3. Undo rotation about the source center to reach the flipped frame.
|
|
164
|
+
* 4. Undo flip about the source center.
|
|
165
|
+
*
|
|
166
|
+
* @param modifiers Ordered modifier array the client sends.
|
|
167
|
+
* @param imageSize Natural dimensions of the source image.
|
|
168
|
+
* @param u Horizontal probe in [0, 1] across the output.
|
|
169
|
+
* @param v Vertical probe in [0, 1] across the output.
|
|
170
|
+
*/
|
|
171
|
+
function serverSourcePixel(
|
|
172
|
+
modifiers: Modifier[],
|
|
173
|
+
imageSize: Size,
|
|
174
|
+
u: number,
|
|
175
|
+
v: number
|
|
176
|
+
): { x: number; y: number } {
|
|
177
|
+
const { flip, rotation, crop } = readModifiers( modifiers );
|
|
178
|
+
|
|
179
|
+
const fullBBox = getRotatedBBox(
|
|
180
|
+
imageSize.width,
|
|
181
|
+
imageSize.height,
|
|
182
|
+
rotation
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// Percent → pixels in the full-AABB frame. When crop is absent the
|
|
186
|
+
// output canvas is the full AABB itself.
|
|
187
|
+
const cropW = crop ? ( crop.width * fullBBox.width ) / 100 : fullBBox.width;
|
|
188
|
+
const cropH = crop
|
|
189
|
+
? ( crop.height * fullBBox.height ) / 100
|
|
190
|
+
: fullBBox.height;
|
|
191
|
+
const cropX = crop ? ( crop.left * fullBBox.width ) / 100 : 0;
|
|
192
|
+
const cropY = crop ? ( crop.top * fullBBox.height ) / 100 : 0;
|
|
193
|
+
|
|
194
|
+
// Undo crop translation.
|
|
195
|
+
const cx = u * cropW + cropX;
|
|
196
|
+
const cy = v * cropH + cropY;
|
|
197
|
+
|
|
198
|
+
// Undo rotation about source center. Core applies rotation to the
|
|
199
|
+
// flipped source, so inverting rotation brings us back to the flipped
|
|
200
|
+
// frame (source center at full-AABB center).
|
|
201
|
+
const rad = ( rotation * Math.PI ) / 180;
|
|
202
|
+
const cos = Math.cos( rad );
|
|
203
|
+
const sin = Math.sin( rad );
|
|
204
|
+
const dx = cx - fullBBox.width / 2;
|
|
205
|
+
const dy = cy - fullBBox.height / 2;
|
|
206
|
+
// gl-matrix mat2d.rotate: (x, y) → (x·cos - y·sin, x·sin + y·cos).
|
|
207
|
+
// Inverse is the transpose: (x, y) → (x·cos + y·sin, -x·sin + y·cos).
|
|
208
|
+
let fx = dx * cos + dy * sin + imageSize.width / 2;
|
|
209
|
+
let fy = -dx * sin + dy * cos + imageSize.height / 2;
|
|
210
|
+
|
|
211
|
+
// Undo flip about source center (flip is its own inverse).
|
|
212
|
+
if ( flip.horizontal ) {
|
|
213
|
+
fx = imageSize.width - fx;
|
|
214
|
+
}
|
|
215
|
+
if ( flip.vertical ) {
|
|
216
|
+
fy = imageSize.height - fy;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return { x: fx, y: fy };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Seven probe points — corners catch offset/scale drift, center catches
|
|
223
|
+
// uniform bugs, two asymmetric interior points catch cross-axis bugs
|
|
224
|
+
// that a center probe would miss.
|
|
225
|
+
const PROBES: { label: string; u: number; v: number }[] = [
|
|
226
|
+
{ label: 'top-left', u: 0, v: 0 },
|
|
227
|
+
{ label: 'top-right', u: 1, v: 0 },
|
|
228
|
+
{ label: 'bottom-right', u: 1, v: 1 },
|
|
229
|
+
{ label: 'bottom-left', u: 0, v: 1 },
|
|
230
|
+
{ label: 'center', u: 0.5, v: 0.5 },
|
|
231
|
+
{ label: 'interior-1', u: 0.3, v: 0.7 },
|
|
232
|
+
{ label: 'interior-2', u: 0.8, v: 0.25 },
|
|
233
|
+
];
|
|
234
|
+
|
|
235
|
+
interface ParityRow {
|
|
236
|
+
label: string;
|
|
237
|
+
state: CropperState;
|
|
238
|
+
probeLabel: string;
|
|
239
|
+
u: number;
|
|
240
|
+
v: number;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function buildRows(): ParityRow[] {
|
|
244
|
+
const rotations = [ 0, 15, 45, 60, 90, 135, 201, 270 ];
|
|
245
|
+
const zooms = [ 1, 1.5, 2.5 ];
|
|
246
|
+
const pans = [
|
|
247
|
+
{ x: 0, y: 0 },
|
|
248
|
+
{ x: 0.08, y: -0.05 },
|
|
249
|
+
{ x: -0.1, y: 0.12 },
|
|
250
|
+
];
|
|
251
|
+
const flips = [
|
|
252
|
+
{ horizontal: false, vertical: false },
|
|
253
|
+
{ horizontal: true, vertical: false },
|
|
254
|
+
{ horizontal: false, vertical: true },
|
|
255
|
+
{ horizontal: true, vertical: true },
|
|
256
|
+
];
|
|
257
|
+
const cropRects = [
|
|
258
|
+
{ label: 'full', rect: { x: 0, y: 0, width: 1, height: 1 } },
|
|
259
|
+
{
|
|
260
|
+
label: 'centered',
|
|
261
|
+
rect: { x: 0.25, y: 0.25, width: 0.5, height: 0.5 },
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
label: 'off-center',
|
|
265
|
+
rect: { x: 0.1, y: 0.2, width: 0.45, height: 0.55 },
|
|
266
|
+
},
|
|
267
|
+
];
|
|
268
|
+
|
|
269
|
+
const rows: ParityRow[] = [];
|
|
270
|
+
for ( const rotation of rotations ) {
|
|
271
|
+
for ( const zoom of zooms ) {
|
|
272
|
+
for ( const pan of pans ) {
|
|
273
|
+
for ( const flip of flips ) {
|
|
274
|
+
for ( const { label: cropLabel, rect } of cropRects ) {
|
|
275
|
+
const flipLabel = `${ flip.horizontal ? 'H' : '-' }${
|
|
276
|
+
flip.vertical ? 'V' : '-'
|
|
277
|
+
}`;
|
|
278
|
+
const stateLabel = `rot=${ rotation } zoom=${ zoom } pan=(${ pan.x },${ pan.y }) flip=${ flipLabel } crop=${ cropLabel }`;
|
|
279
|
+
const state = makeState( {
|
|
280
|
+
rotation,
|
|
281
|
+
zoom,
|
|
282
|
+
pan,
|
|
283
|
+
flip,
|
|
284
|
+
cropRect: rect,
|
|
285
|
+
} );
|
|
286
|
+
for ( const { label: probeLabel, u, v } of PROBES ) {
|
|
287
|
+
rows.push( {
|
|
288
|
+
label: `${ stateLabel } probe=${ probeLabel }`,
|
|
289
|
+
state,
|
|
290
|
+
probeLabel,
|
|
291
|
+
u,
|
|
292
|
+
v,
|
|
293
|
+
} );
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return rows;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Output size the server would produce, computed from the modifier list.
|
|
305
|
+
* With a crop: the crop's pixel dims in the full-AABB frame. Without a
|
|
306
|
+
* crop: the full rotated AABB.
|
|
307
|
+
*
|
|
308
|
+
* @param modifiers Modifier array the server will apply.
|
|
309
|
+
* @param imageSize Natural dimensions of the source image.
|
|
310
|
+
*/
|
|
311
|
+
function outputSizeFor( modifiers: Modifier[], imageSize: Size ): Size {
|
|
312
|
+
const { rotation, crop } = readModifiers( modifiers );
|
|
313
|
+
const full = getRotatedBBox( imageSize.width, imageSize.height, rotation );
|
|
314
|
+
if ( ! crop ) {
|
|
315
|
+
return { width: full.width, height: full.height };
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
width: ( crop.width * full.width ) / 100,
|
|
319
|
+
height: ( crop.height * full.height ) / 100,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
describe( 'buildModifiers ↔ Export-camera parity', () => {
|
|
324
|
+
const rows = buildRows();
|
|
325
|
+
|
|
326
|
+
it.each( rows )( '$label', ( { state, u, v } ) => {
|
|
327
|
+
const modifiers = buildModifiers( state, IMAGE );
|
|
328
|
+
|
|
329
|
+
// Output canvas is whatever the server would emit: the crop rect
|
|
330
|
+
// if present, otherwise the full rotated AABB. This makes (u, v)
|
|
331
|
+
// map to the same *output* pixel on both paths.
|
|
332
|
+
const outputSize = outputSizeFor( modifiers, IMAGE );
|
|
333
|
+
|
|
334
|
+
const exported = exportSourcePixel( state, IMAGE, outputSize, u, v );
|
|
335
|
+
const server = serverSourcePixel( modifiers, IMAGE, u, v );
|
|
336
|
+
|
|
337
|
+
// Tolerance of 1 source pixel. The two paths compose rotations
|
|
338
|
+
// and scales in different orders, so sub-pixel disagreement is
|
|
339
|
+
// expected from floating-point. Anything larger is a real bug.
|
|
340
|
+
expect( server.x ).toBeCloseTo( exported.x, 0 );
|
|
341
|
+
expect( server.y ).toBeCloseTo( exported.y, 0 );
|
|
342
|
+
} );
|
|
343
|
+
} );
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Button, RangeControl } from '@wordpress/components';
|
|
5
|
+
import { Stack } from '@wordpress/ui';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import {
|
|
8
|
+
rotateLeft,
|
|
9
|
+
rotateRight,
|
|
10
|
+
flipHorizontal,
|
|
11
|
+
flipVertical,
|
|
12
|
+
} from '@wordpress/icons';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import { useCropper } from '../../image-editor';
|
|
18
|
+
import { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';
|
|
19
|
+
|
|
20
|
+
export interface MediaEditorToolbarProps {
|
|
21
|
+
/**
|
|
22
|
+
* Extra work to run when the user clicks Reset — e.g. clearing
|
|
23
|
+
* aspect-ratio / freeform state that lives outside the cropper
|
|
24
|
+
* controller.
|
|
25
|
+
*/
|
|
26
|
+
onReset?: () => void;
|
|
27
|
+
/** Signal that a placement-oriented control is being adjusted. */
|
|
28
|
+
onPlacementControlInteraction?: () => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Toolbar for the media editor modal. Hosts the tactile cropper verbs —
|
|
33
|
+
* rotate, flip, fine rotation, reset — so they stay within thumb reach
|
|
34
|
+
* when the toolbar sits at the bottom of the modal. Aspect-ratio presets
|
|
35
|
+
* and freeform toggle live in the Crop sidebar tab instead.
|
|
36
|
+
* @param props
|
|
37
|
+
* @param props.onReset
|
|
38
|
+
* @param props.onPlacementControlInteraction
|
|
39
|
+
*/
|
|
40
|
+
export default function MediaEditorToolbar( {
|
|
41
|
+
onReset,
|
|
42
|
+
onPlacementControlInteraction,
|
|
43
|
+
}: MediaEditorToolbarProps ) {
|
|
44
|
+
const { state, setRotation, setFlip, snapRotate90, reset, isDirty } =
|
|
45
|
+
useCropper();
|
|
46
|
+
|
|
47
|
+
const handleReset = () => {
|
|
48
|
+
reset();
|
|
49
|
+
onReset?.();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// `setRotation` is an absolute-angle setter. When a single flip is active
|
|
53
|
+
// the visual direction inverts, so slider input must flip sign to match
|
|
54
|
+
// what the user sees. `snapRotate90` already handles this internally.
|
|
55
|
+
const baseAngle = Math.round( state.rotation / 90 ) * 90;
|
|
56
|
+
const singleFlip = state.flip.horizontal !== state.flip.vertical;
|
|
57
|
+
const visualDir = singleFlip ? -1 : 1;
|
|
58
|
+
const fineOffset = ( state.rotation - baseAngle ) * visualDir;
|
|
59
|
+
|
|
60
|
+
const handleRotationSlider = ( value: number | undefined ) => {
|
|
61
|
+
if ( value === undefined ) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a
|
|
65
|
+
// 90° midpoint and flips the derived baseAngle on the next render,
|
|
66
|
+
// causing subsequent events to spiral.
|
|
67
|
+
const EPS = 0.01;
|
|
68
|
+
const clamped = Math.max(
|
|
69
|
+
-MAX_ROTATION_OFFSET + EPS,
|
|
70
|
+
Math.min( MAX_ROTATION_OFFSET - EPS, value )
|
|
71
|
+
);
|
|
72
|
+
onPlacementControlInteraction?.();
|
|
73
|
+
setRotation( baseAngle + clamped * visualDir );
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Stack
|
|
78
|
+
className="media-editor-toolbar"
|
|
79
|
+
direction="row"
|
|
80
|
+
align="center"
|
|
81
|
+
justify="center"
|
|
82
|
+
gap="sm"
|
|
83
|
+
wrap="wrap"
|
|
84
|
+
>
|
|
85
|
+
<Button
|
|
86
|
+
size="compact"
|
|
87
|
+
icon={ rotateLeft }
|
|
88
|
+
label={ __( 'Rotate 90° counter-clockwise' ) }
|
|
89
|
+
showTooltip
|
|
90
|
+
onClick={ () => snapRotate90( -1 ) }
|
|
91
|
+
/>
|
|
92
|
+
<Button
|
|
93
|
+
size="compact"
|
|
94
|
+
icon={ rotateRight }
|
|
95
|
+
label={ __( 'Rotate 90° clockwise' ) }
|
|
96
|
+
showTooltip
|
|
97
|
+
onClick={ () => snapRotate90( 1 ) }
|
|
98
|
+
/>
|
|
99
|
+
<Button
|
|
100
|
+
size="compact"
|
|
101
|
+
icon={ flipHorizontal }
|
|
102
|
+
label={ __( 'Flip horizontal' ) }
|
|
103
|
+
showTooltip
|
|
104
|
+
isPressed={ state.flip.horizontal }
|
|
105
|
+
onClick={ () =>
|
|
106
|
+
setFlip( {
|
|
107
|
+
horizontal: ! state.flip.horizontal,
|
|
108
|
+
vertical: state.flip.vertical,
|
|
109
|
+
} )
|
|
110
|
+
}
|
|
111
|
+
/>
|
|
112
|
+
<Button
|
|
113
|
+
size="compact"
|
|
114
|
+
icon={ flipVertical }
|
|
115
|
+
label={ __( 'Flip vertical' ) }
|
|
116
|
+
showTooltip
|
|
117
|
+
isPressed={ state.flip.vertical }
|
|
118
|
+
onClick={ () =>
|
|
119
|
+
setFlip( {
|
|
120
|
+
horizontal: state.flip.horizontal,
|
|
121
|
+
vertical: ! state.flip.vertical,
|
|
122
|
+
} )
|
|
123
|
+
}
|
|
124
|
+
/>
|
|
125
|
+
<div className="media-editor-toolbar__rotation-slider">
|
|
126
|
+
<RangeControl
|
|
127
|
+
__next40pxDefaultSize
|
|
128
|
+
__nextHasNoMarginBottom
|
|
129
|
+
label={ __( 'Fine rotation' ) }
|
|
130
|
+
hideLabelFromVision
|
|
131
|
+
min={ -MAX_ROTATION_OFFSET }
|
|
132
|
+
max={ MAX_ROTATION_OFFSET }
|
|
133
|
+
step={ 0.5 }
|
|
134
|
+
value={ fineOffset }
|
|
135
|
+
onChange={ handleRotationSlider }
|
|
136
|
+
showTooltip={ false }
|
|
137
|
+
/>
|
|
138
|
+
</div>
|
|
139
|
+
<Button
|
|
140
|
+
size="compact"
|
|
141
|
+
variant="tertiary"
|
|
142
|
+
disabled={ ! isDirty }
|
|
143
|
+
accessibleWhenDisabled
|
|
144
|
+
onClick={ handleReset }
|
|
145
|
+
>
|
|
146
|
+
{ __( 'Reset' ) }
|
|
147
|
+
</Button>
|
|
148
|
+
</Stack>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
2
|
+
@use "@wordpress/base-styles/breakpoints" as *;
|
|
3
|
+
|
|
4
|
+
.media-editor-toolbar {
|
|
5
|
+
width: 100%;
|
|
6
|
+
padding: $grid-unit-10 $grid-unit-20;
|
|
7
|
+
|
|
8
|
+
// Let the rotation slider absorb extra horizontal space (so it grows
|
|
9
|
+
// between the icon buttons and Reset) while capping its width so it
|
|
10
|
+
// doesn't dominate on wide viewports.
|
|
11
|
+
.media-editor-toolbar__rotation-slider {
|
|
12
|
+
flex: 1 1 auto;
|
|
13
|
+
max-width: 240px;
|
|
14
|
+
|
|
15
|
+
// At narrow widths the slider is too cramped to aim precisely;
|
|
16
|
+
// the 90° rotate buttons cover the essential need.
|
|
17
|
+
@media (max-width: #{ $break-mobile }) {
|
|
18
|
+
display: none;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -74,10 +74,11 @@ function MediaPreviewContent( {
|
|
|
74
74
|
<p className="media-editor-preview__mime-type">
|
|
75
75
|
{ mimeType }
|
|
76
76
|
</p>
|
|
77
|
+
{ /* eslint-disable-next-line react/jsx-no-target-blank */ }
|
|
77
78
|
<a
|
|
78
79
|
href={ mediaUrl }
|
|
79
80
|
target="_blank"
|
|
80
|
-
rel="noopener
|
|
81
|
+
rel="noopener"
|
|
81
82
|
className="media-editor-preview__download-link"
|
|
82
83
|
>
|
|
83
84
|
{ __( 'View file' ) }
|