@wordpress/media-editor 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -68
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -720
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +136 -89
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -281
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -696
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -75
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -273
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +5 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +20 -42
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor/use-save-media-editor.ts"],
|
|
4
|
-
"sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\nimport {\n\tbuildModifiers,\n\ttype Modifier,\n} from '../media-editor-modal/build-modifiers';\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tconst { state } = session.cropper;\n\tif ( ! session.hasOutputEdits || ! state.image ) {\n\t\treturn [];\n\t}\n\treturn buildModifiers( state, {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t} );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\n\t\t\t}\n\n\t\t\tif ( next && next.id ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tsession.cropper.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t\tprevious,\n\t\t\t\t} );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( ( error as { message?: string } )?.message ??\n\t\t\t\t\t\t__( 'An unknown error occurred.' ) );\n\t\t\tcreateErrorNotice(\n\t\t\t\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t)\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\t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UACT,KAAK,KAAK;AAAA,UACV,OAAO;AAAA,UACP;AAAA,QACD,CAAE;AAAA,MACH;AAAA,IACD,SAAU,OAAQ;AACjB,YAAM,UACL,iBAAiB,QACd,MAAM,UACF,OAAiC,WACtC,GAAI,4BAA6B;AACpC;AAAA,QACC,UACG;AAAA;AAAA,UAEA,GAAI,0BAA2B;AAAA,UAC/B;AAAA,QACD,IACC;AAAA;AAAA,UAEA,GAAI,0BAA2B;AAAA,UAC/B;AAAA,QACD;AAAA,QACF;AAAA,UACC,MAAM;AAAA,UACN,SAAS;AAAA,QACV;AAAA,MACD;AAAA,IACD,UAAE;AACD,kBAAa,KAAM;AAAA,IACpB;AAAA,EACD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO,EAAE,UAAU,KAAK;AACzB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"use-save-media-editor.mjs","names":["coreStore","noticesStore"],"sources":["../../../src/components/media-editor/use-save-media-editor.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\nimport {\n\tbuildModifiers,\n\ttype Modifier,\n} from '../media-editor-modal/build-modifiers';\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tif ( ! session.hasOutputEdits ) {\n\t\treturn [];\n\t}\n\treturn buildModifiers( session.cropper );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\n\t\t\t}\n\n\t\t\tif ( next && next.id ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tsession.cropper.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t\tprevious,\n\t\t\t\t} );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( ( error as { message?: string } )?.message ??\n\t\t\t\t\t\t__( 'An unknown error occurred.' ) );\n\t\t\tcreateErrorNotice(\n\t\t\t\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t)\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,qBAAqB;CAC1B;CACA;CACA;CACA;CACA;AACD;AAGA,MAAa,+BAA+B;AAuC5C,SAAS,iBAAkB,SAA0C;CACpE,IAAK,CAAE,QAAQ,gBACd,OAAO,CAAC;CAET,OAAO,eAAgB,QAAQ,OAAQ;AACxC;AAEA,SAAS,iBACR,cACA,OAC4B;CAC5B,MAAM,gBAA2C,CAAC;CAClD,KAAM,MAAM,OAAO,oBAClB,IAAK,gBAAgB,OAAO,cAC3B,cAAe,OAAQ,aAAc;CAOvC,IAAK,EAAI,UAAU,kBAAmB,OAAO,SAAS,KAAA,GACrD,cAAc,OAAO,MAAM;CAE5B,OAAO;AACR;AAEA,SAAgB,mBAAoB,EACnC,SACA,IACA,SACA,OACA,SACA,qBACqD;CACrD,MAAM,WAAW,YAAY;CAC7B,MAAM,EACL,wB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UACF,OAAiC,WACtC,GAAI,4BAA6B;IACpC,kBACC,UACG,QAEA,GAAI,0BAA2B,GAC/B,OACD,IACC,QAEA,GAAI,0BAA2B,GAC/B,OACD,GACF;KACC,MAAM;KACN,SAAS;IACV,CACD;GACD,UAAU;IACT,YAAa,KAAM;GACpB;EACD,GAAG;GACF;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACD,CAEsB;CAAE;AACzB"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/media-editor/src/components/media-editor-canvas/index.tsx
|
|
2
1
|
import clsx from "clsx";
|
|
3
2
|
import { useCallback, useEffect, useMemo, useState } from "@wordpress/element";
|
|
4
3
|
import { Spinner } from "@wordpress/components";
|
|
@@ -6,99 +5,102 @@ import { __ } from "@wordpress/i18n";
|
|
|
6
5
|
import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
|
|
7
6
|
import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
|
|
8
7
|
import { Cropper } from "../../image-editor/index.mjs";
|
|
9
|
-
import {
|
|
8
|
+
import { resolveAspectRatio, useMediaEditor } from "../../state/index.mjs";
|
|
10
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
10
|
+
// packages/media-editor/src/components/media-editor-canvas/index.tsx
|
|
11
|
+
/**
|
|
12
|
+
* Editing surface for image media in the media editor modal. Pulls
|
|
13
|
+
* its cropper controller from the surrounding `<MediaEditorStateProvider>`
|
|
14
|
+
* so the bottom bar and Crop sidebar tab share the same state.
|
|
15
|
+
*
|
|
16
|
+
* Returns `null` for missing or non-image media so the modal's outer
|
|
17
|
+
* guards can render a spinner or fall through to `<MediaPreview>`.
|
|
18
|
+
*
|
|
19
|
+
* @param props
|
|
20
|
+
* @param props.isPlacementActive
|
|
21
|
+
* @param props.onGestureStart
|
|
22
|
+
* @param props.onGestureEnd
|
|
23
|
+
* @param props.disabled
|
|
24
|
+
*/
|
|
25
|
+
function MediaEditorCanvas({ isPlacementActive = false, onGestureStart, onGestureEnd, disabled = false }) {
|
|
26
|
+
const { media } = useMediaEditorContext();
|
|
27
|
+
const session = useMediaEditor();
|
|
28
|
+
const { aspectRatioValue } = session.cropOptions;
|
|
29
|
+
const cropperImage = session.cropper.state.image;
|
|
30
|
+
const { beginGesture, endGesture, setSourceImage } = session;
|
|
31
|
+
const [settled, setSettled] = useState();
|
|
32
|
+
const aspectRatio = useMemo(() => resolveAspectRatio(aspectRatioValue, cropperImage), [aspectRatioValue, cropperImage]);
|
|
33
|
+
const handleGestureStart = useCallback(() => {
|
|
34
|
+
beginGesture();
|
|
35
|
+
onGestureStart?.();
|
|
36
|
+
}, [beginGesture, onGestureStart]);
|
|
37
|
+
const handleGestureEnd = useCallback(() => {
|
|
38
|
+
endGesture();
|
|
39
|
+
onGestureEnd?.();
|
|
40
|
+
}, [endGesture, onGestureEnd]);
|
|
41
|
+
const mediaUrl = media?.source_url;
|
|
42
|
+
const mediaType = getMediaTypeFromMimeType(media?.mime_type);
|
|
43
|
+
const mediaWidth = Number(media?.media_details?.width);
|
|
44
|
+
const mediaHeight = Number(media?.media_details?.height);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!mediaUrl || !Number.isFinite(mediaWidth) || !Number.isFinite(mediaHeight) || mediaWidth <= 0 || mediaHeight <= 0) return;
|
|
47
|
+
setSourceImage({
|
|
48
|
+
src: mediaUrl,
|
|
49
|
+
naturalWidth: mediaWidth,
|
|
50
|
+
naturalHeight: mediaHeight
|
|
51
|
+
});
|
|
52
|
+
}, [
|
|
53
|
+
mediaUrl,
|
|
54
|
+
mediaWidth,
|
|
55
|
+
mediaHeight,
|
|
56
|
+
setSourceImage
|
|
57
|
+
]);
|
|
58
|
+
const isImage = mediaType.type === "image";
|
|
59
|
+
const status = settled && settled.url === mediaUrl ? settled.status : "loading";
|
|
60
|
+
const handleImageLoaded = useCallback(() => {
|
|
61
|
+
setSettled({
|
|
62
|
+
url: mediaUrl,
|
|
63
|
+
status: "loaded"
|
|
64
|
+
});
|
|
65
|
+
}, [mediaUrl]);
|
|
66
|
+
const handleImageError = useCallback(() => {
|
|
67
|
+
setSettled({
|
|
68
|
+
url: mediaUrl,
|
|
69
|
+
status: "error"
|
|
70
|
+
});
|
|
71
|
+
}, [mediaUrl]);
|
|
72
|
+
if (!mediaUrl || !isImage) return null;
|
|
73
|
+
if (status === "error") return /* @__PURE__ */ jsx("div", {
|
|
74
|
+
className: "media-editor-canvas",
|
|
75
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
76
|
+
className: "media-editor-canvas__error",
|
|
77
|
+
role: "alert",
|
|
78
|
+
children: /* @__PURE__ */ jsx("p", { children: __("Failed to load image.") })
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
82
|
+
className: "media-editor-canvas",
|
|
83
|
+
children: [status === "loading" && /* @__PURE__ */ jsx("div", {
|
|
84
|
+
className: "media-editor-canvas__spinner",
|
|
85
|
+
children: /* @__PURE__ */ jsx(Spinner, {})
|
|
86
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
87
|
+
className: clsx("media-editor-canvas__cropper", { "is-loaded": status === "loaded" }),
|
|
88
|
+
children: /* @__PURE__ */ jsx(Cropper, {
|
|
89
|
+
src: mediaUrl,
|
|
90
|
+
controller: session.cropper,
|
|
91
|
+
aspectRatio,
|
|
92
|
+
freeformCrop: true,
|
|
93
|
+
showGrid: "interactive",
|
|
94
|
+
isPlacementActive,
|
|
95
|
+
onGestureStart: handleGestureStart,
|
|
96
|
+
onGestureEnd: handleGestureEnd,
|
|
97
|
+
onImageLoaded: handleImageLoaded,
|
|
98
|
+
onImageError: handleImageError,
|
|
99
|
+
disabled
|
|
100
|
+
})
|
|
101
|
+
})]
|
|
102
|
+
});
|
|
100
103
|
}
|
|
101
|
-
export {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
//# sourceMappingURL=index.mjs.map
|
|
104
|
+
export { MediaEditorCanvas as default };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor-canvas/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport { useCallback, useEffect, useMemo, useState } from '@wordpress/element';\nimport { Spinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { Cropper } from '../../image-editor';\nimport { useMediaEditor, resolveAspectRatio } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas cropper gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas cropper gesture ends. */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Disable crop interaction on the canvas. Set while the edit is saving,\n\t * so a drag cannot change the crop after the request was built.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its cropper controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n * @param props.disabled\n */\nexport default function MediaEditorCanvas( {\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n\tdisabled = false,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst session = useMediaEditor();\n\tconst { aspectRatioValue } = session.cropOptions;\n\tconst cropperImage = session.cropper.state.image;\n\tconst { beginGesture, endGesture, setSourceImage } = session;\n\n\t// Tracks whether the image pixels have actually loaded. The cropper's\n\t// geometry is driven by the known media dimensions, so its handles and\n\t// overlays would otherwise appear before the image finishes streaming in.\n\tconst [ status, setStatus ] = useState< 'loading' | 'loaded' | 'error' >(\n\t\t'loading'\n\t);\n\n\t// Resolved aspect ratio is derived from the preset key + the\n\t// loaded image (for the \"Original\" preset). The reducer doesn't\n\t// store this number — only the preset key — so it's a render-time\n\t// derivation here.\n\tconst aspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\n\t);\n\n\tconst handleGestureStart = useCallback( () => {\n\t\tbeginGesture();\n\t\tonGestureStart?.();\n\t}, [ beginGesture, onGestureStart ] );\n\n\tconst handleGestureEnd = useCallback( () => {\n\t\tendGesture();\n\t\tonGestureEnd?.();\n\t}, [ endGesture, onGestureEnd ] );\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\tconst mediaWidth = Number( media?.media_details?.width );\n\tconst mediaHeight = Number( media?.media_details?.height );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! mediaUrl ||\n\t\t\t! Number.isFinite( mediaWidth ) ||\n\t\t\t! Number.isFinite( mediaHeight ) ||\n\t\t\tmediaWidth <= 0 ||\n\t\t\tmediaHeight <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetSourceImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\n\t// Probe the image to know when its pixels have loaded (or failed),\n\t// independent of the cropper. The browser shares one fetch/cache with the\n\t// cropper's own `<img>`, so this adds no network cost. The cropper stays\n\t// framework-pure — load/error handling lives here in the wrapper layer.\n\tuseEffect( () => {\n\t\tif ( ! mediaUrl || ! isImage ) {\n\t\t\treturn;\n\t\t}\n\t\tsetStatus( 'loading' );\n\t\tconst probe = new window.Image();\n\t\tprobe.onload = () => setStatus( 'loaded' );\n\t\tprobe.onerror = () => setStatus( 'error' );\n\t\tprobe.src = mediaUrl;\n\t\t// Cached images may already be complete before listeners attach.\n\t\tif ( probe.complete ) {\n\t\t\tsetStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );\n\t\t}\n\t\treturn () => {\n\t\t\tprobe.onload = null;\n\t\t\tprobe.onerror = null;\n\t\t};\n\t}, [ mediaUrl, isImage ] );\n\n\tif ( ! mediaUrl || ! isImage ) {\n\t\treturn null;\n\t}\n\n\tif ( status === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-canvas\">\n\t\t\t\t<div className=\"media-editor-canvas__error\" role=\"alert\">\n\t\t\t\t\t<p>{ __( 'Failed to load image.' ) }</p>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t{ status === 'loading' && (\n\t\t\t\t<div className=\"media-editor-canvas__spinner\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The cropper stays mounted while loading (hidden behind the\n\t\t\t * spinner) so the image decodes off-screen and reveals in one paint\n\t\t\t * instead of streaming in top-to-bottom. Until it's revealed it's\n\t\t\t * non-interactive (`pointer-events: none` in CSS).\n\t\t\t *\n\t\t\t * The crop area is never focused programmatically: the modal keeps\n\t\t\t * initial focus on the dialog frame, and users reach the crop area\n\t\t\t * by tabbing to it.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'media-editor-canvas__cropper', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<Cropper\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ session.cropper }\n\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\tshowGrid=\"interactive\"\n\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,UAA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AE,UAAU,YAAY,aAAa,cAAe,CAAE;AAEzD,QAAM,UAAU,UAAU,SAAS;AAMnC,YAAW,MAAM;AAChB,QAAK,CAAE,YAAY,CAAE,SAAU;AAC9B;AAAA,IACD;AACA,cAAW,SAAU;AACrB,UAAM,QAAQ,IAAI,OAAO,MAAM;AAC/B,UAAM,SAAS,MAAM,UAAW,QAAS;AACzC,UAAM,UAAU,MAAM,UAAW,OAAQ;AACzC,UAAM,MAAM;AAEZ,QAAK,MAAM,UAAW;AACrB,gBAAW,MAAM,eAAe,IAAI,WAAW,OAAQ;AAAA,IACxD;AACA,WAAO,MAAM;AACZ,YAAM,SAAS;AACf,YAAM,UAAU;AAAA,IACjB;AAAA,EACD,GAAG,CAAE,UAAU,OAAQ,CAAE;AAEzB,MAAK,CAAE,YAAY,CAAE,SAAU;AAC9B,WAAO;AAAA,EACR;AAEA,MAAK,WAAW,SAAU;AACzB,WACC,oBAAC,SAAI,WAAU,uBACd,8BAAC,SAAI,WAAU,8BAA6B,MAAK,SAChD,8BAAC,OAAI,aAAI,uBAAwB,GAAG,GACrC,GACD;AAAA,EAEF;AAEA,SACC,qBAAC,SAAI,WAAU,uBACZ;AAAA,eAAW,aACZ,oBAAC,SAAI,WAAU,gCACd,8BAAC,WAAQ,GACV;AAAA,IAYD;AAAA,MAAC;AAAA;AAAA,QACA,WAAY,KAAM,gCAAgC;AAAA,UACjD,aAAa,WAAW;AAAA,QACzB,CAAE;AAAA,QAEF;AAAA,UAAC;AAAA;AAAA,YACA,KAAM;AAAA,YACN,YAAa,QAAQ;AAAA,YACrB;AAAA,YACA,cAAY;AAAA,YACZ,UAAS;AAAA,YACT;AAAA,YACA,gBAAiB;AAAA,YACjB,cAAe;AAAA,YACf;AAAA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,KACD;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["WCSpinner"],"sources":["../../../src/components/media-editor-canvas/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useCallback, useEffect, useMemo, useState } from '@wordpress/element';\nimport { Spinner as WCSpinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { Cropper } from '../../image-editor';\nimport { useMediaEditor, resolveAspectRatio } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas cropper gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas cropper gesture ends. */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Disable crop interaction on the canvas. Set while the edit is saving,\n\t * so a drag cannot change the crop after the request was built.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its cropper controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n * @param props.disabled\n */\nexport default function MediaEditorCanvas( {\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n\tdisabled = false,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst session = useMediaEditor();\n\tconst { aspectRatioValue } = session.cropOptions;\n\tconst cropperImage = session.cropper.state.image;\n\tconst { beginGesture, endGesture, setSourceImage } = session;\n\n\t// Tracks whether the image pixels have actually loaded. The cropper's\n\t// geometry is driven by the known media dimensions, so its handles and\n\t// overlays would otherwise appear before the image finishes streaming in.\n\t// Stored with the URL it is for, so a new URL (restoring the original\n\t// swaps it in place) counts as loading until the cropper reports back.\n\tconst [ settled, setSettled ] = useState< {\n\t\turl: string | undefined;\n\t\tstatus: 'loaded' | 'error';\n\t} >();\n\n\t// Resolved aspect ratio is derived from the preset key + the\n\t// loaded image (for the \"Original\" preset). The reducer doesn't\n\t// store this number — only the preset key — so it's a render-time\n\t// derivation here.\n\tconst aspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\n\t);\n\n\tconst handleGestureStart = useCallback( () => {\n\t\tbeginGesture();\n\t\tonGestureStart?.();\n\t}, [ beginGesture, onGestureStart ] );\n\n\tconst handleGestureEnd = useCallback( () => {\n\t\tendGesture();\n\t\tonGestureEnd?.();\n\t}, [ endGesture, onGestureEnd ] );\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\tconst mediaWidth = Number( media?.media_details?.width );\n\tconst mediaHeight = Number( media?.media_details?.height );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! mediaUrl ||\n\t\t\t! Number.isFinite( mediaWidth ) ||\n\t\t\t! Number.isFinite( mediaHeight ) ||\n\t\t\tmediaWidth <= 0 ||\n\t\t\tmediaHeight <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetSourceImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\tconst status =\n\t\tsettled && settled.url === mediaUrl ? settled.status : 'loading';\n\tconst handleImageLoaded = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'loaded' } );\n\t}, [ mediaUrl ] );\n\tconst handleImageError = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'error' } );\n\t}, [ mediaUrl ] );\n\n\tif ( ! mediaUrl || ! isImage ) {\n\t\treturn null;\n\t}\n\n\tif ( status === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-canvas\">\n\t\t\t\t<div className=\"media-editor-canvas__error\" role=\"alert\">\n\t\t\t\t\t<p>{ __( 'Failed to load image.' ) }</p>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t{ status === 'loading' && (\n\t\t\t\t<div className=\"media-editor-canvas__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The cropper stays mounted while loading (hidden behind the\n\t\t\t * spinner) so the image decodes off-screen and reveals in one paint\n\t\t\t * instead of streaming in top-to-bottom. Until it's revealed it's\n\t\t\t * non-interactive (`pointer-events: none` in CSS).\n\t\t\t *\n\t\t\t * The crop area is never focused programmatically: the modal keeps\n\t\t\t * initial focus on the dialog frame, and users reach the crop area\n\t\t\t * by tabbing to it.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'media-editor-canvas__cropper', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<Cropper\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ session.cropper }\n\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\tshowGrid=\"interactive\"\n\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t\t\tonImageLoaded={ handleImageLoaded }\n\t\t\t\t\tonImageError={ handleImageError }\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAwB,kBAAmB,EAC1C,oBAAoB,OACpB,gBACA,cACA,WAAW,SACgB;CAC3B,MAAM,EAAE,UAAU,sBAAsB;CACxC,MAAM,UAAU,eAAe;CAC/B,MAAM,EAAE,qBAAqB,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AC,KAAD,EAAA,UAAK,GAAI,uBAAwB,EAAM,CAAA;EACnC,CAAA;CACD,CAAA;CAIP,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,WAAW,aACZ,oBAAC,OAAD;GAAK,WAAU;GACd,UAAA,oBAACA,SAAD,CAAY,CAAA;EACR,CAAA,GAYN,oBAAC,OAAD;GACC,WAAY,KAAM,gCAAgC,EACjD,aAAa,WAAW,SACzB,CAAE;GAEF,UAAA,oBAAC,SAAD;IACC,KAAM;IACN,YAAa,QAAQ;IACP;IACd,cAAA;IACA,UAAS;IACW;IACpB,gBAAiB;IACjB,cAAe;IACf,eAAgB;IAChB,cAAe;IACJ;GACX,CAAA;EACG,CAAA,CACD;;AAEP"}
|
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import { SelectControl as WCSelectControl } from "@wordpress/components";
|
|
3
|
-
import { Stack, VisuallyHidden } from "@wordpress/ui";
|
|
1
|
+
import { SelectControl, Stack, VisuallyHidden } from "@wordpress/ui";
|
|
4
2
|
import { __ } from "@wordpress/i18n";
|
|
5
3
|
import { CROP_CONTROL_ATTR } from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
6
4
|
import MediaEditorImageControls from "../media-editor-image-controls/index.mjs";
|
|
7
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
6
|
+
// packages/media-editor/src/components/media-editor-crop-panel/index.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Sidebar panel for crop controls: rotate, flip and zoom above the
|
|
9
|
+
* aspect-ratio selector. Rendered where the panel docks; below that the
|
|
10
|
+
* transform controls sit under the canvas instead, placed by the editor.
|
|
11
|
+
* @param props
|
|
12
|
+
* @param props.aspectRatioValue
|
|
13
|
+
* @param props.onAspectRatioChange
|
|
14
|
+
* @param props.aspectRatioOptions
|
|
15
|
+
* @param props.disabled
|
|
16
|
+
*/
|
|
17
|
+
function MediaEditorCropPanel({ aspectRatioValue, onAspectRatioChange, aspectRatioOptions, disabled = false }) {
|
|
18
|
+
const items = aspectRatioOptions.map((preset) => ({
|
|
19
|
+
label: preset.label,
|
|
20
|
+
value: preset.value.toString()
|
|
21
|
+
}));
|
|
22
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
23
|
+
direction: "column",
|
|
24
|
+
gap: "xl",
|
|
25
|
+
[CROP_CONTROL_ATTR]: true,
|
|
26
|
+
children: [
|
|
27
|
+
/* @__PURE__ */ jsx(VisuallyHidden, {
|
|
28
|
+
render: /* @__PURE__ */ jsx("h2", {}),
|
|
29
|
+
children: __("Crop options")
|
|
30
|
+
}),
|
|
31
|
+
/* @__PURE__ */ jsx(MediaEditorImageControls, {
|
|
32
|
+
withLabels: true,
|
|
33
|
+
disabled
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ jsx(SelectControl, {
|
|
36
|
+
label: __("Aspect ratio"),
|
|
37
|
+
value: items.find((item) => item.value === aspectRatioValue) ?? null,
|
|
38
|
+
onValueChange: (item) => {
|
|
39
|
+
if (item && item.value !== null) onAspectRatioChange(item.value);
|
|
40
|
+
},
|
|
41
|
+
disabled,
|
|
42
|
+
items
|
|
43
|
+
})
|
|
44
|
+
]
|
|
45
|
+
});
|
|
44
46
|
}
|
|
45
|
-
export {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//# sourceMappingURL=index.mjs.map
|
|
47
|
+
export { MediaEditorCropPanel as default };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor-crop-panel/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { SelectControl as WCSelectControl } from '@wordpress/components';\nimport { Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\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/** Aspect-ratio presets to display in the selector. */\n\taspectRatioOptions: AspectRatioPreset[];\n\t/** Disable every control in the panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\n/**\n * Sidebar panel for crop controls: rotate, flip and zoom above the\n * aspect-ratio selector. Rendered where the panel docks; below that the\n * transform controls sit under the canvas instead, placed by the editor.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.aspectRatioOptions\n * @param props.disabled\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n\tdisabled = false,\n}: MediaEditorCropPanelProps ) {\n\treturn (\n\t\t// Tag the whole panel as a crop-control region so the modal's\n\t\t// Cmd+Z handler doesn't mistake the SelectControl input for a\n\t\t// metadata field (which would suppress undo).\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"xl\"\n\t\t\t{ ...{ [ CROP_CONTROL_ATTR ]: true } }\n\t\t>\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Crop options' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<MediaEditorImageControls withLabels disabled={ disabled } />\n\t\t\t<WCSelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\tonChange={ onAspectRatioChange }\n\t\t\t\tdisabled={ disabled }\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</Stack>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB,uBAAuB;AACjD,SAAS,OAAO,sBAAsB;AACtC,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAClC,OAAO,8BAA8B;AAsCnC,SAK0B,KAL1B;AAVa,SAAR,qBAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACZ,GAA+B;AAC9B;AAAA;AAAA;AAAA;AAAA,IAIC;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,KAAI;AAAA,QACF,GAAG,EAAE,CAAE,iBAAkB,GAAG,KAAK;AAAA,QAEnC;AAAA,8BAAC,kBAAe,QAAS,oBAAC,QAAG,GAC1B,aAAI,cAAe,GACtB;AAAA,UACA,oBAAC,4BAAyB,YAAU,MAAC,UAAsB;AAAA,UAC3D;AAAA,YAAC;AAAA;AAAA,cACA,OAAQ,GAAI,cAAe;AAAA,cAC3B,OAAQ;AAAA,cACR,UAAW;AAAA,cACX;AAAA,cACA,SAAU,mBAAmB,IAAK,CAAE,YAAc;AAAA,gBACjD,OAAO,OAAO;AAAA,gBACd,OAAO,OAAO,MAAM,SAAS;AAAA,cAC9B,EAAI;AAAA;AAAA,UACL;AAAA;AAAA;AAAA,IACD;AAAA;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-crop-panel/index.tsx"],"sourcesContent":["import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\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/** Aspect-ratio presets to display in the selector. */\n\taspectRatioOptions: AspectRatioPreset[];\n\t/** Disable every control in the panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\n/**\n * Sidebar panel for crop controls: rotate, flip and zoom above the\n * aspect-ratio selector. Rendered where the panel docks; below that the\n * transform controls sit under the canvas instead, placed by the editor.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.aspectRatioOptions\n * @param props.disabled\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n\tdisabled = false,\n}: MediaEditorCropPanelProps ) {\n\tconst items = aspectRatioOptions.map( ( preset ) => ( {\n\t\tlabel: preset.label,\n\t\tvalue: preset.value.toString(),\n\t} ) );\n\n\treturn (\n\t\t// Tag the whole panel as a crop-control region so the modal's\n\t\t// Cmd+Z handler doesn't mistake the SelectControl input for a\n\t\t// metadata field (which would suppress undo).\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"xl\"\n\t\t\t{ ...{ [ CROP_CONTROL_ATTR ]: true } }\n\t\t>\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Crop options' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<MediaEditorImageControls withLabels disabled={ disabled } />\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={\n\t\t\t\t\titems.find( ( item ) => item.value === aspectRatioValue ) ??\n\t\t\t\t\tnull\n\t\t\t\t}\n\t\t\t\tonValueChange={ ( item ) => {\n\t\t\t\t\tif ( item && item.value !== null ) {\n\t\t\t\t\t\tonAspectRatioChange( item.value );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\titems={ items }\n\t\t\t/>\n\t\t</Stack>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA+BA,SAAwB,qBAAsB,EAC7C,kBACA,qBACA,oBACA,WAAW,SACmB;CAC9B,MAAM,QAAQ,mBAAmB,KAAO,YAAc;EACrD,OAAO,OAAO;EACd,OAAO,OAAO,MAAM,SAAS;CAC9B,EAAI;CAEJ,OAIC,qBAAC,OAAD;EACC,WAAU;EACV,KAAI;GACK,oBAAqB;EAH/B,UAAA;GAKC,oBAAC,gBAAD;IAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;IAC3B,UAAA,GAAI,cAAe;GACN,CAAA;GAChB,oBAAC,0BAAD;IAA0B,YAAA;IAAsB;GAAY,CAAA;GAC5D,oBAAC,eAAD;IACC,OAAQ,GAAI,cAAe;IAC3B,OACC,MAAM,MAAQ,SAAU,KAAK,UAAU,gBAAiB,KACxD;IAED,gBAAkB,SAAU;KAC3B,IAAK,QAAQ,KAAK,UAAU,MAC3B,oBAAqB,KAAK,KAAM;IAElC;IACW;IACH;GACR,CAAA;EACK;;AAET"}
|
|
@@ -1,52 +1,46 @@
|
|
|
1
|
-
// packages/media-editor/src/components/media-editor-fine-rotation/index.tsx
|
|
2
1
|
import { __ } from "@wordpress/i18n";
|
|
3
2
|
import { useMediaEditor } from "../../state/index.mjs";
|
|
4
3
|
import { useCropGestureHandlers } from "../../hooks/use-crop-gesture-handlers.mjs";
|
|
5
4
|
import { MAX_ROTATION_OFFSET } from "../../image-editor/core/constants.mjs";
|
|
6
5
|
import RotationRuler from "../rotation-ruler/index.mjs";
|
|
7
6
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
);
|
|
7
|
+
// packages/media-editor/src/components/media-editor-fine-rotation/index.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Fine-rotation slider for the media editor. It renders under the canvas so it
|
|
10
|
+
* stays constrained to the canvas column at all viewport sizes. Lives
|
|
11
|
+
* separately from the snap-rotate / flip buttons so the two can be placed
|
|
12
|
+
* independently per viewport.
|
|
13
|
+
*
|
|
14
|
+
* @param props
|
|
15
|
+
* @param props.onPlacementControlInteraction
|
|
16
|
+
* @param props.disabled
|
|
17
|
+
*/
|
|
18
|
+
function MediaEditorFineRotation({ onPlacementControlInteraction, disabled = false }) {
|
|
19
|
+
const { state, setRotation } = useMediaEditor().cropper;
|
|
20
|
+
const rotationGestureHandlers = useCropGestureHandlers({ commitOnKeyUp: false });
|
|
21
|
+
const baseAngle = Math.round(state.rotation / 90) * 90;
|
|
22
|
+
const visualDir = state.flip.horizontal !== state.flip.vertical ? -1 : 1;
|
|
23
|
+
const fineOffset = (state.rotation - baseAngle) * visualDir;
|
|
24
|
+
const handleRotationSlider = (value) => {
|
|
25
|
+
const EPS = .01;
|
|
26
|
+
const clamped = Math.max(-MAX_ROTATION_OFFSET + EPS, Math.min(MAX_ROTATION_OFFSET - EPS, value));
|
|
27
|
+
onPlacementControlInteraction?.();
|
|
28
|
+
setRotation(baseAngle + clamped * visualDir);
|
|
29
|
+
};
|
|
30
|
+
return /* @__PURE__ */ jsx("div", {
|
|
31
|
+
role: "presentation",
|
|
32
|
+
className: "media-editor-fine-rotation",
|
|
33
|
+
...rotationGestureHandlers,
|
|
34
|
+
children: /* @__PURE__ */ jsx(RotationRuler, {
|
|
35
|
+
label: __("Fine rotation"),
|
|
36
|
+
min: -MAX_ROTATION_OFFSET,
|
|
37
|
+
max: MAX_ROTATION_OFFSET,
|
|
38
|
+
value: fineOffset,
|
|
39
|
+
onChange: handleRotationSlider,
|
|
40
|
+
disabled
|
|
41
|
+
})
|
|
42
|
+
});
|
|
48
43
|
}
|
|
49
|
-
export {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=index.mjs.map
|
|
44
|
+
export { MediaEditorFineRotation as default };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor-fine-rotation/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation } = useMediaEditor().cropper;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,OAAO,mBAAmB;AA6DvB;AAvCY,SAAR,wBAA0C;AAAA,EAChD;AAAA,EACA,WAAW;AACZ,GAAkC;AACjC,QAAM,EAAE,OAAO,YAAY,IAAI,eAAe,EAAE;AAIhD,QAAM,0BAA0B,uBAAwB;AAAA,IACvD,eAAe;AAAA,EAChB,CAAE;AAKF,QAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;AACtD,QAAM,aAAa,MAAM,KAAK,eAAe,MAAM,KAAK;AACxD,QAAM,YAAY,aAAa,KAAK;AACpC,QAAM,cAAe,MAAM,WAAW,aAAc;AAEpD,QAAM,uBAAuB,CAAE,UAAmB;AAIjD,UAAM,MAAM;AACZ,UAAM,UAAU,KAAK;AAAA,MACpB,CAAC,sBAAsB;AAAA,MACvB,KAAK,IAAK,sBAAsB,KAAK,KAAM;AAAA,IAC5C;AACA,oCAAgC;AAChC,gBAAa,YAAY,UAAU,SAAU;AAAA,EAC9C;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,WAAU;AAAA,MACR,GAAG;AAAA,MAEL;AAAA,QAAC;AAAA;AAAA,UACA,OAAQ,GAAI,eAAgB;AAAA,UAC5B,KAAM,CAAC;AAAA,UACP,KAAM;AAAA,UACN,OAAQ;AAAA,UACR,UAAW;AAAA,UACX;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-fine-rotation/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation } = useMediaEditor().cropper;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,SAAwB,wBAAyB,EAChD,+BACA,WAAW,SACsB;CACjC,MAAM,EAAE,OAAO,gBAAgB,eAAe,CAAC,CAAC;CAIhD,MAAM,0BAA0B,uBAAwB,EACvD,eAAe,MAChB,CAAE;CAKF,MAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;CAEtD,MAAM,YADa,MAAM,KAAK,eAAe,MAAM,KAAK,WACzB,KAAK;CACpC,MAAM,cAAe,MAAM,WAAW,aAAc;CAEpD,MAAM,wBAAyB,UAAmB;EAIjD,MAAM,MAAM;EACZ,MAAM,UAAU,KAAK,IACpB,CAAC,sBAAsB,KACvB,KAAK,IAAK,sBAAsB,KAAK,KAAM,CAC5C;EACA,gCAAgC;EAChC,YAAa,YAAY,UAAU,SAAU;CAC9C;CAEA,OACC,oBAAC,OAAD;EACC,MAAK;EACL,WAAU;EACV,GAAK;EAEL,UAAA,oBAAC,eAAD;GACC,OAAQ,GAAI,eAAgB;GAC5B,KAAM,CAAC;GACP,KAAM;GACN,OAAQ;GACR,UAAW;GACA;EACX,CAAA;CACG,CAAA;AAEP"}
|