@wordpress/media-editor 0.21.0 → 0.23.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 +30 -0
- package/build/components/media-editor/index.cjs +586 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +42 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +131 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +117 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +81 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +61 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +181 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +82 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +113 -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/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 +59 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +100 -113
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +22 -45
- 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 +11 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +227 -296
- 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 +545 -675
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +37 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +95 -98
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +171 -238
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +74 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -90
- 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/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 +53 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +80 -91
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +3 -26
- 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 +7 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +223 -288
- 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 +145 -61
- package/build-style/style.css +144 -61
- package/build-types/components/media-editor/index.d.ts +20 -2
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- 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 +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- 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/state/aspect-ratio-presets.d.ts +24 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -4
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -63
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +33 -52
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +22 -23
- package/src/components/media-editor/index.tsx +355 -167
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +9 -10
- package/src/components/media-editor/use-save-media-editor.ts +48 -10
- package/src/components/media-editor-canvas/index.tsx +30 -51
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +15 -11
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +1 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +65 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +9 -5
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/state/README.md +32 -0
- package/src/state/aspect-ratio-presets.ts +37 -0
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -17
- package/src/state/types.ts +18 -72
- package/src/state/use-media-editor-state.ts +155 -238
- package/src/style.scss +2 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
- package/build/image-editor/core/camera.cjs +0 -225
- package/build/image-editor/core/camera.cjs.map +0 -7
- package/build/image-editor/core/constants.cjs +0 -108
- package/build/image-editor/core/constants.cjs.map +0 -7
- package/build/image-editor/core/containment.cjs +0 -276
- package/build/image-editor/core/containment.cjs.map +0 -7
- package/build/image-editor/core/crop-rect.cjs +0 -48
- package/build/image-editor/core/crop-rect.cjs.map +0 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
- package/build/image-editor/core/index.cjs +0 -62
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/interaction-controller.cjs +0 -654
- package/build/image-editor/core/interaction-controller.cjs.map +0 -7
- package/build/image-editor/core/math/rotation.cjs +0 -41
- package/build/image-editor/core/math/rotation.cjs.map +0 -7
- package/build/image-editor/core/math/sanitize.cjs +0 -92
- package/build/image-editor/core/math/sanitize.cjs.map +0 -7
- package/build/image-editor/core/setter-helpers.cjs +0 -64
- package/build/image-editor/core/setter-helpers.cjs.map +0 -7
- package/build/image-editor/core/source-region.cjs +0 -206
- package/build/image-editor/core/source-region.cjs.map +0 -7
- package/build/image-editor/core/state.cjs +0 -283
- package/build/image-editor/core/state.cjs.map +0 -7
- package/build/image-editor/core/stencil-math.cjs +0 -216
- package/build/image-editor/core/stencil-math.cjs.map +0 -7
- package/build/image-editor/core/transform-style.cjs +0 -52
- package/build/image-editor/core/transform-style.cjs.map +0 -7
- package/build/image-editor/core/transforms/pipeline.cjs +0 -43
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
- package/build/image-editor/core/types.cjs +0 -19
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/core/viewport-state.cjs +0 -50
- package/build/image-editor/core/viewport-state.cjs.map +0 -7
- package/build/image-editor/index.cjs +0 -67
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/cropper-provider.cjs +0 -50
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
- package/build/image-editor/react/components/cropper.cjs +0 -722
- package/build/image-editor/react/components/cropper.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs +0 -36
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
- package/build/image-editor/react/components/viewport-provider.cjs +0 -51
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs +0 -34
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
- package/build/image-editor/react/hooks/use-aria-announcer.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/image-editor/react/hooks/use-interaction.cjs +0 -213
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
- package/build/image-editor/react/visually-hidden-style.cjs +0 -41
- package/build/image-editor/react/visually-hidden-style.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/components/media-editor-modal/build-modifiers.mjs +0 -66
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
- package/build-module/image-editor/core/camera.mjs +0 -198
- package/build-module/image-editor/core/camera.mjs.map +0 -7
- package/build-module/image-editor/core/constants.mjs +0 -69
- package/build-module/image-editor/core/constants.mjs.map +0 -7
- package/build-module/image-editor/core/containment.mjs +0 -253
- package/build-module/image-editor/core/containment.mjs.map +0 -7
- package/build-module/image-editor/core/crop-rect.mjs +0 -23
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
- package/build-module/image-editor/core/index.mjs +0 -36
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -635
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
- package/build-module/image-editor/core/math/rotation.mjs +0 -15
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
- package/build-module/image-editor/core/math/sanitize.mjs +0 -63
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
- package/build-module/image-editor/core/setter-helpers.mjs +0 -39
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
- package/build-module/image-editor/core/source-region.mjs +0 -178
- package/build-module/image-editor/core/source-region.mjs.map +0 -7
- package/build-module/image-editor/core/state.mjs +0 -260
- package/build-module/image-editor/core/state.mjs.map +0 -7
- package/build-module/image-editor/core/stencil-math.mjs +0 -187
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
- package/build-module/image-editor/core/transform-style.mjs +0 -27
- package/build-module/image-editor/core/transform-style.mjs.map +0 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/core/viewport-state.mjs +0 -24
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
- package/build-module/image-editor/index.mjs +0 -39
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper.mjs +0 -704
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs +0 -9
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs +0 -8
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
- package/build-module/image-editor/react/hooks/use-aria-announcer.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/image-editor/react/hooks/use-interaction.mjs +0 -190
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
- package/build-module/image-editor/react/visually-hidden-style.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/components/media-editor-modal/build-modifiers.d.ts +0 -80
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -99
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -16
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -63
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -161
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -150
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -47
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -52
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1116
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-aria-announcer.d.ts","sourceRoot":"","sources":["../../../../src/image-editor/react/hooks/use-aria-announcer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAgJrD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAE,KAAK,EAAE,YAAY,GAAI,IAAI,CAkC5D"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { CropperState, NormalizedRect, Size } from '../../core/types';
|
|
2
|
-
import { type CropperSetters } from './build-cropper-setters';
|
|
3
|
-
/**
|
|
4
|
-
* The cropper controller surface — the contract the Cropper component
|
|
5
|
-
* and its interaction hooks consume.
|
|
6
|
-
*
|
|
7
|
-
* History (undo / redo / commitHistory) is intentionally NOT part of
|
|
8
|
-
* this interface. The cropper is a pure state machine; history is a
|
|
9
|
-
* higher-layer concern owned by a composite store
|
|
10
|
-
* (see media-editor/src/state).
|
|
11
|
-
*/
|
|
12
|
-
export interface CropperController extends CropperSetters {
|
|
13
|
-
/** The current cropper state (read-only). */
|
|
14
|
-
state: CropperState;
|
|
15
|
-
/** Set the loaded image (natural size and src). */
|
|
16
|
-
setImage: (image: CropperState['image']) => void;
|
|
17
|
-
/** Reset the state. Optionally merge partial state overrides. */
|
|
18
|
-
reset: (resetState?: Partial<CropperState>) => void;
|
|
19
|
-
/** Whether the current state differs from the initial state. */
|
|
20
|
-
isDirty: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Export the cropped image as a Blob. Throws on failure — see
|
|
23
|
-
* `exportCroppedImage` for error semantics.
|
|
24
|
-
*/
|
|
25
|
-
getCroppedImage: (mimeType?: string, quality?: number) => Promise<Blob>;
|
|
26
|
-
/**
|
|
27
|
-
* Report the current rendered image size to the controller. The
|
|
28
|
-
* Cropper component calls this on visualSize changes; composite
|
|
29
|
-
* controllers use it to compute aspect-ratio reshapes. The pure
|
|
30
|
-
* cropper hook ignores it (no-op).
|
|
31
|
-
*/
|
|
32
|
-
setVisualSize: (size: Size) => void;
|
|
33
|
-
/**
|
|
34
|
-
* Adjust the cropRect in response to a viewport change (window
|
|
35
|
-
* resize, canvas resize). Behaves like `setCropRect` but, in
|
|
36
|
-
* composite controllers, does NOT record an undo entry — viewport
|
|
37
|
-
* reshapes aren't editor actions. The pure cropper hook aliases
|
|
38
|
-
* this to `setCropRect` (history is a composite concern).
|
|
39
|
-
*/
|
|
40
|
-
adjustCropRectForViewport: (rect: NormalizedRect) => void;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Pure reducer hook for the image cropper.
|
|
44
|
-
*
|
|
45
|
-
* Wraps the framework-agnostic `cropperReducer` and exposes named
|
|
46
|
-
* setters (built from the shared `buildCropperSetters` factory).
|
|
47
|
-
* Does NOT manage undo/redo history — that responsibility belongs to
|
|
48
|
-
* the surrounding application (see `useMediaEditorState` for the
|
|
49
|
-
* composite store used by the media editor).
|
|
50
|
-
*
|
|
51
|
-
* @param initialState Optional partial state to merge with DEFAULT_STATE.
|
|
52
|
-
* @return The cropper controller — state, setters, and helpers.
|
|
53
|
-
*/
|
|
54
|
-
export declare function useCropperReducer(initialState?: Partial<CropperState>): CropperController;
|
|
55
|
-
//# sourceMappingURL=use-cropper-reducer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-cropper-reducer.d.ts","sourceRoot":"","sources":["../../../../src/image-editor/react/hooks/use-cropper-reducer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,YAAY,EAEZ,cAAc,EACd,IAAI,EACJ,MAAM,kBAAkB,CAAC;AAQ1B,OAAO,EAEN,KAAK,cAAc,EACnB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACxD,6CAA6C;IAC7C,KAAK,EAAE,YAAY,CAAC;IACpB,mDAAmD;IACnD,QAAQ,EAAE,CAAE,KAAK,EAAE,YAAY,CAAE,OAAO,CAAE,KAAM,IAAI,CAAC;IACrD,iEAAiE;IACjE,KAAK,EAAE,CAAE,UAAU,CAAC,EAAE,OAAO,CAAE,YAAY,CAAE,KAAM,IAAI,CAAC;IACxD,gEAAgE;IAChE,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,eAAe,EAAE,CAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAM,OAAO,CAAE,IAAI,CAAE,CAAC;IAC5E;;;;;OAKG;IACH,aAAa,EAAE,CAAE,IAAI,EAAE,IAAI,KAAM,IAAI,CAAC;IACtC;;;;;;OAMG;IACH,yBAAyB,EAAE,CAAE,IAAI,EAAE,cAAc,KAAM,IAAI,CAAC;CAC5D;AAaD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,CAAC,EAAE,OAAO,CAAE,YAAY,CAAE,GACpC,iBAAiB,CA0GnB"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { CropperState, Size } from '../../core/types';
|
|
2
|
-
import { type CropperInteractionActions } from '../../core/interaction-controller';
|
|
3
|
-
/**
|
|
4
|
-
* The return type of the useInteraction hook.
|
|
5
|
-
*/
|
|
6
|
-
export interface UseInteractionReturn {
|
|
7
|
-
/** Event handler props to spread on the container element. */
|
|
8
|
-
handlers: {
|
|
9
|
-
onPointerDown: (e: React.PointerEvent) => void;
|
|
10
|
-
onTouchStart: (e: React.TouchEvent) => void;
|
|
11
|
-
onKeyDown: (e: React.KeyboardEvent) => void;
|
|
12
|
-
};
|
|
13
|
-
/** Native wheel handler — must be registered with { passive: false }. */
|
|
14
|
-
onWheelNative: (e: WheelEvent) => void;
|
|
15
|
-
/** Whether a drag (pan) interaction is in progress. */
|
|
16
|
-
isDragging: boolean;
|
|
17
|
-
/** Whether a double-tap zoom animation is in progress. */
|
|
18
|
-
isZooming: boolean;
|
|
19
|
-
/** Whether the user is currently performing a placement interaction. */
|
|
20
|
-
isPlacementActive: boolean;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Options for the useInteraction hook.
|
|
24
|
-
*/
|
|
25
|
-
export interface UseInteractionOptions {
|
|
26
|
-
/** Minimum zoom level. Defaults to MIN_ZOOM. */
|
|
27
|
-
minZoom?: number;
|
|
28
|
-
/** Maximum zoom level. Defaults to MAX_ZOOM. */
|
|
29
|
-
maxZoom?: number;
|
|
30
|
-
/** Zoom speed multiplier for wheel events. Defaults to 0.0025. */
|
|
31
|
-
zoomSpeed?: number;
|
|
32
|
-
/**
|
|
33
|
-
* Pan step size in normalized coords for keyboard events.
|
|
34
|
-
* Defaults to 0.01. Shift multiplies it by 10.
|
|
35
|
-
*/
|
|
36
|
-
keyboardStep?: number;
|
|
37
|
-
/** Zoom level for double-tap zoom. Defaults to 2. */
|
|
38
|
-
doubleTapZoom?: number;
|
|
39
|
-
/** Fires when a continuous gesture begins (pan drag, pinch zoom). */
|
|
40
|
-
onGestureStart?: () => void;
|
|
41
|
-
/** Fires when a continuous gesture ends (pointer release). */
|
|
42
|
-
onGestureEnd?: () => void;
|
|
43
|
-
/**
|
|
44
|
-
* Ignore all interaction. Any gesture already in flight is torn down,
|
|
45
|
-
* so a drag started before this flipped cannot keep moving the image.
|
|
46
|
-
*/
|
|
47
|
-
disabled?: boolean;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Mouse, touch, and keyboard event handling for pan, zoom,
|
|
51
|
-
* and crop manipulation.
|
|
52
|
-
*
|
|
53
|
-
* Returns event handler props to spread on the container element.
|
|
54
|
-
* Uses requestAnimationFrame for drag/pinch updates to avoid
|
|
55
|
-
* layout thrashing.
|
|
56
|
-
*
|
|
57
|
-
* @param state The current cropper state.
|
|
58
|
-
* @param actions Named state updates for cropper interactions.
|
|
59
|
-
* @param containerSize The container dimensions in pixels.
|
|
60
|
-
* @param imageSize The rendered image dimensions in pixels.
|
|
61
|
-
* @param options Optional configuration for zoom and keyboard behavior.
|
|
62
|
-
* @return Event handler props for the container element.
|
|
63
|
-
*/
|
|
64
|
-
export declare function useInteraction(state: CropperState, actions: CropperInteractionActions, containerSize: Size, imageSize?: Size, options?: UseInteractionOptions): UseInteractionReturn;
|
|
65
|
-
//# sourceMappingURL=use-interaction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-interaction.d.ts","sourceRoot":"","sources":["../../../../src/image-editor/react/hooks/use-interaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAEN,KAAK,yBAAyB,EAC9B,MAAM,mCAAmC,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,8DAA8D;IAC9D,QAAQ,EAAE;QACT,aAAa,EAAE,CAAE,CAAC,EAAE,KAAK,CAAC,YAAY,KAAM,IAAI,CAAC;QACjD,YAAY,EAAE,CAAE,CAAC,EAAE,KAAK,CAAC,UAAU,KAAM,IAAI,CAAC;QAC9C,SAAS,EAAE,CAAE,CAAC,EAAE,KAAK,CAAC,aAAa,KAAM,IAAI,CAAC;KAC9C,CAAC;IACF,yEAAyE;IACzE,aAAa,EAAE,CAAE,CAAC,EAAE,UAAU,KAAM,IAAI,CAAC;IACzC,uDAAuD;IACvD,UAAU,EAAE,OAAO,CAAC;IACpB,0DAA0D;IAC1D,SAAS,EAAE,OAAO,CAAC;IACnB,wEAAwE;IACxE,iBAAiB,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AA6BD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,yBAAyB,EAClC,aAAa,EAAE,IAAI,EACnB,SAAS,CAAC,EAAE,IAAI,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC7B,oBAAoB,CA8LtB"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { CropperState, Size } from '../../core/types';
|
|
2
|
-
/**
|
|
3
|
-
* React hook that computes a memoized CSS matrix() transform string
|
|
4
|
-
* from the cropper state.
|
|
5
|
-
*
|
|
6
|
-
* Delegates to the pure `computeTransformStyle` function in core.
|
|
7
|
-
*
|
|
8
|
-
* @param state The current cropper state.
|
|
9
|
-
* @param imageSize The rendered image dimensions in pixels.
|
|
10
|
-
* @return A CSS transform string.
|
|
11
|
-
*/
|
|
12
|
-
export declare function useTransformStyle(state: CropperState, imageSize: Size): string;
|
|
13
|
-
//# sourceMappingURL=use-transform-style.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-transform-style.d.ts","sourceRoot":"","sources":["../../../../src/image-editor/react/hooks/use-transform-style.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAG3D;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,IAAI,GACb,MAAM,CAKR"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ViewportState } from '../../core/types';
|
|
2
|
-
export interface UseViewportStateReturn {
|
|
3
|
-
viewport: ViewportState;
|
|
4
|
-
/**
|
|
5
|
-
* Unused in the current Cropper implementation — scaffolded for the
|
|
6
|
-
* upcoming navigator panel (viewport zoom slider).
|
|
7
|
-
*/
|
|
8
|
-
setViewportZoom: (zoom: number) => void;
|
|
9
|
-
setViewportPan: (pan: {
|
|
10
|
-
x: number;
|
|
11
|
-
y: number;
|
|
12
|
-
}) => void;
|
|
13
|
-
resetViewport: () => void;
|
|
14
|
-
}
|
|
15
|
-
export declare function useViewportState(): UseViewportStateReturn;
|
|
16
|
-
//# sourceMappingURL=use-viewport-state.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-viewport-state.d.ts","sourceRoot":"","sources":["../../../../src/image-editor/react/hooks/use-viewport-state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMtD,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,aAAa,CAAC;IACxB;;;OAGG;IACH,eAAe,EAAE,CAAE,IAAI,EAAE,MAAM,KAAM,IAAI,CAAC;IAC1C,cAAc,EAAE,CAAE,GAAG,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,KAAM,IAAI,CAAC;IAC1D,aAAa,EAAE,MAAM,IAAI,CAAC;CAC1B;AAED,wBAAgB,gBAAgB,IAAI,sBAAsB,CAsBzD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visually-hidden-style.d.ts","sourceRoot":"","sources":["../../../src/image-editor/react/visually-hidden-style.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,aAUzC,CAAC"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import type { CropperState, Size } from '../../image-editor';
|
|
2
|
-
import { getRotatedBBox } from '../../image-editor/core/camera';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A single modifier in the Core REST `/edit` payload. Order is
|
|
6
|
-
* significant — the server applies modifiers sequentially (see
|
|
7
|
-
* `WP_REST_Attachments_Controller::edit_media_item`).
|
|
8
|
-
*
|
|
9
|
-
* Shape/units:
|
|
10
|
-
* - `flip`: booleans per axis. Applied first in this module's output.
|
|
11
|
-
* - `rotate`: `angle` in degrees, clockwise-positive (matches the
|
|
12
|
-
* cropper's own convention; Core negates it internally for
|
|
13
|
-
* `WP_Image_Editor::rotate`, which is counterclockwise-positive).
|
|
14
|
-
* - `crop`: percentages (0–100) of the image's dimensions **at the
|
|
15
|
-
* moment the crop is applied**. Because modifiers are applied in
|
|
16
|
-
* order, after a preceding `rotate` the server's
|
|
17
|
-
* `WP_Image_Editor::get_size()` reports the full post-rotate AABB,
|
|
18
|
-
* so the percentages are of that AABB. Origin is top-left.
|
|
19
|
-
*/
|
|
20
|
-
export type Modifier =
|
|
21
|
-
| {
|
|
22
|
-
type: 'flip';
|
|
23
|
-
args: { flip: { horizontal: boolean; vertical: boolean } };
|
|
24
|
-
}
|
|
25
|
-
| { type: 'rotate'; args: { angle: number } }
|
|
26
|
-
| {
|
|
27
|
-
type: 'crop';
|
|
28
|
-
args: { left: number; top: number; width: number; height: number };
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Tolerance (percent) used to decide whether a crop rect is effectively
|
|
33
|
-
* full-frame. Sub-pixel / float-ulp deltas below this value are treated
|
|
34
|
-
* as no crop. Matches the historical threshold used by the legacy
|
|
35
|
-
* `use-save-image.js` (which compared against `99.9`).
|
|
36
|
-
*/
|
|
37
|
-
const CROP_TOLERANCE = 0.1;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Build a Core-compatible modifiers array from the cropper state.
|
|
41
|
-
*
|
|
42
|
-
* Emits `[flip, rotate, crop]` in that order. Identity operations are
|
|
43
|
-
* pruned — an absent flip, a rotation that normalizes to 0°, and a crop
|
|
44
|
-
* rect that covers (within tolerance) the full post-rotate AABB each
|
|
45
|
-
* produce no modifier. An identity state (fresh image, no edits) returns
|
|
46
|
-
* an empty array; callers can use that to skip the `/edit` call.
|
|
47
|
-
*
|
|
48
|
-
* Frames and math:
|
|
49
|
-
*
|
|
50
|
-
* The cropper's `cropRect` is stored as fractions of the **snap-rotation**
|
|
51
|
-
* bounding box (the stencil-reference frame — see `createCamera` /
|
|
52
|
-
* `createExportCamera`). Pan is in that frame; zoom scales the image
|
|
53
|
-
* beneath a fixed stencil. Two conversions are needed to reach the frame
|
|
54
|
-
* Core's crop modifier applies against:
|
|
55
|
-
*
|
|
56
|
-
* 1. Express the stencil rect in snap-AABB **pixels**:
|
|
57
|
-
* Image screen-normalized top-left with zoom/pan is
|
|
58
|
-
* `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the
|
|
59
|
-
* inverse of that transform applied to `cropRect`.
|
|
60
|
-
*
|
|
61
|
-
* 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs
|
|
62
|
-
* share the source-image center, so the conversion is a pure
|
|
63
|
-
* translation by `(fullCenter - snapCenter)`. Finally, express the
|
|
64
|
-
* translated rect as percentages of the full AABB.
|
|
65
|
-
*
|
|
66
|
-
* Rotation sign: the cropper composes `flip · R(θ)` on the source (see
|
|
67
|
-
* `createExportCamera` — rotate then flip). Core's `[flip, rotate]`
|
|
68
|
-
* applies the opposite order: `R(θ') · flip`. For both to land on the
|
|
69
|
-
* same pixels we invert the rotation sign when exactly one flip axis
|
|
70
|
-
* is set (`flip_h · R(θ) = R(-θ) · flip_h`). Both-or-neither flips
|
|
71
|
-
* leave the sign alone because `flip_h · flip_v = -I` commutes with
|
|
72
|
-
* rotation.
|
|
73
|
-
*
|
|
74
|
-
* @param state Current cropper state.
|
|
75
|
-
* @param imageSize Natural dimensions of the source image.
|
|
76
|
-
* @return Ordered modifier array; empty when nothing is server-relevant.
|
|
77
|
-
*/
|
|
78
|
-
export function buildModifiers(
|
|
79
|
-
state: CropperState,
|
|
80
|
-
imageSize: Size
|
|
81
|
-
): Modifier[] {
|
|
82
|
-
const modifiers: Modifier[] = [];
|
|
83
|
-
|
|
84
|
-
if ( imageSize.width === 0 || imageSize.height === 0 ) {
|
|
85
|
-
return modifiers;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const { cropRect, pan, zoom, flip } = state;
|
|
89
|
-
const hasFlipH = flip.horizontal;
|
|
90
|
-
const hasFlipV = flip.vertical;
|
|
91
|
-
|
|
92
|
-
if ( hasFlipH || hasFlipV ) {
|
|
93
|
-
modifiers.push( {
|
|
94
|
-
type: 'flip',
|
|
95
|
-
args: { flip: { horizontal: hasFlipH, vertical: hasFlipV } },
|
|
96
|
-
} );
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const rawAngle = ( ( state.rotation % 360 ) + 360 ) % 360;
|
|
100
|
-
// Invert the sign for single-axis flips so Core's `flip → rotate`
|
|
101
|
-
// pipeline matches the cropper's `rotate → flip` composition.
|
|
102
|
-
const singleAxisFlip = hasFlipH !== hasFlipV;
|
|
103
|
-
const signedAngle = singleAxisFlip ? ( 360 - rawAngle ) % 360 : rawAngle;
|
|
104
|
-
if ( signedAngle !== 0 ) {
|
|
105
|
-
modifiers.push( { type: 'rotate', args: { angle: signedAngle } } );
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const snapRotation = Math.round( state.rotation / 90 ) * 90;
|
|
109
|
-
const { width: snapW, height: snapH } = getRotatedBBox(
|
|
110
|
-
imageSize.width,
|
|
111
|
-
imageSize.height,
|
|
112
|
-
snapRotation
|
|
113
|
-
);
|
|
114
|
-
const { width: fullW, height: fullH } = getRotatedBBox(
|
|
115
|
-
imageSize.width,
|
|
116
|
-
imageSize.height,
|
|
117
|
-
state.rotation
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
// Stencil rect in snap-AABB pixels. Inverts `createExportCamera`'s
|
|
121
|
-
// pan/zoom composition to recover the pixel rectangle the stencil
|
|
122
|
-
// framed in that frame.
|
|
123
|
-
const imgLeft = 0.5 + pan.x - zoom / 2;
|
|
124
|
-
const imgTop = 0.5 + pan.y - zoom / 2;
|
|
125
|
-
const snapX = ( ( cropRect.x - imgLeft ) / zoom ) * snapW;
|
|
126
|
-
const snapY = ( ( cropRect.y - imgTop ) / zoom ) * snapH;
|
|
127
|
-
const widthPx = ( cropRect.width / zoom ) * snapW;
|
|
128
|
-
const heightPx = ( cropRect.height / zoom ) * snapH;
|
|
129
|
-
|
|
130
|
-
// Translate to the full AABB (both centered on source).
|
|
131
|
-
const offsetX = ( fullW - snapW ) / 2;
|
|
132
|
-
const offsetY = ( fullH - snapH ) / 2;
|
|
133
|
-
const fullX = snapX + offsetX;
|
|
134
|
-
const fullY = snapY + offsetY;
|
|
135
|
-
|
|
136
|
-
// Percentages of the full AABB — Core's crop frame after rotate.
|
|
137
|
-
const leftPct = ( fullX / fullW ) * 100;
|
|
138
|
-
const topPct = ( fullY / fullH ) * 100;
|
|
139
|
-
const widthPct = ( widthPx / fullW ) * 100;
|
|
140
|
-
const heightPct = ( heightPx / fullH ) * 100;
|
|
141
|
-
|
|
142
|
-
const coversFullFrame =
|
|
143
|
-
leftPct <= CROP_TOLERANCE &&
|
|
144
|
-
topPct <= CROP_TOLERANCE &&
|
|
145
|
-
widthPct >= 100 - CROP_TOLERANCE &&
|
|
146
|
-
heightPct >= 100 - CROP_TOLERANCE;
|
|
147
|
-
|
|
148
|
-
if ( ! coversFullFrame ) {
|
|
149
|
-
modifiers.push( {
|
|
150
|
-
type: 'crop',
|
|
151
|
-
args: {
|
|
152
|
-
left: leftPct,
|
|
153
|
-
top: topPct,
|
|
154
|
-
width: widthPct,
|
|
155
|
-
height: heightPct,
|
|
156
|
-
},
|
|
157
|
-
} );
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return modifiers;
|
|
161
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# Image Editor
|
|
2
|
-
|
|
3
|
-
> **Status: internal.** This module is not part of `@wordpress/media-editor`'s public API. Import it only from inside the media-editor package, through the local `../image-editor` barrel.
|
|
4
|
-
|
|
5
|
-
The image editor is the cropper engine used by the media editor:
|
|
6
|
-
|
|
7
|
-
- **Core:** state, camera math, containment, source-region, transforms, and canvas export.
|
|
8
|
-
- **React:** `<Cropper>`, `useCropperReducer`, and the optional `CropperProvider` / `useCropper` context wrapper.
|
|
9
|
-
|
|
10
|
-
`useCropperReducer` does not provide undo/redo. The media editor's composite state layer adds history and sidebar crop options on top of the cropper reducer.
|
|
11
|
-
|
|
12
|
-
## Quick Start
|
|
13
|
-
|
|
14
|
-
```tsx
|
|
15
|
-
import { Cropper, useCropperReducer } from '../image-editor';
|
|
16
|
-
|
|
17
|
-
function ImageCropper() {
|
|
18
|
-
const controller = useCropperReducer();
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div style={ { width: 600, height: 400 } }>
|
|
22
|
-
<Cropper
|
|
23
|
-
src="https://example.com/photo.jpg"
|
|
24
|
-
controller={ controller }
|
|
25
|
-
freeformCrop
|
|
26
|
-
showDimming
|
|
27
|
-
showGrid="interactive"
|
|
28
|
-
/>
|
|
29
|
-
</div>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
`useCropperReducer` returns a controller object with the current `state`, named setters, `reset`, `isDirty`, and `getCroppedImage`.
|
|
35
|
-
|
|
36
|
-
## Internal APIs
|
|
37
|
-
|
|
38
|
-
### `Cropper`
|
|
39
|
-
|
|
40
|
-
Fills its parent container. Required props are `src` and `controller`. Common options include `freeformCrop`, `aspectRatio`, `showGrid`, `showDimming`, `showDimensions`, `onGestureStart`, and `onGestureEnd`.
|
|
41
|
-
|
|
42
|
-
### `useCropperReducer( initialState? )`
|
|
43
|
-
|
|
44
|
-
Pure React state hook for the cropper reducer. Returns a `CropperController`: current state, named setters, `reset`, `isDirty`, and `getCroppedImage`.
|
|
45
|
-
|
|
46
|
-
### `CropperProvider` / `useCropper`
|
|
47
|
-
|
|
48
|
-
Convenience context wrapper around `useCropperReducer` for component trees that need shared cropper state.
|
|
49
|
-
|
|
50
|
-
## Core Helpers
|
|
51
|
-
|
|
52
|
-
The local barrel also exposes helpers for reducer composition, source-region calculation, pipeline replay, and canvas export. Use named setters or `TransformOperation` values for normal state changes. Use reducer actions only when composing a controller such as `useMediaEditorState()`.
|
|
53
|
-
|
|
54
|
-
## Styles
|
|
55
|
-
|
|
56
|
-
Styles are bundled through the media-editor stylesheet. Classes use the `wp-media-editor-image-editor` prefix.
|
|
57
|
-
|
|
58
|
-
## More
|
|
59
|
-
|
|
60
|
-
- [docs/architecture.md](docs/architecture.md)
|
|
61
|
-
- [docs/recipes.md](docs/recipes.md)
|