@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,250 +0,0 @@
|
|
|
1
|
-
import type { CropperState } from '../types';
|
|
2
|
-
import { createExportCamera, getRotatedBBox } from '../camera';
|
|
3
|
-
|
|
4
|
-
/** Default export quality for lossy formats (JPEG, WebP). */
|
|
5
|
-
const DEFAULT_QUALITY = 0.92;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Load an image from a URL with CORS support.
|
|
9
|
-
*
|
|
10
|
-
* @param src - The image URL to load.
|
|
11
|
-
* @return A promise that resolves to the loaded HTMLImageElement.
|
|
12
|
-
*/
|
|
13
|
-
export function loadImage( src: string ): Promise< HTMLImageElement > {
|
|
14
|
-
return new Promise( ( resolve, reject ) => {
|
|
15
|
-
const image = new Image();
|
|
16
|
-
image.addEventListener( 'load', () => resolve( image ) );
|
|
17
|
-
image.addEventListener( 'error', ( error ) => reject( error ) );
|
|
18
|
-
image.crossOrigin = 'anonymous';
|
|
19
|
-
image.src = src;
|
|
20
|
-
} );
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Apply rectangular crop, rotation, and flip transforms to produce a canvas.
|
|
25
|
-
*
|
|
26
|
-
* Uses createExportCamera to compose the full transform matrix, then applies
|
|
27
|
-
* it in a single ctx.setTransform call before drawing the image.
|
|
28
|
-
*
|
|
29
|
-
* @param image - The source image element.
|
|
30
|
-
* @param state - The full cropper state containing crop, rotation, and flip settings.
|
|
31
|
-
* @return A canvas element containing the transformed and cropped image.
|
|
32
|
-
*/
|
|
33
|
-
export function renderToCanvas(
|
|
34
|
-
image: HTMLImageElement,
|
|
35
|
-
state: CropperState
|
|
36
|
-
): HTMLCanvasElement {
|
|
37
|
-
const { naturalWidth, naturalHeight } = image;
|
|
38
|
-
const { rotation, cropRect } = state;
|
|
39
|
-
const imageSize = { width: naturalWidth, height: naturalHeight };
|
|
40
|
-
|
|
41
|
-
// Output size is the crop region in the snap-rotation bbox — matches
|
|
42
|
-
// the preview's reference frame so the exported pixels track exactly
|
|
43
|
-
// what the stencil framed, even at fine rotation angles.
|
|
44
|
-
const snapRotation = Math.round( rotation / 90 ) * 90;
|
|
45
|
-
const rotBBox = getRotatedBBox( naturalWidth, naturalHeight, snapRotation );
|
|
46
|
-
const outW = Math.round( cropRect.width * rotBBox.width );
|
|
47
|
-
const outH = Math.round( cropRect.height * rotBBox.height );
|
|
48
|
-
|
|
49
|
-
const canvas = document.createElement( 'canvas' );
|
|
50
|
-
canvas.width = outW;
|
|
51
|
-
canvas.height = outH;
|
|
52
|
-
const ctx = canvas.getContext( '2d' );
|
|
53
|
-
if ( ! ctx ) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
'Could not obtain a 2D context for the export canvas.'
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const camera = createExportCamera( state, imageSize, {
|
|
60
|
-
width: outW,
|
|
61
|
-
height: outH,
|
|
62
|
-
} );
|
|
63
|
-
ctx.setTransform(
|
|
64
|
-
camera[ 0 ],
|
|
65
|
-
camera[ 1 ],
|
|
66
|
-
camera[ 2 ],
|
|
67
|
-
camera[ 3 ],
|
|
68
|
-
camera[ 4 ],
|
|
69
|
-
camera[ 5 ]
|
|
70
|
-
);
|
|
71
|
-
ctx.drawImage( image, 0, 0 );
|
|
72
|
-
return canvas;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Convert a canvas to a Blob with configurable MIME type and quality.
|
|
77
|
-
*
|
|
78
|
-
* @param canvas - The canvas to export.
|
|
79
|
-
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
80
|
-
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
81
|
-
* @return A promise that resolves to the canvas content as a Blob.
|
|
82
|
-
*/
|
|
83
|
-
export function canvasToBlob(
|
|
84
|
-
canvas: HTMLCanvasElement,
|
|
85
|
-
mimeType: string = 'image/png',
|
|
86
|
-
quality: number = DEFAULT_QUALITY
|
|
87
|
-
): Promise< Blob > {
|
|
88
|
-
return new Promise( ( resolve, reject ) => {
|
|
89
|
-
canvas.toBlob(
|
|
90
|
-
( blob ) => {
|
|
91
|
-
if ( blob ) {
|
|
92
|
-
resolve( blob );
|
|
93
|
-
} else {
|
|
94
|
-
reject( new Error( 'Canvas toBlob returned null.' ) );
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
mimeType,
|
|
98
|
-
quality
|
|
99
|
-
);
|
|
100
|
-
} );
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Convert a canvas to a data URL string.
|
|
105
|
-
*
|
|
106
|
-
* @param canvas - The canvas to export.
|
|
107
|
-
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
108
|
-
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
109
|
-
* @return The canvas content as a data URL string.
|
|
110
|
-
*/
|
|
111
|
-
export function canvasToDataURL(
|
|
112
|
-
canvas: HTMLCanvasElement,
|
|
113
|
-
mimeType: string = 'image/png',
|
|
114
|
-
quality: number = DEFAULT_QUALITY
|
|
115
|
-
): string {
|
|
116
|
-
return canvas.toDataURL( mimeType, quality );
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Load an image, render with transforms, and export as a Blob.
|
|
121
|
-
*
|
|
122
|
-
* Throws on failure so callers can distinguish error cases:
|
|
123
|
-
* - Image load failures (network errors, 404s) throw the native
|
|
124
|
-
* load error from the Image element.
|
|
125
|
-
* - Cross-origin failures manifest as tainted-canvas errors from
|
|
126
|
-
* `canvas.toBlob()` — the browser rejects reading pixel data
|
|
127
|
-
* from a canvas that drew an image without valid CORS headers.
|
|
128
|
-
* Ensure the source server sets `Access-Control-Allow-Origin`.
|
|
129
|
-
* - Canvas context creation failures throw a descriptive Error.
|
|
130
|
-
*
|
|
131
|
-
* Only works in browser environments (needs DOM / HTMLCanvasElement).
|
|
132
|
-
*
|
|
133
|
-
* @param src - The image URL to load.
|
|
134
|
-
* @param state - The cropper state with all transform settings.
|
|
135
|
-
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
136
|
-
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
137
|
-
* @return A promise that resolves to the exported Blob.
|
|
138
|
-
* @throws If the image fails to load, canvas creation fails, or
|
|
139
|
-
* the resulting canvas is tainted by CORS restrictions.
|
|
140
|
-
*/
|
|
141
|
-
export async function exportCroppedImage(
|
|
142
|
-
src: string,
|
|
143
|
-
state: CropperState,
|
|
144
|
-
mimeType: string = 'image/png',
|
|
145
|
-
quality: number = DEFAULT_QUALITY
|
|
146
|
-
): Promise< Blob > {
|
|
147
|
-
const image = await loadImage( src );
|
|
148
|
-
const canvas = renderToCanvas( image, state );
|
|
149
|
-
return canvasToBlob( canvas, mimeType, quality );
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Apply the cropper's transform (crop, rotation, flip, zoom) to an existing
|
|
154
|
-
* canvas or image source. This is the bridge for multi-step editing pipelines
|
|
155
|
-
* where an upstream tool (e.g., brightness/color adjustment) has already
|
|
156
|
-
* processed the image and you want to apply the crop on top.
|
|
157
|
-
*
|
|
158
|
-
* Accepts any CanvasImageSource: HTMLImageElement, HTMLCanvasElement,
|
|
159
|
-
* OffscreenCanvas, ImageBitmap, HTMLVideoElement, etc.
|
|
160
|
-
*
|
|
161
|
-
* @param source - The image source to crop/transform.
|
|
162
|
-
* @param sourceSize - The dimensions of the source (natural width/height).
|
|
163
|
-
* @param sourceSize.width - The width of the source in pixels.
|
|
164
|
-
* @param sourceSize.height - The height of the source in pixels.
|
|
165
|
-
* @param state - The cropper state with all transform settings.
|
|
166
|
-
* @param outputSize - Optional output size. Defaults to the crop region's natural pixel size.
|
|
167
|
-
* @param outputSize.width - The width of the output in pixels.
|
|
168
|
-
* @param outputSize.height - The height of the output in pixels.
|
|
169
|
-
* @return A canvas with the transforms applied.
|
|
170
|
-
*/
|
|
171
|
-
export function applyToCanvas(
|
|
172
|
-
source: CanvasImageSource,
|
|
173
|
-
sourceSize: { width: number; height: number },
|
|
174
|
-
state: CropperState,
|
|
175
|
-
outputSize?: { width: number; height: number }
|
|
176
|
-
): HTMLCanvasElement {
|
|
177
|
-
// Use snap-rotation bbox for default sizing so the default output
|
|
178
|
-
// matches the preview's reference frame at fine rotation angles
|
|
179
|
-
// (see renderToCanvas / createExportCamera).
|
|
180
|
-
const snapRotation = Math.round( state.rotation / 90 ) * 90;
|
|
181
|
-
const rotBBox = getRotatedBBox(
|
|
182
|
-
sourceSize.width,
|
|
183
|
-
sourceSize.height,
|
|
184
|
-
snapRotation
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
// Default output size: the crop region in natural pixels.
|
|
188
|
-
const outW =
|
|
189
|
-
outputSize?.width ?? Math.round( state.cropRect.width * rotBBox.width );
|
|
190
|
-
const outH =
|
|
191
|
-
outputSize?.height ??
|
|
192
|
-
Math.round( state.cropRect.height * rotBBox.height );
|
|
193
|
-
|
|
194
|
-
const canvas = document.createElement( 'canvas' );
|
|
195
|
-
canvas.width = outW;
|
|
196
|
-
canvas.height = outH;
|
|
197
|
-
const ctx = canvas.getContext( '2d' );
|
|
198
|
-
if ( ! ctx ) {
|
|
199
|
-
throw new Error(
|
|
200
|
-
'Could not obtain a 2D context for the export canvas.'
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const camera = createExportCamera( state, sourceSize, {
|
|
205
|
-
width: outW,
|
|
206
|
-
height: outH,
|
|
207
|
-
} );
|
|
208
|
-
ctx.setTransform(
|
|
209
|
-
camera[ 0 ],
|
|
210
|
-
camera[ 1 ],
|
|
211
|
-
camera[ 2 ],
|
|
212
|
-
camera[ 3 ],
|
|
213
|
-
camera[ 4 ],
|
|
214
|
-
camera[ 5 ]
|
|
215
|
-
);
|
|
216
|
-
ctx.drawImage( source, 0, 0 );
|
|
217
|
-
return canvas;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Download the cropped image as a file.
|
|
222
|
-
*
|
|
223
|
-
* Loads the source image, applies all transforms, and triggers a
|
|
224
|
-
* browser download via exportCroppedImage() + object URL + anchor click.
|
|
225
|
-
*
|
|
226
|
-
* Throws on export failure (see `exportCroppedImage`).
|
|
227
|
-
*
|
|
228
|
-
* @param src - The image URL to load.
|
|
229
|
-
* @param state - The cropper state with all transform settings.
|
|
230
|
-
* @param filename - The download filename. Defaults to 'cropped-image'.
|
|
231
|
-
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
232
|
-
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
233
|
-
* @return A promise that resolves when the download is triggered.
|
|
234
|
-
*/
|
|
235
|
-
export async function downloadCroppedImage(
|
|
236
|
-
src: string,
|
|
237
|
-
state: CropperState,
|
|
238
|
-
filename: string = 'cropped-image',
|
|
239
|
-
mimeType: string = 'image/png',
|
|
240
|
-
quality: number = DEFAULT_QUALITY
|
|
241
|
-
): Promise< void > {
|
|
242
|
-
const blob = await exportCroppedImage( src, state, mimeType, quality );
|
|
243
|
-
const ext = mimeType.split( '/' )[ 1 ] ?? 'png';
|
|
244
|
-
const url = URL.createObjectURL( blob );
|
|
245
|
-
const a = document.createElement( 'a' );
|
|
246
|
-
a.href = url;
|
|
247
|
-
a.download = `${ filename }.${ ext }`;
|
|
248
|
-
a.click();
|
|
249
|
-
URL.revokeObjectURL( url );
|
|
250
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Types
|
|
2
|
-
export type {
|
|
3
|
-
CropperState,
|
|
4
|
-
CropperAction,
|
|
5
|
-
TransformOperation,
|
|
6
|
-
NormalizedPoint,
|
|
7
|
-
NormalizedRect,
|
|
8
|
-
Size,
|
|
9
|
-
Flip,
|
|
10
|
-
StencilProps,
|
|
11
|
-
HandlePosition,
|
|
12
|
-
} from './types';
|
|
13
|
-
|
|
14
|
-
// Constants
|
|
15
|
-
export { DEFAULT_STATE, ORIGINAL_ASPECT_RATIO } from './constants';
|
|
16
|
-
export type { AspectRatioPreset } from './constants';
|
|
17
|
-
|
|
18
|
-
// Reducer + state helpers. `CropperAction` and `cropperReducer` are
|
|
19
|
-
// exported so composite stores can delegate cropper actions through the
|
|
20
|
-
// pure reducer (see `useMediaEditorState`). Most consumers should
|
|
21
|
-
// instead drive state through the named setters on `CropperController`.
|
|
22
|
-
export {
|
|
23
|
-
cropperReducer,
|
|
24
|
-
enforceContainment,
|
|
25
|
-
areCropperStatesEqual,
|
|
26
|
-
isStateDirty,
|
|
27
|
-
} from './state';
|
|
28
|
-
|
|
29
|
-
// Source region (pixel and percentage)
|
|
30
|
-
export { getSourceRegion, getSourceRegionPercent } from './source-region';
|
|
31
|
-
export type { SourceRegion, SourceRegionPercent } from './source-region';
|
|
32
|
-
|
|
33
|
-
// Crop-rect helpers
|
|
34
|
-
export { computeInscribedRect } from './crop-rect';
|
|
35
|
-
|
|
36
|
-
// Pipeline
|
|
37
|
-
export {
|
|
38
|
-
applyOperationToState,
|
|
39
|
-
stateFromPipeline,
|
|
40
|
-
} from './transforms/pipeline';
|
|
41
|
-
|
|
42
|
-
// Export / canvas
|
|
43
|
-
export { exportCroppedImage, applyToCanvas } from './export/canvas-renderer';
|