@wordpress/media-editor 0.22.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 +18 -0
- package/build/components/media-editor/index.cjs +74 -21
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +23 -3
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +6 -11
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +17 -1
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +4 -5
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +1 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +0 -1
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +10 -4
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +32 -67
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build-module/components/media-editor/index.mjs +78 -25
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +23 -3
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +1 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +0 -1
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +10 -5
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-style/style-rtl.css +104 -57
- package/build-style/style.css +103 -57
- package/build-types/components/media-editor/index.d.ts +17 -3
- 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/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- 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 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- 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 +163 -28
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- 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 +11 -9
- 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-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +0 -1
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +32 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +155 -240
- package/src/style.scss +2 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- 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 -98
- 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 -17
- 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 -54
- 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-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.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 -167
- 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 -137
- 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 -43
- 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 -43
- 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 -1108
- 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-controller.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,75 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useReducer, useRef, useState } from "@wordpress/element";
|
|
2
|
-
import { DEFAULT_STATE } from "../../core/constants.mjs";
|
|
3
|
-
import { exportCroppedImage } from "../../core/export/canvas-renderer.mjs";
|
|
4
|
-
import { cropperReducer, enforceContainment, isStateDirty } from "../../core/state.mjs";
|
|
5
|
-
import { buildCropperSetters } from "./build-cropper-setters.mjs";
|
|
6
|
-
// packages/media-editor/src/image-editor/react/hooks/use-cropper-controller.ts
|
|
7
|
-
function areCropperImagesEqual(a, b) {
|
|
8
|
-
return a?.src === b?.src && a?.naturalWidth === b?.naturalWidth && a?.naturalHeight === b?.naturalHeight;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Controller hook for the image cropper: the state, the named setters and
|
|
12
|
-
* the export helpers, without history.
|
|
13
|
-
*
|
|
14
|
-
* Wraps the framework-agnostic `cropperReducer` and exposes named
|
|
15
|
-
* setters (built from the shared `buildCropperSetters` factory).
|
|
16
|
-
* Does NOT manage undo/redo history — that responsibility belongs to
|
|
17
|
-
* the surrounding application (see `useMediaEditorState` for the
|
|
18
|
-
* composite store used by the media editor).
|
|
19
|
-
*
|
|
20
|
-
* @param initialState Optional partial state to merge with DEFAULT_STATE.
|
|
21
|
-
* @return The cropper controller — state, setters, and helpers.
|
|
22
|
-
*/
|
|
23
|
-
function useCropperController(initialState) {
|
|
24
|
-
const [state, dispatch] = useReducer(cropperReducer, initialState, (init) => enforceContainment({
|
|
25
|
-
...DEFAULT_STATE,
|
|
26
|
-
...init
|
|
27
|
-
}));
|
|
28
|
-
const [initialBaseline, setInitialBaseline] = useState(() => enforceContainment({
|
|
29
|
-
...DEFAULT_STATE,
|
|
30
|
-
...initialState
|
|
31
|
-
}));
|
|
32
|
-
const stateRef = useRef(state);
|
|
33
|
-
const dispatchAndSync = useCallback((action) => {
|
|
34
|
-
const next = cropperReducer(stateRef.current, action);
|
|
35
|
-
stateRef.current = next;
|
|
36
|
-
dispatch(action);
|
|
37
|
-
return next;
|
|
38
|
-
}, []);
|
|
39
|
-
const setImage = useCallback((image) => {
|
|
40
|
-
if (areCropperImagesEqual(stateRef.current.image, image)) return;
|
|
41
|
-
const next = dispatchAndSync({
|
|
42
|
-
type: "SET_IMAGE",
|
|
43
|
-
payload: image
|
|
44
|
-
});
|
|
45
|
-
setInitialBaseline(next);
|
|
46
|
-
}, [dispatchAndSync]);
|
|
47
|
-
const reset = useCallback((resetState) => {
|
|
48
|
-
const nextInitialState = dispatchAndSync({
|
|
49
|
-
type: "RESET",
|
|
50
|
-
payload: resetState
|
|
51
|
-
});
|
|
52
|
-
setInitialBaseline(nextInitialState);
|
|
53
|
-
}, [dispatchAndSync]);
|
|
54
|
-
const setters = useMemo(() => buildCropperSetters(dispatchAndSync, () => stateRef.current), [dispatchAndSync]);
|
|
55
|
-
const isDirty = isStateDirty(state, initialBaseline);
|
|
56
|
-
const getCroppedImage = useCallback((mimeType, quality) => {
|
|
57
|
-
if (!state.image) return Promise.reject(/* @__PURE__ */ new Error("No image loaded — call setImage first."));
|
|
58
|
-
return exportCroppedImage(state.image.src, state, mimeType, quality);
|
|
59
|
-
}, [state]);
|
|
60
|
-
const setVisualSize = useCallback(() => {}, []);
|
|
61
|
-
const adjustCropRectForViewport = setters.setCropRect;
|
|
62
|
-
return {
|
|
63
|
-
...setters,
|
|
64
|
-
state,
|
|
65
|
-
setImage,
|
|
66
|
-
reset,
|
|
67
|
-
isDirty,
|
|
68
|
-
getCroppedImage,
|
|
69
|
-
setVisualSize,
|
|
70
|
-
adjustCropRectForViewport
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
export { useCropperController };
|
|
74
|
-
|
|
75
|
-
//# sourceMappingURL=use-cropper-controller.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-cropper-controller.mjs","names":[],"sources":["../../../../src/image-editor/react/hooks/use-cropper-controller.ts"],"sourcesContent":["import {\n\tuseReducer,\n\tuseCallback,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport type {\n\tCropperState,\n\tCropperAction,\n\tNormalizedRect,\n\tSize,\n} from '../../core/types';\nimport { DEFAULT_STATE } from '../../core/constants';\nimport { exportCroppedImage } from '../../core/export/canvas-renderer';\nimport {\n\tcropperReducer,\n\tenforceContainment,\n\tisStateDirty,\n} from '../../core/state';\nimport {\n\tbuildCropperSetters,\n\ttype CropperSetters,\n} from './build-cropper-setters';\n\n/**\n * The cropper controller surface — the contract the Cropper component\n * and its interaction hooks consume.\n *\n * History (undo / redo / commitHistory) is intentionally NOT part of\n * this interface. The cropper is a pure state machine; history is a\n * higher-layer concern owned by a composite store\n * (see media-editor/src/state).\n */\nexport interface CropperController extends CropperSetters {\n\t/** The current cropper state (read-only). */\n\tstate: CropperState;\n\t/** Set the loaded image (natural size and src). */\n\tsetImage: ( image: CropperState[ 'image' ] ) => void;\n\t/** Reset the state. Optionally merge partial state overrides. */\n\treset: ( resetState?: Partial< CropperState > ) => void;\n\t/** Whether the current state differs from the initial state. */\n\tisDirty: boolean;\n\t/**\n\t * Export the cropped image as a Blob. Throws on failure — see\n\t * `exportCroppedImage` for error semantics.\n\t */\n\tgetCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;\n\t/**\n\t * Called by `Cropper` whenever its rendered image size changes; not for\n\t * consumers to call. A composite controller uses the size to reshape the\n\t * crop for an aspect ratio. The pure cropper hook ignores it.\n\t */\n\tsetVisualSize: ( size: Size ) => void;\n\t/**\n\t * Called by `Cropper` when the viewport changes (window or canvas\n\t * resize); not for consumers to call. Like `setCropRect`, except that a\n\t * composite controller records no undo entry for it, since a viewport\n\t * reshape is not an editor action. The pure cropper hook aliases it to\n\t * `setCropRect`.\n\t */\n\tadjustCropRectForViewport: ( rect: NormalizedRect ) => void;\n}\n\nfunction areCropperImagesEqual(\n\ta: CropperState[ 'image' ],\n\tb: CropperState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * Controller hook for the image cropper: the state, the named setters and\n * the export helpers, without history.\n *\n * Wraps the framework-agnostic `cropperReducer` and exposes named\n * setters (built from the shared `buildCropperSetters` factory).\n * Does NOT manage undo/redo history — that responsibility belongs to\n * the surrounding application (see `useMediaEditorState` for the\n * composite store used by the media editor).\n *\n * @param initialState Optional partial state to merge with DEFAULT_STATE.\n * @return The cropper controller — state, setters, and helpers.\n */\nexport function useCropperController(\n\tinitialState?: Partial< CropperState >\n): CropperController {\n\tconst [ state, dispatch ] = useReducer(\n\t\tcropperReducer,\n\t\tinitialState,\n\t\t( init ) => enforceContainment( { ...DEFAULT_STATE, ...init } )\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. Stored in state (not a ref) so the comparison reads\n\t// a value, not a ref's `current`. `setImage` and `reset` refresh\n\t// this when the consumer establishes a new baseline.\n\tconst [ initialBaseline, setInitialBaseline ] = useState< CropperState >(\n\t\t() => enforceContainment( { ...DEFAULT_STATE, ...initialState } )\n\t);\n\t// Latest-state ref used by setters that need to read fresh state\n\t// (focal-point zoom, toggleFlip, reset, setImage). Updated\n\t// synchronously inside `dispatchAndSync` so multiple actions in\n\t// one event see each other's output before React commits.\n\tconst stateRef = useRef( state );\n\n\tconst dispatchAndSync = useCallback( ( action: CropperAction ) => {\n\t\tconst next = cropperReducer( stateRef.current, action );\n\t\tstateRef.current = next;\n\t\tdispatch( action );\n\t\treturn next;\n\t}, [] );\n\n\tconst setImage = useCallback(\n\t\t( image: CropperState[ 'image' ] ) => {\n\t\t\tif ( areCropperImagesEqual( stateRef.current.image, image ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst next = dispatchAndSync( {\n\t\t\t\ttype: 'SET_IMAGE',\n\t\t\t\tpayload: image,\n\t\t\t} );\n\t\t\t// Refresh the \"clean\" snapshot to match the post-load state\n\t\t\t// produced by the reducer. Otherwise containment can nudge\n\t\t\t// pan/zoom by tiny amounts on load and `isDirty` would\n\t\t\t// report true from the start.\n\t\t\tsetInitialBaseline( next );\n\t\t},\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tconst nextInitialState = dispatchAndSync( {\n\t\t\t\ttype: 'RESET',\n\t\t\t\tpayload: resetState,\n\t\t\t} );\n\t\t\t// Mirror the reducer's RESET exactly so isDirty stays in\n\t\t\t// sync. The containment step can tweak pan/zoom/cropRect by\n\t\t\t// float ulp; fold those into the \"initial\" snapshot or\n\t\t\t// isDirty would report true after a reset.\n\t\t\tsetInitialBaseline( nextInitialState );\n\t\t},\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst setters = useMemo(\n\t\t() => buildCropperSetters( dispatchAndSync, () => stateRef.current ),\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst isDirty = isStateDirty( state, initialBaseline );\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded — call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.image.src,\n\t\t\t\tstate,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state ]\n\t);\n\n\t// No-op for the pure hook — visualSize matters only when a\n\t// composite store needs to compute aspect-ratio reshapes\n\t// (see useMediaEditorState). Typed to accept a Size so it\n\t// satisfies the controller surface; the value is intentionally\n\t// ignored.\n\tconst setVisualSize = useCallback( () => {}, [] );\n\n\t// In the pure hook, history isn't a concern — viewport-driven\n\t// reshape is identical to setCropRect.\n\tconst adjustCropRectForViewport = setters.setCropRect;\n\n\tconst controller: CropperController = {\n\t\t...setters,\n\t\tstate,\n\t\tsetImage,\n\t\treset,\n\t\tisDirty,\n\t\tgetCroppedImage,\n\t\tsetVisualSize,\n\t\tadjustCropRectForViewport,\n\t};\n\treturn controller;\n}\n"],"mappings":";;;;;;AAgEA,SAAS,sBACR,GACA,GACU;CACV,OACC,GAAG,QAAQ,GAAG,OACd,GAAG,iBAAiB,GAAG,gBACvB,GAAG,kBAAkB,GAAG;AAE1B;;;;;;;;;;;;;;AAeA,SAAgB,qBACf,cACoB;CACpB,MAAM,CAAE,OAAO,YAAa,WAC3B,gBACA,eACE,SAAU,mBAAoB;EAAE,GAAG;EAAe,GAAG;CAAK,CAAE,CAC/D;CAMA,MAAM,CAAE,iBAAiB,sBAAuB,eACzC,mBAAoB;EAAE,GAAG;EAAe,GAAG;CAAa,CAAE,CACjE;CAKA,MAAM,WAAW,OAAQ,KAAM;CAE/B,MAAM,kBAAkB,aAAe,WAA2B;EACjE,MAAM,OAAO,eAAgB,SAAS,SAAS,MAAO;EACtD,SAAS,UAAU;EACnB,SAAU,MAAO;EACjB,OAAO;CACR,GAAG,CAAC,CAAE;CAEN,MAAM,WAAW,aACd,UAAoC;EACrC,IAAK,sBAAuB,SAAS,QAAQ,OAAO,KAAM,GACzD;EAED,MAAM,OAAO,gBAAiB;GAC7B,MAAM;GACN,SAAS;EACV,CAAE;EAKF,mBAAoB,IAAK;CAC1B,GACA,CAAE,eAAgB,CACnB;CAEA,MAAM,QAAQ,aACX,eAA0C;EAC3C,MAAM,mBAAmB,gBAAiB;GACzC,MAAM;GACN,SAAS;EACV,CAAE;EAKF,mBAAoB,gBAAiB;CACtC,GACA,CAAE,eAAgB,CACnB;CAEA,MAAM,UAAU,cACT,oBAAqB,uBAAuB,SAAS,OAAQ,GACnE,CAAE,eAAgB,CACnB;CAEA,MAAM,UAAU,aAAc,OAAO,eAAgB;CAErD,MAAM,kBAAkB,aACrB,UAAmB,YAAuC;EAC3D,IAAK,CAAE,MAAM,OACZ,OAAO,QAAQ,uBACd,IAAI,MAAO,wCAAyC,CACrD;EAED,OAAO,mBACN,MAAM,MAAM,KACZ,OACA,UACA,OACD;CACD,GACA,CAAE,KAAM,CACT;CAOA,MAAM,gBAAgB,kBAAmB,CAAC,GAAG,CAAC,CAAE;CAIhD,MAAM,4BAA4B,QAAQ;CAY1C,OAAO;EATN,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;EACA;CAEe;AACjB"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from "@wordpress/element";
|
|
2
|
-
import { InteractionController } from "../../core/interaction-controller.mjs";
|
|
3
|
-
// packages/media-editor/src/image-editor/react/hooks/use-interaction.ts
|
|
4
|
-
/** How long keyboard placement stays active after the latest handled key. */
|
|
5
|
-
const KEYBOARD_INTERACTION_IDLE_MS = 300;
|
|
6
|
-
function isHandledKeyboardPan(event) {
|
|
7
|
-
switch (event.key) {
|
|
8
|
-
case "ArrowUp":
|
|
9
|
-
case "ArrowDown":
|
|
10
|
-
case "ArrowLeft":
|
|
11
|
-
case "ArrowRight": return true;
|
|
12
|
-
default: return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function isHandledKeyboardZoom(event) {
|
|
16
|
-
switch (event.key) {
|
|
17
|
-
case "+":
|
|
18
|
-
case "=":
|
|
19
|
-
case "-":
|
|
20
|
-
case "_": return true;
|
|
21
|
-
default: return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Mouse, touch, and keyboard event handling for pan, zoom,
|
|
26
|
-
* and crop manipulation.
|
|
27
|
-
*
|
|
28
|
-
* Returns event handler props to spread on the container element.
|
|
29
|
-
* Uses requestAnimationFrame for drag/pinch updates to avoid
|
|
30
|
-
* layout thrashing.
|
|
31
|
-
*
|
|
32
|
-
* @param state The current cropper state.
|
|
33
|
-
* @param actions Named state updates for cropper interactions.
|
|
34
|
-
* @param containerSize The container dimensions in pixels.
|
|
35
|
-
* @param imageSize The rendered image dimensions in pixels.
|
|
36
|
-
* @param options Optional configuration for zoom and keyboard behavior.
|
|
37
|
-
* @return Event handler props for the container element.
|
|
38
|
-
*/
|
|
39
|
-
function useInteraction(state, actions, containerSize, imageSize, options) {
|
|
40
|
-
const [isDragging, setIsDragging] = useState(false);
|
|
41
|
-
const [isZooming, setIsZooming] = useState(false);
|
|
42
|
-
const [isGestureActive, setIsGestureActive] = useState(false);
|
|
43
|
-
const [isKeyboardPanning, setIsKeyboardPanning] = useState(false);
|
|
44
|
-
const keyboardInteractionTimerRef = useRef(void 0);
|
|
45
|
-
const isKeyboardGestureActiveRef = useRef(false);
|
|
46
|
-
const stateRef = useRef(state);
|
|
47
|
-
stateRef.current = state;
|
|
48
|
-
const containerSizeRef = useRef(containerSize);
|
|
49
|
-
containerSizeRef.current = containerSize;
|
|
50
|
-
const imageSizeRef = useRef(imageSize);
|
|
51
|
-
imageSizeRef.current = imageSize;
|
|
52
|
-
const optionsRef = useRef(options);
|
|
53
|
-
optionsRef.current = options;
|
|
54
|
-
const actionsRef = useRef(actions);
|
|
55
|
-
actionsRef.current = actions;
|
|
56
|
-
const controllerRef = useRef(null);
|
|
57
|
-
const startPlacementGesture = useCallback(() => {
|
|
58
|
-
setIsGestureActive(true);
|
|
59
|
-
}, []);
|
|
60
|
-
const stopPlacementGesture = useCallback(() => {
|
|
61
|
-
setIsGestureActive(false);
|
|
62
|
-
}, []);
|
|
63
|
-
const signalKeyboardGesture = useCallback(() => {
|
|
64
|
-
if (!isKeyboardGestureActiveRef.current) {
|
|
65
|
-
isKeyboardGestureActiveRef.current = true;
|
|
66
|
-
optionsRef.current?.onGestureStart?.();
|
|
67
|
-
}
|
|
68
|
-
clearTimeout(keyboardInteractionTimerRef.current);
|
|
69
|
-
keyboardInteractionTimerRef.current = setTimeout(() => {
|
|
70
|
-
isKeyboardGestureActiveRef.current = false;
|
|
71
|
-
setIsKeyboardPanning(false);
|
|
72
|
-
optionsRef.current?.onGestureEnd?.();
|
|
73
|
-
}, KEYBOARD_INTERACTION_IDLE_MS);
|
|
74
|
-
}, []);
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
return () => {
|
|
77
|
-
clearTimeout(keyboardInteractionTimerRef.current);
|
|
78
|
-
};
|
|
79
|
-
}, []);
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
const controller = new InteractionController({
|
|
82
|
-
getState: () => stateRef.current,
|
|
83
|
-
actions: {
|
|
84
|
-
setPan: (pan) => actionsRef.current.setPan(pan),
|
|
85
|
-
setZoom: (zoom) => actionsRef.current.setZoom(zoom),
|
|
86
|
-
setZoomAtPoint: (zoom, pan) => actionsRef.current.setZoomAtPoint(zoom, pan),
|
|
87
|
-
snapRotate90: (direction) => actionsRef.current.snapRotate90(direction),
|
|
88
|
-
toggleFlip: (direction) => actionsRef.current.toggleFlip?.(direction)
|
|
89
|
-
},
|
|
90
|
-
getContainerSize: () => containerSizeRef.current,
|
|
91
|
-
getImageSize: () => imageSizeRef.current,
|
|
92
|
-
get minZoom() {
|
|
93
|
-
return optionsRef.current?.minZoom;
|
|
94
|
-
},
|
|
95
|
-
get maxZoom() {
|
|
96
|
-
return optionsRef.current?.maxZoom;
|
|
97
|
-
},
|
|
98
|
-
get zoomSpeed() {
|
|
99
|
-
return optionsRef.current?.zoomSpeed;
|
|
100
|
-
},
|
|
101
|
-
get keyboardStep() {
|
|
102
|
-
return optionsRef.current?.keyboardStep;
|
|
103
|
-
},
|
|
104
|
-
get doubleTapZoom() {
|
|
105
|
-
return optionsRef.current?.doubleTapZoom;
|
|
106
|
-
},
|
|
107
|
-
onGestureStart: () => {
|
|
108
|
-
startPlacementGesture();
|
|
109
|
-
optionsRef.current?.onGestureStart?.();
|
|
110
|
-
},
|
|
111
|
-
onGestureEnd: () => {
|
|
112
|
-
stopPlacementGesture();
|
|
113
|
-
optionsRef.current?.onGestureEnd?.();
|
|
114
|
-
},
|
|
115
|
-
onStatusChange: (status) => {
|
|
116
|
-
setIsDragging(status.isDragging);
|
|
117
|
-
setIsZooming(status.isZooming);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
controllerRef.current = controller;
|
|
121
|
-
return () => {
|
|
122
|
-
controller.destroy();
|
|
123
|
-
controllerRef.current = null;
|
|
124
|
-
};
|
|
125
|
-
}, [startPlacementGesture, stopPlacementGesture]);
|
|
126
|
-
const isDisabled = options?.disabled ?? false;
|
|
127
|
-
useEffect(() => {
|
|
128
|
-
if (!isDisabled) return;
|
|
129
|
-
controllerRef.current?.destroy();
|
|
130
|
-
setIsDragging(false);
|
|
131
|
-
setIsZooming(false);
|
|
132
|
-
setIsKeyboardPanning(false);
|
|
133
|
-
const wasGestureOpen = isGestureActive || isKeyboardGestureActiveRef.current;
|
|
134
|
-
if (isKeyboardGestureActiveRef.current) {
|
|
135
|
-
isKeyboardGestureActiveRef.current = false;
|
|
136
|
-
clearTimeout(keyboardInteractionTimerRef.current);
|
|
137
|
-
}
|
|
138
|
-
stopPlacementGesture();
|
|
139
|
-
if (wasGestureOpen) optionsRef.current?.onGestureEnd?.();
|
|
140
|
-
}, [
|
|
141
|
-
isDisabled,
|
|
142
|
-
isGestureActive,
|
|
143
|
-
stopPlacementGesture
|
|
144
|
-
]);
|
|
145
|
-
const onPointerDown = useCallback((e) => {
|
|
146
|
-
if (optionsRef.current?.disabled) return;
|
|
147
|
-
const el = e.currentTarget;
|
|
148
|
-
controllerRef.current?.handlePointerDown(e.nativeEvent, el);
|
|
149
|
-
}, []);
|
|
150
|
-
const onTouchStart = useCallback((e) => {
|
|
151
|
-
if (optionsRef.current?.disabled) return;
|
|
152
|
-
const el = e.currentTarget;
|
|
153
|
-
const rect = el.getBoundingClientRect();
|
|
154
|
-
controllerRef.current?.handleTouchStart(e.nativeEvent, rect, el.ownerDocument);
|
|
155
|
-
}, []);
|
|
156
|
-
const onKeyDown = useCallback((e) => {
|
|
157
|
-
if (optionsRef.current?.disabled) return;
|
|
158
|
-
if (isHandledKeyboardPan(e.nativeEvent)) {
|
|
159
|
-
setIsKeyboardPanning(true);
|
|
160
|
-
signalKeyboardGesture();
|
|
161
|
-
} else if (isHandledKeyboardZoom(e.nativeEvent)) signalKeyboardGesture();
|
|
162
|
-
controllerRef.current?.handleKeyDown(e.nativeEvent);
|
|
163
|
-
}, [signalKeyboardGesture]);
|
|
164
|
-
const onWheelNative = useCallback((e) => {
|
|
165
|
-
if (optionsRef.current?.disabled) return;
|
|
166
|
-
controllerRef.current?.handleWheel(e);
|
|
167
|
-
}, []);
|
|
168
|
-
return {
|
|
169
|
-
handlers: {
|
|
170
|
-
onPointerDown,
|
|
171
|
-
onTouchStart,
|
|
172
|
-
onKeyDown
|
|
173
|
-
},
|
|
174
|
-
onWheelNative,
|
|
175
|
-
isDragging,
|
|
176
|
-
isZooming,
|
|
177
|
-
isPlacementActive: isGestureActive || isKeyboardPanning || isZooming
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
export { useInteraction };
|
|
181
|
-
|
|
182
|
-
//# sourceMappingURL=use-interaction.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-interaction.mjs","names":[],"sources":["../../../../src/image-editor/react/hooks/use-interaction.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler — must be registered with { passive: false }. */\n\tonWheelNative: ( e: WheelEvent ) => void;\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n\t/** Whether the user is currently performing a placement interaction. */\n\tisPlacementActive: boolean;\n}\n\n/**\n * Options for the useInteraction hook.\n */\nexport interface UseInteractionOptions {\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Ignore all interaction. Any gesture already in flight is torn down,\n\t * so a drag started before this flipped cannot keep moving the image.\n\t */\n\tdisabled?: boolean;\n}\n\n/** How long keyboard placement stays active after the latest handled key. */\nconst KEYBOARD_INTERACTION_IDLE_MS = 300;\n\nfunction isHandledKeyboardPan( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown':\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isHandledKeyboardZoom( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase '+':\n\t\tcase '=':\n\t\tcase '-':\n\t\tcase '_':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Mouse, touch, and keyboard event handling for pan, zoom,\n * and crop manipulation.\n *\n * Returns event handler props to spread on the container element.\n * Uses requestAnimationFrame for drag/pinch updates to avoid\n * layout thrashing.\n *\n * @param state The current cropper state.\n * @param actions Named state updates for cropper interactions.\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param options Optional configuration for zoom and keyboard behavior.\n * @return Event handler props for the container element.\n */\nexport function useInteraction(\n\tstate: CropperState,\n\tactions: CropperInteractionActions,\n\tcontainerSize: Size,\n\timageSize?: Size,\n\toptions?: UseInteractionOptions\n): UseInteractionReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst [ isZooming, setIsZooming ] = useState( false );\n\tconst [ isGestureActive, setIsGestureActive ] = useState( false );\n\tconst [ isKeyboardPanning, setIsKeyboardPanning ] = useState( false );\n\tconst keyboardInteractionTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\t// Tracks whether a keyboard gesture (pan or zoom) is currently active so\n\t// onGestureStart is only fired once per gesture, not on every key repeat.\n\tconst isKeyboardGestureActiveRef = useRef( false );\n\n\t// Keep mutable refs so the controller always reads fresh values\n\t// without needing to be recreated.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\tconst containerSizeRef = useRef( containerSize );\n\tcontainerSizeRef.current = containerSize;\n\tconst imageSizeRef = useRef( imageSize );\n\timageSizeRef.current = imageSize;\n\tconst optionsRef = useRef( options );\n\toptionsRef.current = options;\n\tconst actionsRef = useRef( actions );\n\tactionsRef.current = actions;\n\n\tconst controllerRef = useRef< InteractionController | null >( null );\n\tconst startPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( true );\n\t}, [] );\n\tconst stopPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( false );\n\t}, [] );\n\t// Shared timer logic for any keyboard gesture (pan or zoom): fires\n\t// onGestureStart once per burst and onGestureEnd after the idle window.\n\tconst signalKeyboardGesture = useCallback( () => {\n\t\tif ( ! isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = true;\n\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\tkeyboardInteractionTimerRef.current = setTimeout( () => {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tsetIsKeyboardPanning( false );\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}, KEYBOARD_INTERACTION_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Create / destroy the controller. The controller reads all volatile\n\t// values through refs, so it can stay mounted across render updates.\n\tuseEffect( () => {\n\t\tconst controller = new InteractionController( {\n\t\t\tgetState: () => stateRef.current,\n\t\t\tactions: {\n\t\t\t\tsetPan: ( pan ) => actionsRef.current.setPan( pan ),\n\t\t\t\tsetZoom: ( zoom ) => actionsRef.current.setZoom( zoom ),\n\t\t\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\t\t\tactionsRef.current.setZoomAtPoint( zoom, pan ),\n\t\t\t\tsnapRotate90: ( direction ) =>\n\t\t\t\t\tactionsRef.current.snapRotate90( direction ),\n\t\t\t\ttoggleFlip: ( direction ) =>\n\t\t\t\t\tactionsRef.current.toggleFlip?.( direction ),\n\t\t\t},\n\t\t\tgetContainerSize: () => containerSizeRef.current,\n\t\t\tgetImageSize: () => imageSizeRef.current,\n\t\t\tget minZoom() {\n\t\t\t\treturn optionsRef.current?.minZoom;\n\t\t\t},\n\t\t\tget maxZoom() {\n\t\t\t\treturn optionsRef.current?.maxZoom;\n\t\t\t},\n\t\t\tget zoomSpeed() {\n\t\t\t\treturn optionsRef.current?.zoomSpeed;\n\t\t\t},\n\t\t\tget keyboardStep() {\n\t\t\t\treturn optionsRef.current?.keyboardStep;\n\t\t\t},\n\t\t\tget doubleTapZoom() {\n\t\t\t\treturn optionsRef.current?.doubleTapZoom;\n\t\t\t},\n\t\t\tonGestureStart: () => {\n\t\t\t\tstartPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t\t},\n\t\t\tonGestureEnd: () => {\n\t\t\t\tstopPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t\t},\n\t\t\tonStatusChange: ( status ) => {\n\t\t\t\tsetIsDragging( status.isDragging );\n\t\t\t\tsetIsZooming( status.isZooming );\n\t\t\t},\n\t\t} );\n\t\tcontrollerRef.current = controller;\n\t\treturn () => {\n\t\t\tcontroller.destroy();\n\t\t\tcontrollerRef.current = null;\n\t\t};\n\t}, [ startPlacementGesture, stopPlacementGesture ] );\n\n\t// Cancel any gesture already in flight when interaction is switched off,\n\t// so a drag that started before the flip cannot keep moving the image.\n\t// `destroy()` releases the pointer/touch listeners and the pending rAF;\n\t// the controller keeps working for later gestures once re-enabled.\n\t//\n\t// It does not signal the end of the gesture it just cut short, so that\n\t// is done here: a caller told a gesture began is otherwise left waiting\n\t// for an end that never comes, which keeps undo/redo disabled and leaves\n\t// the cropper's history batch open after a failed save.\n\tconst isDisabled = options?.disabled ?? false;\n\tuseEffect( () => {\n\t\tif ( ! isDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tcontrollerRef.current?.destroy();\n\t\tsetIsDragging( false );\n\t\tsetIsZooming( false );\n\t\tsetIsKeyboardPanning( false );\n\t\tconst wasGestureOpen =\n\t\t\tisGestureActive || isKeyboardGestureActiveRef.current;\n\t\tif ( isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t}\n\t\tstopPlacementGesture();\n\t\tif ( wasGestureOpen ) {\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}\n\t}, [ isDisabled, isGestureActive, stopPlacementGesture ] );\n\n\tconst onPointerDown = useCallback( ( e: React.PointerEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tcontrollerRef.current?.handlePointerDown( e.nativeEvent, el );\n\t}, [] );\n\n\tconst onTouchStart = useCallback( ( e: React.TouchEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tconst rect = el.getBoundingClientRect();\n\t\tcontrollerRef.current?.handleTouchStart(\n\t\t\te.nativeEvent,\n\t\t\trect,\n\t\t\tel.ownerDocument\n\t\t);\n\t}, [] );\n\n\tconst onKeyDown = useCallback(\n\t\t( e: React.KeyboardEvent ) => {\n\t\t\tif ( optionsRef.current?.disabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( isHandledKeyboardPan( e.nativeEvent ) ) {\n\t\t\t\tsetIsKeyboardPanning( true );\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t} else if ( isHandledKeyboardZoom( e.nativeEvent ) ) {\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t}\n\t\t\tcontrollerRef.current?.handleKeyDown( e.nativeEvent );\n\t\t},\n\t\t[ signalKeyboardGesture ]\n\t);\n\n\tconst onWheelNative = useCallback( ( e: WheelEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tcontrollerRef.current?.handleWheel( e );\n\t}, [] );\n\n\treturn {\n\t\thandlers: {\n\t\t\tonPointerDown,\n\t\t\tonTouchStart,\n\t\t\tonKeyDown,\n\t\t},\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isGestureActive || isKeyboardPanning || isZooming,\n\t};\n}\n"],"mappings":";;;;AAwDA,MAAM,+BAA+B;AAErC,SAAS,qBAAsB,OAAgC;CAC9D,QAAS,MAAM,KAAf;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,cACJ,OAAO;EACR,SACC,OAAO;CACT;AACD;AAEA,SAAS,sBAAuB,OAAgC;CAC/D,QAAS,MAAM,KAAf;EACC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,KACJ,OAAO;EACR,SACC,OAAO;CACT;AACD;;;;;;;;;;;;;;;;AAiBA,SAAgB,eACf,OACA,SACA,eACA,WACA,SACuB;CACvB,MAAM,CAAE,YAAY,iBAAkB,SAAU,KAAM;CACtD,MAAM,CAAE,WAAW,gBAAiB,SAAU,KAAM;CACpD,MAAM,CAAE,iBAAiB,sBAAuB,SAAU,KAAM;CAChE,MAAM,CAAE,mBAAmB,wBAAyB,SAAU,KAAM;CACpE,MAAM,8BAA8B,OAEjC,KAAA,CAAU;CAGb,MAAM,6BAA6B,OAAQ,KAAM;CAIjD,MAAM,WAAW,OAAQ,KAAM;CAC/B,SAAS,UAAU;CACnB,MAAM,mBAAmB,OAAQ,aAAc;CAC/C,iBAAiB,UAAU;CAC3B,MAAM,eAAe,OAAQ,SAAU;CACvC,aAAa,UAAU;CACvB,MAAM,aAAa,OAAQ,OAAQ;CACnC,WAAW,UAAU;CACrB,MAAM,aAAa,OAAQ,OAAQ;CACnC,WAAW,UAAU;CAErB,MAAM,gBAAgB,OAAwC,IAAK;CACnE,MAAM,wBAAwB,kBAAmB;EAChD,mBAAoB,IAAK;CAC1B,GAAG,CAAC,CAAE;CACN,MAAM,uBAAuB,kBAAmB;EAC/C,mBAAoB,KAAM;CAC3B,GAAG,CAAC,CAAE;CAGN,MAAM,wBAAwB,kBAAmB;EAChD,IAAK,CAAE,2BAA2B,SAAU;GAC3C,2BAA2B,UAAU;GACrC,WAAW,SAAS,iBAAiB;EACtC;EACA,aAAc,4BAA4B,OAAQ;EAClD,4BAA4B,UAAU,iBAAkB;GACvD,2BAA2B,UAAU;GACrC,qBAAsB,KAAM;GAC5B,WAAW,SAAS,eAAe;EACpC,GAAG,4BAA6B;CACjC,GAAG,CAAC,CAAE;CAEN,gBAAiB;EAChB,aAAa;GACZ,aAAc,4BAA4B,OAAQ;EACnD;CACD,GAAG,CAAC,CAAE;CAIN,gBAAiB;EAChB,MAAM,aAAa,IAAI,sBAAuB;GAC7C,gBAAgB,SAAS;GACzB,SAAS;IACR,SAAU,QAAS,WAAW,QAAQ,OAAQ,GAAI;IAClD,UAAW,SAAU,WAAW,QAAQ,QAAS,IAAK;IACtD,iBAAkB,MAAM,QACvB,WAAW,QAAQ,eAAgB,MAAM,GAAI;IAC9C,eAAgB,cACf,WAAW,QAAQ,aAAc,SAAU;IAC5C,aAAc,cACb,WAAW,QAAQ,aAAc,SAAU;GAC7C;GACA,wBAAwB,iBAAiB;GACzC,oBAAoB,aAAa;GACjC,IAAI,UAAU;IACb,OAAO,WAAW,SAAS;GAC5B;GACA,IAAI,UAAU;IACb,OAAO,WAAW,SAAS;GAC5B;GACA,IAAI,YAAY;IACf,OAAO,WAAW,SAAS;GAC5B;GACA,IAAI,eAAe;IAClB,OAAO,WAAW,SAAS;GAC5B;GACA,IAAI,gBAAgB;IACnB,OAAO,WAAW,SAAS;GAC5B;GACA,sBAAsB;IACrB,sBAAsB;IACtB,WAAW,SAAS,iBAAiB;GACtC;GACA,oBAAoB;IACnB,qBAAqB;IACrB,WAAW,SAAS,eAAe;GACpC;GACA,iBAAkB,WAAY;IAC7B,cAAe,OAAO,UAAW;IACjC,aAAc,OAAO,SAAU;GAChC;EACD,CAAE;EACF,cAAc,UAAU;EACxB,aAAa;GACZ,WAAW,QAAQ;GACnB,cAAc,UAAU;EACzB;CACD,GAAG,CAAE,uBAAuB,oBAAqB,CAAE;CAWnD,MAAM,aAAa,SAAS,YAAY;CACxC,gBAAiB;EAChB,IAAK,CAAE,YACN;EAED,cAAc,SAAS,QAAQ;EAC/B,cAAe,KAAM;EACrB,aAAc,KAAM;EACpB,qBAAsB,KAAM;EAC5B,MAAM,iBACL,mBAAmB,2BAA2B;EAC/C,IAAK,2BAA2B,SAAU;GACzC,2BAA2B,UAAU;GACrC,aAAc,4BAA4B,OAAQ;EACnD;EACA,qBAAqB;EACrB,IAAK,gBACJ,WAAW,SAAS,eAAe;CAErC,GAAG;EAAE;EAAY;EAAiB;CAAqB,CAAE;CAEzD,MAAM,gBAAgB,aAAe,MAA2B;EAC/D,IAAK,WAAW,SAAS,UACxB;EAED,MAAM,KAAK,EAAE;EACb,cAAc,SAAS,kBAAmB,EAAE,aAAa,EAAG;CAC7D,GAAG,CAAC,CAAE;CAEN,MAAM,eAAe,aAAe,MAAyB;EAC5D,IAAK,WAAW,SAAS,UACxB;EAED,MAAM,KAAK,EAAE;EACb,MAAM,OAAO,GAAG,sBAAsB;EACtC,cAAc,SAAS,iBACtB,EAAE,aACF,MACA,GAAG,aACJ;CACD,GAAG,CAAC,CAAE;CAEN,MAAM,YAAY,aACf,MAA4B;EAC7B,IAAK,WAAW,SAAS,UACxB;EAED,IAAK,qBAAsB,EAAE,WAAY,GAAI;GAC5C,qBAAsB,IAAK;GAC3B,sBAAsB;EACvB,OAAO,IAAK,sBAAuB,EAAE,WAAY,GAChD,sBAAsB;EAEvB,cAAc,SAAS,cAAe,EAAE,WAAY;CACrD,GACA,CAAE,qBAAsB,CACzB;CAEA,MAAM,gBAAgB,aAAe,MAAmB;EACvD,IAAK,WAAW,SAAS,UACxB;EAED,cAAc,SAAS,YAAa,CAAE;CACvC,GAAG,CAAC,CAAE;CAEN,OAAO;EACN,UAAU;GACT;GACA;GACA;EACD;EACA;EACA;EACA;EACA,mBAAmB,mBAAmB,qBAAqB;CAC5D;AACD"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "@wordpress/element";
|
|
2
|
-
import { computeTransformStyle } from "../../core/transform-style.mjs";
|
|
3
|
-
// packages/media-editor/src/image-editor/react/hooks/use-transform-style.ts
|
|
4
|
-
/**
|
|
5
|
-
* React hook that computes a memoized CSS matrix() transform string
|
|
6
|
-
* from the cropper state.
|
|
7
|
-
*
|
|
8
|
-
* Delegates to the pure `computeTransformStyle` function in core.
|
|
9
|
-
*
|
|
10
|
-
* @param state The current cropper state.
|
|
11
|
-
* @param imageSize The rendered image dimensions in pixels.
|
|
12
|
-
* @return A CSS transform string.
|
|
13
|
-
*/
|
|
14
|
-
function useTransformStyle(state, imageSize) {
|
|
15
|
-
return useMemo(() => computeTransformStyle(state, imageSize), [state, imageSize]);
|
|
16
|
-
}
|
|
17
|
-
export { useTransformStyle };
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=use-transform-style.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-transform-style.mjs","names":[],"sources":["../../../../src/image-editor/react/hooks/use-transform-style.ts"],"sourcesContent":["import { useMemo } from '@wordpress/element';\nimport type { CropperState, Size } from '../../core/types';\nimport { computeTransformStyle } from '../../core/transform-style';\n\n/**\n * React hook that computes a memoized CSS matrix() transform string\n * from the cropper state.\n *\n * Delegates to the pure `computeTransformStyle` function in core.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function useTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\treturn useMemo(\n\t\t() => computeTransformStyle( state, imageSize ),\n\t\t[ state, imageSize ]\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,kBACf,OACA,WACS;CACT,OAAO,cACA,sBAAuB,OAAO,SAAU,GAC9C,CAAE,OAAO,SAAU,CACpB;AACD"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useReducer } from "@wordpress/element";
|
|
2
|
-
import { DEFAULT_VIEWPORT_STATE, viewportReducer } from "../../core/viewport-state.mjs";
|
|
3
|
-
// packages/media-editor/src/image-editor/react/hooks/use-viewport-state.ts
|
|
4
|
-
function useViewportState() {
|
|
5
|
-
const [viewport, dispatch] = useReducer(viewportReducer, DEFAULT_VIEWPORT_STATE);
|
|
6
|
-
const setViewportZoom = useCallback((zoom) => {
|
|
7
|
-
dispatch({
|
|
8
|
-
type: "SET_VIEWPORT_ZOOM",
|
|
9
|
-
payload: zoom
|
|
10
|
-
});
|
|
11
|
-
}, []);
|
|
12
|
-
const setViewportPan = useCallback((pan) => {
|
|
13
|
-
dispatch({
|
|
14
|
-
type: "SET_VIEWPORT_PAN",
|
|
15
|
-
payload: pan
|
|
16
|
-
});
|
|
17
|
-
}, []);
|
|
18
|
-
const resetViewport = useCallback(() => {
|
|
19
|
-
dispatch({ type: "RESET_VIEWPORT" });
|
|
20
|
-
}, []);
|
|
21
|
-
return useMemo(() => ({
|
|
22
|
-
viewport,
|
|
23
|
-
setViewportZoom,
|
|
24
|
-
setViewportPan,
|
|
25
|
-
resetViewport
|
|
26
|
-
}), [
|
|
27
|
-
viewport,
|
|
28
|
-
setViewportZoom,
|
|
29
|
-
setViewportPan,
|
|
30
|
-
resetViewport
|
|
31
|
-
]);
|
|
32
|
-
}
|
|
33
|
-
export { useViewportState };
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=use-viewport-state.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-viewport-state.mjs","names":[],"sources":["../../../../src/image-editor/react/hooks/use-viewport-state.ts"],"sourcesContent":["import { useReducer, useCallback, useMemo } from '@wordpress/element';\nimport type { ViewportState } from '../../core/types';\nimport {\n\tviewportReducer,\n\tDEFAULT_VIEWPORT_STATE,\n} from '../../core/viewport-state';\n\nexport interface UseViewportStateReturn {\n\tviewport: ViewportState;\n\t/**\n\t * Unused in the current Cropper implementation — scaffolded for the\n\t * upcoming navigator panel (viewport zoom slider).\n\t */\n\tsetViewportZoom: ( zoom: number ) => void;\n\tsetViewportPan: ( pan: { x: number; y: number } ) => void;\n\tresetViewport: () => void;\n}\n\nexport function useViewportState(): UseViewportStateReturn {\n\tconst [ viewport, dispatch ] = useReducer(\n\t\tviewportReducer,\n\t\tDEFAULT_VIEWPORT_STATE\n\t);\n\n\tconst setViewportZoom = useCallback( ( zoom: number ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_ZOOM', payload: zoom } );\n\t}, [] );\n\n\tconst setViewportPan = useCallback( ( pan: { x: number; y: number } ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_PAN', payload: pan } );\n\t}, [] );\n\n\tconst resetViewport = useCallback( () => {\n\t\tdispatch( { type: 'RESET_VIEWPORT' } );\n\t}, [] );\n\n\treturn useMemo(\n\t\t() => ( { viewport, setViewportZoom, setViewportPan, resetViewport } ),\n\t\t[ viewport, setViewportZoom, setViewportPan, resetViewport ]\n\t);\n}\n"],"mappings":";;;AAkBA,SAAgB,mBAA2C;CAC1D,MAAM,CAAE,UAAU,YAAa,WAC9B,iBACA,sBACD;CAEA,MAAM,kBAAkB,aAAe,SAAkB;EACxD,SAAU;GAAE,MAAM;GAAqB,SAAS;EAAK,CAAE;CACxD,GAAG,CAAC,CAAE;CAEN,MAAM,iBAAiB,aAAe,QAAmC;EACxE,SAAU;GAAE,MAAM;GAAoB,SAAS;EAAI,CAAE;CACtD,GAAG,CAAC,CAAE;CAEN,MAAM,gBAAgB,kBAAmB;EACxC,SAAU,EAAE,MAAM,iBAAiB,CAAE;CACtC,GAAG,CAAC,CAAE;CAEN,OAAO,eACE;EAAE;EAAU;EAAiB;EAAgB;CAAc,IACnE;EAAE;EAAU;EAAiB;EAAgB;CAAc,CAC5D;AACD"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// packages/media-editor/src/image-editor/react/visually-hidden-style.ts
|
|
2
|
-
/**
|
|
3
|
-
* CSS style object that visually hides an element while keeping it accessible
|
|
4
|
-
* to screen readers.
|
|
5
|
-
*/
|
|
6
|
-
const VISUALLY_HIDDEN_STYLE = {
|
|
7
|
-
position: "absolute",
|
|
8
|
-
width: 1,
|
|
9
|
-
height: 1,
|
|
10
|
-
padding: 0,
|
|
11
|
-
margin: -1,
|
|
12
|
-
overflow: "hidden",
|
|
13
|
-
clip: "rect(0, 0, 0, 0)",
|
|
14
|
-
whiteSpace: "nowrap",
|
|
15
|
-
border: 0
|
|
16
|
-
};
|
|
17
|
-
export { VISUALLY_HIDDEN_STYLE };
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=visually-hidden-style.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visually-hidden-style.mjs","names":[],"sources":["../../../src/image-editor/react/visually-hidden-style.ts"],"sourcesContent":["/**\n * CSS style object that visually hides an element while keeping it accessible\n * to screen readers.\n */\nexport const VISUALLY_HIDDEN_STYLE: React.CSSProperties = {\n\tposition: 'absolute',\n\twidth: 1,\n\theight: 1,\n\tpadding: 0,\n\tmargin: -1,\n\toverflow: 'hidden',\n\tclip: 'rect(0, 0, 0, 0)',\n\twhiteSpace: 'nowrap',\n\tborder: 0,\n};\n"],"mappings":";;;;;AAIA,MAAa,wBAA6C;CACzD,UAAU;CACV,OAAO;CACP,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,UAAU;CACV,MAAM;CACN,YAAY;CACZ,QAAQ;AACT"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { CropperController } from '../../image-editor';
|
|
2
|
-
/**
|
|
3
|
-
* A single modifier in the Core REST `/edit` payload. Order is
|
|
4
|
-
* significant — the server applies modifiers sequentially (see
|
|
5
|
-
* `WP_REST_Attachments_Controller::edit_media_item`).
|
|
6
|
-
*
|
|
7
|
-
* Shape/units:
|
|
8
|
-
* - `flip`: booleans per axis. Applied first in this module's output.
|
|
9
|
-
* - `rotate`: `angle` in degrees, clockwise-positive (matches the
|
|
10
|
-
* cropper's own convention; Core negates it internally for
|
|
11
|
-
* `WP_Image_Editor::rotate`, which is counterclockwise-positive).
|
|
12
|
-
* - `crop`: percentages (0–100) of the image's dimensions **at the
|
|
13
|
-
* moment the crop is applied**. Because modifiers are applied in
|
|
14
|
-
* order, after a preceding `rotate` the server's
|
|
15
|
-
* `WP_Image_Editor::get_size()` reports the full post-rotate AABB,
|
|
16
|
-
* so the percentages are of that AABB. Origin is top-left.
|
|
17
|
-
*/
|
|
18
|
-
export type Modifier = {
|
|
19
|
-
type: 'flip';
|
|
20
|
-
args: {
|
|
21
|
-
flip: {
|
|
22
|
-
horizontal: boolean;
|
|
23
|
-
vertical: boolean;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
} | {
|
|
27
|
-
type: 'rotate';
|
|
28
|
-
args: {
|
|
29
|
-
angle: number;
|
|
30
|
-
};
|
|
31
|
-
} | {
|
|
32
|
-
type: 'crop';
|
|
33
|
-
args: {
|
|
34
|
-
left: number;
|
|
35
|
-
top: number;
|
|
36
|
-
width: number;
|
|
37
|
-
height: number;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Build a Core-compatible modifiers array from the cropper state.
|
|
42
|
-
*
|
|
43
|
-
* Emits `[flip, rotate, crop]` in that order. Identity operations are
|
|
44
|
-
* pruned — an absent flip, a rotation that normalizes to 0°, and a crop
|
|
45
|
-
* rect that covers (within tolerance) the full post-rotate AABB each
|
|
46
|
-
* produce no modifier. An identity state (fresh image, no edits) returns
|
|
47
|
-
* an empty array; callers can use that to skip the `/edit` call.
|
|
48
|
-
*
|
|
49
|
-
* Frames and math:
|
|
50
|
-
*
|
|
51
|
-
* The cropper's `cropRect` is stored as fractions of the **snap-rotation**
|
|
52
|
-
* bounding box (the stencil-reference frame — see `createCamera` /
|
|
53
|
-
* `createExportCamera`). Pan is in that frame; zoom scales the image
|
|
54
|
-
* beneath a fixed stencil. Two conversions are needed to reach the frame
|
|
55
|
-
* Core's crop modifier applies against:
|
|
56
|
-
*
|
|
57
|
-
* 1. Express the stencil rect in snap-AABB **pixels**:
|
|
58
|
-
* Image screen-normalized top-left with zoom/pan is
|
|
59
|
-
* `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the
|
|
60
|
-
* inverse of that transform applied to `cropRect`.
|
|
61
|
-
*
|
|
62
|
-
* 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs
|
|
63
|
-
* share the source-image center, so the conversion is a pure
|
|
64
|
-
* translation by `(fullCenter - snapCenter)`. Finally, express the
|
|
65
|
-
* translated rect as percentages of the full AABB.
|
|
66
|
-
*
|
|
67
|
-
* Rotation sign: the cropper composes `flip · R(θ)` on the source (see
|
|
68
|
-
* `createExportCamera` — rotate then flip). Core's `[flip, rotate]`
|
|
69
|
-
* applies the opposite order: `R(θ') · flip`. For both to land on the
|
|
70
|
-
* same pixels we invert the rotation sign when exactly one flip axis
|
|
71
|
-
* is set (`flip_h · R(θ) = R(-θ) · flip_h`). Both-or-neither flips
|
|
72
|
-
* leave the sign alone because `flip_h · flip_v = -I` commutes with
|
|
73
|
-
* rotation.
|
|
74
|
-
*
|
|
75
|
-
* @param cropper The cropper controller. The current edit and the loaded
|
|
76
|
-
* image's natural size are both read from its state.
|
|
77
|
-
* @return Ordered modifier array; empty when nothing is server-relevant or
|
|
78
|
-
* no image has loaded.
|
|
79
|
-
*/
|
|
80
|
-
export declare function buildModifiers(cropper: Pick<CropperController, 'state'>): Modifier[];
|
|
81
|
-
//# sourceMappingURL=build-modifiers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-modifiers.d.ts","sourceRoot":"","sources":["../../../src/components/media-editor-modal/build-modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAG5D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,QAAQ,GACjB;IACA,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QAAE,IAAI,EAAE;YAAE,UAAU,EAAE,OAAO,CAAC;YAAC,QAAQ,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAC;CAC1D,GACD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAC3C;IACA,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE,CAAC;AAUL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,cAAc,CAC7B,OAAO,EAAE,IAAI,CAAE,iBAAiB,EAAE,OAAO,CAAE,GACzC,QAAQ,EAAE,CAsFZ"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { CropperState, NormalizedPoint, NormalizedRect, Size, Camera } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Compute the axis-aligned bounding box of a rectangle after rotation.
|
|
4
|
-
*
|
|
5
|
-
* @param width The width of the rectangle.
|
|
6
|
-
* @param height The height of the rectangle.
|
|
7
|
-
* @param rotation The rotation angle in degrees.
|
|
8
|
-
* @return The bounding box size after rotation.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getRotatedBBox(width: number, height: number, rotation: number): Size;
|
|
11
|
-
/**
|
|
12
|
-
* Compute the fitted (unrotated) image element dimensions and the visual
|
|
13
|
-
* (rotated) bounding box dimensions for a given container, image, and rotation.
|
|
14
|
-
*
|
|
15
|
-
* This is the same "contain" fit logic used by createCamera, extracted so
|
|
16
|
-
* cropper.tsx can size the <img> element and position overlays without
|
|
17
|
-
* duplicating the math.
|
|
18
|
-
*
|
|
19
|
-
* @param containerSize The container dimensions in pixels.
|
|
20
|
-
* @param imageSize The natural image dimensions in pixels.
|
|
21
|
-
* @param rotation The rotation angle in degrees.
|
|
22
|
-
* @return The fitted element size and visual bounding box size.
|
|
23
|
-
*/
|
|
24
|
-
export declare function getImageFit(containerSize: Size, imageSize: Size, rotation: number): {
|
|
25
|
-
elementSize: Size;
|
|
26
|
-
visualSize: Size;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Resolve the presentational view magnification that makes the crop fill the
|
|
30
|
-
* canvas.
|
|
31
|
-
*
|
|
32
|
-
* The crop overlay is laid out as `cropRect * visualSize` (the contain-fit
|
|
33
|
-
* footprint, with no zoom), so its on-screen size is capped by that footprint.
|
|
34
|
-
* When a crop's aspect differs from the image's, it can be much smaller than
|
|
35
|
-
* the canvas could show (e.g. a square crop in a tall image is bound by the
|
|
36
|
-
* footprint's narrow axis). Scaling `elementSize` and `visualSize` together by
|
|
37
|
-
* the returned factor uniformly magnifies the whole scene — image, crop
|
|
38
|
-
* overlay, and overlays — so the crop reaches `targetFill` of its constraining
|
|
39
|
-
* canvas axis, with the image bleeding past the canvas (clipped by the host).
|
|
40
|
-
*
|
|
41
|
-
* Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,
|
|
42
|
-
* so the framed source region — and therefore the export — is unchanged.
|
|
43
|
-
*
|
|
44
|
-
* @param cropRect The crop rectangle, normalized to the footprint.
|
|
45
|
-
* @param canvasSize The canvas size in pixels.
|
|
46
|
-
* @param visualSize The contain-fit (rotated) image footprint in pixels.
|
|
47
|
-
* @param targetFill Fraction of the constraining canvas axis to fill (0–1].
|
|
48
|
-
* @param maxScale Upper bound on the magnification.
|
|
49
|
-
* @return A magnification factor in [1, maxScale]; 1 when none is needed.
|
|
50
|
-
*/
|
|
51
|
-
export declare function getViewScale(cropRect: NormalizedRect, canvasSize: Size, visualSize: Size, targetFill: number, maxScale: number): number;
|
|
52
|
-
/**
|
|
53
|
-
* Compose a camera matrix from cropper state, container, and image dimensions.
|
|
54
|
-
*
|
|
55
|
-
* The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.
|
|
56
|
-
* Input (0,0) = image top-left, (1,1) = image bottom-right.
|
|
57
|
-
*
|
|
58
|
-
* Composition order (left-to-right = outermost first, applied last to point):
|
|
59
|
-
* M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels
|
|
60
|
-
*
|
|
61
|
-
* Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`
|
|
62
|
-
* are viewport-relative: the image mirrors across the viewport's vertical /
|
|
63
|
-
* horizontal axis regardless of current rotation.
|
|
64
|
-
*
|
|
65
|
-
* @param state The current cropper state (zoom, rotation, flip, crop).
|
|
66
|
-
* @param containerSize The size of the container in pixels.
|
|
67
|
-
* @param imageSize The natural size of the image in pixels.
|
|
68
|
-
* @return The composed camera matrix.
|
|
69
|
-
*/
|
|
70
|
-
export declare function createCamera(state: CropperState, containerSize: Size, imageSize: Size): Camera;
|
|
71
|
-
/**
|
|
72
|
-
* Transform a normalized world point [0,1] to screen pixels.
|
|
73
|
-
*
|
|
74
|
-
* @param camera The camera matrix from createCamera.
|
|
75
|
-
* @param point The normalized world coordinate to transform.
|
|
76
|
-
* @return The screen pixel coordinate.
|
|
77
|
-
*/
|
|
78
|
-
export declare function worldToScreen(camera: Camera, point: NormalizedPoint): {
|
|
79
|
-
x: number;
|
|
80
|
-
y: number;
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Transform a screen pixel point to normalized world coordinates [0,1].
|
|
84
|
-
*
|
|
85
|
-
* @param camera The camera matrix from createCamera.
|
|
86
|
-
* @param point The screen pixel coordinate to transform.
|
|
87
|
-
* @param point.x The x component of the screen pixel coordinate.
|
|
88
|
-
* @param point.y The y component of the screen pixel coordinate.
|
|
89
|
-
* @return The normalized world coordinate.
|
|
90
|
-
*/
|
|
91
|
-
export declare function screenToWorld(camera: Camera, point: {
|
|
92
|
-
x: number;
|
|
93
|
-
y: number;
|
|
94
|
-
}): NormalizedPoint;
|
|
95
|
-
/**
|
|
96
|
-
* The bounding box of a transformed region in screen (pixel) space.
|
|
97
|
-
*/
|
|
98
|
-
export interface VisualBounds {
|
|
99
|
-
left: number;
|
|
100
|
-
top: number;
|
|
101
|
-
width: number;
|
|
102
|
-
height: number;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])
|
|
106
|
-
* after applying the camera transform.
|
|
107
|
-
*
|
|
108
|
-
* @param camera The camera matrix from createCamera.
|
|
109
|
-
* @return The screen-space bounding box of the full image.
|
|
110
|
-
*/
|
|
111
|
-
export declare function getVisibleBounds(camera: Camera): VisualBounds;
|
|
112
|
-
/**
|
|
113
|
-
* Compose a camera matrix for exporting to a canvas.
|
|
114
|
-
*
|
|
115
|
-
* The resulting matrix maps image-pixel coordinates directly to output-canvas
|
|
116
|
-
* coordinates. Apply it with `ctx.setTransform( ...camera )` then
|
|
117
|
-
* `ctx.drawImage( image, 0, 0 )`.
|
|
118
|
-
*
|
|
119
|
-
* The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:
|
|
120
|
-
* translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)
|
|
121
|
-
*
|
|
122
|
-
* @param state The current cropper state.
|
|
123
|
-
* @param imageSize The natural size of the source image in pixels.
|
|
124
|
-
* @param outputSize The desired output canvas size in pixels.
|
|
125
|
-
* @return The composed export camera matrix.
|
|
126
|
-
*/
|
|
127
|
-
export declare function createExportCamera(state: CropperState, imageSize: Size, outputSize: Size): Camera;
|
|
128
|
-
//# sourceMappingURL=camera.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../../../src/image-editor/core/camera.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,YAAY,EACZ,eAAe,EACf,cAAc,EACd,IAAI,EACJ,MAAM,EACN,MAAM,SAAS,CAAC;AAcjB;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACd,IAAI,CAqBN;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAC1B,aAAa,EAAE,IAAI,EACnB,SAAS,EAAE,IAAI,EACf,QAAQ,EAAE,MAAM,GACd;IAAE,WAAW,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,IAAI,CAAA;CAAE,CAqCzC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,cAAc,EACxB,UAAU,EAAE,IAAI,EAChB,UAAU,EAAE,IAAI,EAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,MAAM,CAsBR;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,YAAY,EACnB,aAAa,EAAE,IAAI,EACnB,SAAS,EAAE,IAAI,GACb,MAAM,CAgFR;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,GACpB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAI1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7B,eAAe,CAKjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf;AAsCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAE,MAAM,EAAE,MAAM,GAAI,YAAY,CAO/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,IAAI,EACf,UAAU,EAAE,IAAI,GACd,MAAM,CA2CR"}
|