@wordpress/media-editor 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/build/components/media-editor/index.cjs +586 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +42 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +131 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +117 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +81 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +61 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +181 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +82 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +113 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +59 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +100 -113
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +22 -45
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +11 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +227 -296
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +545 -675
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +37 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +95 -98
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +171 -238
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +74 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -90
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +53 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +80 -91
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +3 -26
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +7 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +223 -288
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +145 -61
- package/build-style/style.css +144 -61
- package/build-types/components/media-editor/index.d.ts +20 -2
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/state/aspect-ratio-presets.d.ts +24 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -4
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -63
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +33 -52
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +22 -23
- package/src/components/media-editor/index.tsx +355 -167
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +9 -10
- package/src/components/media-editor/use-save-media-editor.ts +48 -10
- package/src/components/media-editor-canvas/index.tsx +30 -51
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +15 -11
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +1 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +65 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +9 -5
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/state/README.md +32 -0
- package/src/state/aspect-ratio-presets.ts +37 -0
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -17
- package/src/state/types.ts +18 -72
- package/src/state/use-media-editor-state.ts +155 -238
- package/src/style.scss +2 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
- package/build/image-editor/core/camera.cjs +0 -225
- package/build/image-editor/core/camera.cjs.map +0 -7
- package/build/image-editor/core/constants.cjs +0 -108
- package/build/image-editor/core/constants.cjs.map +0 -7
- package/build/image-editor/core/containment.cjs +0 -276
- package/build/image-editor/core/containment.cjs.map +0 -7
- package/build/image-editor/core/crop-rect.cjs +0 -48
- package/build/image-editor/core/crop-rect.cjs.map +0 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
- package/build/image-editor/core/index.cjs +0 -62
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/interaction-controller.cjs +0 -654
- package/build/image-editor/core/interaction-controller.cjs.map +0 -7
- package/build/image-editor/core/math/rotation.cjs +0 -41
- package/build/image-editor/core/math/rotation.cjs.map +0 -7
- package/build/image-editor/core/math/sanitize.cjs +0 -92
- package/build/image-editor/core/math/sanitize.cjs.map +0 -7
- package/build/image-editor/core/setter-helpers.cjs +0 -64
- package/build/image-editor/core/setter-helpers.cjs.map +0 -7
- package/build/image-editor/core/source-region.cjs +0 -206
- package/build/image-editor/core/source-region.cjs.map +0 -7
- package/build/image-editor/core/state.cjs +0 -283
- package/build/image-editor/core/state.cjs.map +0 -7
- package/build/image-editor/core/stencil-math.cjs +0 -216
- package/build/image-editor/core/stencil-math.cjs.map +0 -7
- package/build/image-editor/core/transform-style.cjs +0 -52
- package/build/image-editor/core/transform-style.cjs.map +0 -7
- package/build/image-editor/core/transforms/pipeline.cjs +0 -43
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
- package/build/image-editor/core/types.cjs +0 -19
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/core/viewport-state.cjs +0 -50
- package/build/image-editor/core/viewport-state.cjs.map +0 -7
- package/build/image-editor/index.cjs +0 -67
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/cropper-provider.cjs +0 -50
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
- package/build/image-editor/react/components/cropper.cjs +0 -722
- package/build/image-editor/react/components/cropper.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs +0 -36
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
- package/build/image-editor/react/components/viewport-provider.cjs +0 -51
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs +0 -34
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -213
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
- package/build/image-editor/react/visually-hidden-style.cjs +0 -41
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -66
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
- package/build-module/image-editor/core/camera.mjs +0 -198
- package/build-module/image-editor/core/camera.mjs.map +0 -7
- package/build-module/image-editor/core/constants.mjs +0 -69
- package/build-module/image-editor/core/constants.mjs.map +0 -7
- package/build-module/image-editor/core/containment.mjs +0 -253
- package/build-module/image-editor/core/containment.mjs.map +0 -7
- package/build-module/image-editor/core/crop-rect.mjs +0 -23
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
- package/build-module/image-editor/core/index.mjs +0 -36
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -635
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
- package/build-module/image-editor/core/math/rotation.mjs +0 -15
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
- package/build-module/image-editor/core/math/sanitize.mjs +0 -63
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
- package/build-module/image-editor/core/setter-helpers.mjs +0 -39
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
- package/build-module/image-editor/core/source-region.mjs +0 -178
- package/build-module/image-editor/core/source-region.mjs.map +0 -7
- package/build-module/image-editor/core/state.mjs +0 -260
- package/build-module/image-editor/core/state.mjs.map +0 -7
- package/build-module/image-editor/core/stencil-math.mjs +0 -187
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
- package/build-module/image-editor/core/transform-style.mjs +0 -27
- package/build-module/image-editor/core/transform-style.mjs.map +0 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/core/viewport-state.mjs +0 -24
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
- package/build-module/image-editor/index.mjs +0 -39
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper.mjs +0 -704
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs +0 -9
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs +0 -8
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -190
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -80
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -99
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -16
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -63
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -161
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -150
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -47
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -52
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1116
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import { mat2d, vec2 } from 'gl-matrix';
|
|
2
|
-
import type {
|
|
3
|
-
CropperState,
|
|
4
|
-
NormalizedPoint,
|
|
5
|
-
NormalizedRect,
|
|
6
|
-
Size,
|
|
7
|
-
Camera,
|
|
8
|
-
} from './types';
|
|
9
|
-
import { degreesToRadians } from './math/rotation';
|
|
10
|
-
import {
|
|
11
|
-
isSafeNumber,
|
|
12
|
-
isValidSize,
|
|
13
|
-
safeBoundedNumber,
|
|
14
|
-
sanitizeCropperState,
|
|
15
|
-
} from './math/sanitize';
|
|
16
|
-
|
|
17
|
-
// Pre-allocated scratch buffers for `screenToWorld`, which is called per
|
|
18
|
-
// pointermove. Module-level singletons — safe because usage is synchronous.
|
|
19
|
-
const _scratchMat = mat2d.create();
|
|
20
|
-
const _scratchVec = vec2.create();
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Compute the axis-aligned bounding box of a rectangle after rotation.
|
|
24
|
-
*
|
|
25
|
-
* @param width The width of the rectangle.
|
|
26
|
-
* @param height The height of the rectangle.
|
|
27
|
-
* @param rotation The rotation angle in degrees.
|
|
28
|
-
* @return The bounding box size after rotation.
|
|
29
|
-
*/
|
|
30
|
-
export function getRotatedBBox(
|
|
31
|
-
width: number,
|
|
32
|
-
height: number,
|
|
33
|
-
rotation: number
|
|
34
|
-
): Size {
|
|
35
|
-
// Short-circuit on any unsafe input. `isSafeNumber` is stricter than
|
|
36
|
-
// `Number.isFinite`: very large but technically-finite rotations (e.g.
|
|
37
|
-
// `Number.MAX_VALUE`) overflow inside `degreesToRadians` and then
|
|
38
|
-
// `Math.cos`/`Math.sin` return `NaN`, so the magnitude bound matters.
|
|
39
|
-
if (
|
|
40
|
-
! isSafeNumber( width ) ||
|
|
41
|
-
! isSafeNumber( height ) ||
|
|
42
|
-
! isSafeNumber( rotation ) ||
|
|
43
|
-
width <= 0 ||
|
|
44
|
-
height <= 0
|
|
45
|
-
) {
|
|
46
|
-
return { width: 0, height: 0 };
|
|
47
|
-
}
|
|
48
|
-
const rad = degreesToRadians( rotation );
|
|
49
|
-
const cosR = Math.abs( Math.cos( rad ) );
|
|
50
|
-
const sinR = Math.abs( Math.sin( rad ) );
|
|
51
|
-
return {
|
|
52
|
-
width: cosR * width + sinR * height,
|
|
53
|
-
height: sinR * width + cosR * height,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Compute the fitted (unrotated) image element dimensions and the visual
|
|
59
|
-
* (rotated) bounding box dimensions for a given container, image, and rotation.
|
|
60
|
-
*
|
|
61
|
-
* This is the same "contain" fit logic used by createCamera, extracted so
|
|
62
|
-
* cropper.tsx can size the <img> element and position overlays without
|
|
63
|
-
* duplicating the math.
|
|
64
|
-
*
|
|
65
|
-
* @param containerSize The container dimensions in pixels.
|
|
66
|
-
* @param imageSize The natural image dimensions in pixels.
|
|
67
|
-
* @param rotation The rotation angle in degrees.
|
|
68
|
-
* @return The fitted element size and visual bounding box size.
|
|
69
|
-
*/
|
|
70
|
-
export function getImageFit(
|
|
71
|
-
containerSize: Size,
|
|
72
|
-
imageSize: Size,
|
|
73
|
-
rotation: number
|
|
74
|
-
): { elementSize: Size; visualSize: Size } {
|
|
75
|
-
if ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {
|
|
76
|
-
return {
|
|
77
|
-
elementSize: { width: 0, height: 0 },
|
|
78
|
-
visualSize: { width: 0, height: 0 },
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const safeRotation = safeBoundedNumber( rotation, 0 );
|
|
82
|
-
// Snap rotation to the nearest 90° multiple for layout sizing.
|
|
83
|
-
// This keeps the stencil a stable size through fine ±45° rotation
|
|
84
|
-
// (no inflation at 15°/30° etc.) while still swapping aspect at
|
|
85
|
-
// 90°/180°/270° so the snap rotate preserves the framed content.
|
|
86
|
-
const snapRotation = Math.round( safeRotation / 90 ) * 90;
|
|
87
|
-
const naturalBBox = getRotatedBBox(
|
|
88
|
-
imageSize.width,
|
|
89
|
-
imageSize.height,
|
|
90
|
-
snapRotation
|
|
91
|
-
);
|
|
92
|
-
// Defensive: getRotatedBBox returns zero dims for hostile inputs, which
|
|
93
|
-
// would make fitScale infinite. Mirror the zero-container short-circuit.
|
|
94
|
-
if ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {
|
|
95
|
-
return {
|
|
96
|
-
elementSize: { width: 0, height: 0 },
|
|
97
|
-
visualSize: { width: 0, height: 0 },
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
const fitScale = Math.min(
|
|
101
|
-
containerSize.width / naturalBBox.width,
|
|
102
|
-
containerSize.height / naturalBBox.height
|
|
103
|
-
);
|
|
104
|
-
const renderedW = imageSize.width * fitScale;
|
|
105
|
-
const renderedH = imageSize.height * fitScale;
|
|
106
|
-
const visualSize = getRotatedBBox( renderedW, renderedH, snapRotation );
|
|
107
|
-
return {
|
|
108
|
-
elementSize: { width: renderedW, height: renderedH },
|
|
109
|
-
visualSize,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Resolve the presentational view magnification that makes the crop fill the
|
|
115
|
-
* canvas.
|
|
116
|
-
*
|
|
117
|
-
* The crop overlay is laid out as `cropRect * visualSize` (the contain-fit
|
|
118
|
-
* footprint, with no zoom), so its on-screen size is capped by that footprint.
|
|
119
|
-
* When a crop's aspect differs from the image's, it can be much smaller than
|
|
120
|
-
* the canvas could show (e.g. a square crop in a tall image is bound by the
|
|
121
|
-
* footprint's narrow axis). Scaling `elementSize` and `visualSize` together by
|
|
122
|
-
* the returned factor uniformly magnifies the whole scene — image, crop
|
|
123
|
-
* overlay, and overlays — so the crop reaches `targetFill` of its constraining
|
|
124
|
-
* canvas axis, with the image bleeding past the canvas (clipped by the host).
|
|
125
|
-
*
|
|
126
|
-
* Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,
|
|
127
|
-
* so the framed source region — and therefore the export — is unchanged.
|
|
128
|
-
*
|
|
129
|
-
* @param cropRect The crop rectangle, normalized to the footprint.
|
|
130
|
-
* @param canvasSize The canvas size in pixels.
|
|
131
|
-
* @param visualSize The contain-fit (rotated) image footprint in pixels.
|
|
132
|
-
* @param targetFill Fraction of the constraining canvas axis to fill (0–1].
|
|
133
|
-
* @param maxScale Upper bound on the magnification.
|
|
134
|
-
* @return A magnification factor in [1, maxScale]; 1 when none is needed.
|
|
135
|
-
*/
|
|
136
|
-
export function getViewScale(
|
|
137
|
-
cropRect: NormalizedRect,
|
|
138
|
-
canvasSize: Size,
|
|
139
|
-
visualSize: Size,
|
|
140
|
-
targetFill: number,
|
|
141
|
-
maxScale: number
|
|
142
|
-
): number {
|
|
143
|
-
const cropScreenW = cropRect.width * visualSize.width;
|
|
144
|
-
const cropScreenH = cropRect.height * visualSize.height;
|
|
145
|
-
// `> 0` comparisons (rather than `<= 0`) reject NaN as well as zero and
|
|
146
|
-
// negatives, so a non-finite rect/dimension/scale can't propagate to a
|
|
147
|
-
// `scale(NaN)`. `isValidSize` already guards finiteness of the sizes.
|
|
148
|
-
if (
|
|
149
|
-
! isValidSize( canvasSize ) ||
|
|
150
|
-
! isValidSize( visualSize ) ||
|
|
151
|
-
! ( cropScreenW > 0 ) ||
|
|
152
|
-
! ( cropScreenH > 0 ) ||
|
|
153
|
-
! Number.isFinite( targetFill ) ||
|
|
154
|
-
! Number.isFinite( maxScale ) ||
|
|
155
|
-
! ( targetFill > 0 ) ||
|
|
156
|
-
! ( maxScale >= 1 )
|
|
157
|
-
) {
|
|
158
|
-
return 1;
|
|
159
|
-
}
|
|
160
|
-
const kW = ( targetFill * canvasSize.width ) / cropScreenW;
|
|
161
|
-
const kH = ( targetFill * canvasSize.height ) / cropScreenH;
|
|
162
|
-
const k = Math.min( kW, kH );
|
|
163
|
-
return Math.min( maxScale, Math.max( 1, k ) );
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Compose a camera matrix from cropper state, container, and image dimensions.
|
|
168
|
-
*
|
|
169
|
-
* The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.
|
|
170
|
-
* Input (0,0) = image top-left, (1,1) = image bottom-right.
|
|
171
|
-
*
|
|
172
|
-
* Composition order (left-to-right = outermost first, applied last to point):
|
|
173
|
-
* M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels
|
|
174
|
-
*
|
|
175
|
-
* Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`
|
|
176
|
-
* are viewport-relative: the image mirrors across the viewport's vertical /
|
|
177
|
-
* horizontal axis regardless of current rotation.
|
|
178
|
-
*
|
|
179
|
-
* @param state The current cropper state (zoom, rotation, flip, crop).
|
|
180
|
-
* @param containerSize The size of the container in pixels.
|
|
181
|
-
* @param imageSize The natural size of the image in pixels.
|
|
182
|
-
* @return The composed camera matrix.
|
|
183
|
-
*/
|
|
184
|
-
export function createCamera(
|
|
185
|
-
state: CropperState,
|
|
186
|
-
containerSize: Size,
|
|
187
|
-
imageSize: Size
|
|
188
|
-
): Camera {
|
|
189
|
-
const m = mat2d.create();
|
|
190
|
-
|
|
191
|
-
if ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {
|
|
192
|
-
return m;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const safeState = sanitizeCropperState( state );
|
|
196
|
-
|
|
197
|
-
// Use the nearest 90° multiple for layout sizing so the stencil
|
|
198
|
-
// and visual bounds are stable through fine rotation. The actual
|
|
199
|
-
// `state.rotation` is still used for the rotation component of
|
|
200
|
-
// the matrix below.
|
|
201
|
-
const snapRotation = Math.round( safeState.rotation / 90 ) * 90;
|
|
202
|
-
|
|
203
|
-
// Rotated bounding box of the natural image (at snap angle).
|
|
204
|
-
const naturalBBox = getRotatedBBox(
|
|
205
|
-
imageSize.width,
|
|
206
|
-
imageSize.height,
|
|
207
|
-
snapRotation
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
// Defensive: getRotatedBBox returns zero dims for unsafe inputs. Mirror
|
|
211
|
-
// the zero-size short-circuit so `fitScale` doesn't become Infinity.
|
|
212
|
-
if ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {
|
|
213
|
-
return m;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// "Contain" fit: scale rotated bounding box to fit within container.
|
|
217
|
-
const fitScale = Math.min(
|
|
218
|
-
containerSize.width / naturalBBox.width,
|
|
219
|
-
containerSize.height / naturalBBox.height
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
// The rendered (unrotated) image dimensions at this fit scale.
|
|
223
|
-
const renderedW = imageSize.width * fitScale;
|
|
224
|
-
const renderedH = imageSize.height * fitScale;
|
|
225
|
-
|
|
226
|
-
// Visual (rotated) image footprint in pixels (at snap angle).
|
|
227
|
-
const { width: visualW, height: visualH } = getRotatedBBox(
|
|
228
|
-
renderedW,
|
|
229
|
-
renderedH,
|
|
230
|
-
snapRotation
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
// Build matrix left-to-right (outermost first).
|
|
234
|
-
// Innermost operations (last in code) are applied first to input point.
|
|
235
|
-
|
|
236
|
-
// Outermost: translate to container center.
|
|
237
|
-
mat2d.translate( m, m, [
|
|
238
|
-
containerSize.width / 2,
|
|
239
|
-
containerSize.height / 2,
|
|
240
|
-
] );
|
|
241
|
-
|
|
242
|
-
// Pan offset in visual-space pixels.
|
|
243
|
-
mat2d.translate( m, m, [
|
|
244
|
-
safeState.pan.x * visualW,
|
|
245
|
-
safeState.pan.y * visualH,
|
|
246
|
-
] );
|
|
247
|
-
|
|
248
|
-
// Flip (viewport-relative — composed outside rotation so horizontal
|
|
249
|
-
// flip always mirrors across the viewport's vertical axis).
|
|
250
|
-
mat2d.scale( m, m, [
|
|
251
|
-
safeState.flip.horizontal ? -1 : 1,
|
|
252
|
-
safeState.flip.vertical ? -1 : 1,
|
|
253
|
-
] );
|
|
254
|
-
|
|
255
|
-
// Rotate.
|
|
256
|
-
mat2d.rotate( m, m, degreesToRadians( safeState.rotation ) );
|
|
257
|
-
|
|
258
|
-
// Zoom.
|
|
259
|
-
mat2d.scale( m, m, [ safeState.zoom, safeState.zoom ] );
|
|
260
|
-
|
|
261
|
-
// Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).
|
|
262
|
-
mat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );
|
|
263
|
-
|
|
264
|
-
// Innermost: scale from normalized [0,1] to rendered pixels.
|
|
265
|
-
mat2d.scale( m, m, [ renderedW, renderedH ] );
|
|
266
|
-
|
|
267
|
-
return m;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Transform a normalized world point [0,1] to screen pixels.
|
|
272
|
-
*
|
|
273
|
-
* @param camera The camera matrix from createCamera.
|
|
274
|
-
* @param point The normalized world coordinate to transform.
|
|
275
|
-
* @return The screen pixel coordinate.
|
|
276
|
-
*/
|
|
277
|
-
export function worldToScreen(
|
|
278
|
-
camera: Camera,
|
|
279
|
-
point: NormalizedPoint
|
|
280
|
-
): { x: number; y: number } {
|
|
281
|
-
const out = vec2.create();
|
|
282
|
-
vec2.transformMat2d( out, [ point.x, point.y ], camera );
|
|
283
|
-
return { x: out[ 0 ], y: out[ 1 ] };
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Transform a screen pixel point to normalized world coordinates [0,1].
|
|
288
|
-
*
|
|
289
|
-
* @param camera The camera matrix from createCamera.
|
|
290
|
-
* @param point The screen pixel coordinate to transform.
|
|
291
|
-
* @param point.x The x component of the screen pixel coordinate.
|
|
292
|
-
* @param point.y The y component of the screen pixel coordinate.
|
|
293
|
-
* @return The normalized world coordinate.
|
|
294
|
-
*/
|
|
295
|
-
export function screenToWorld(
|
|
296
|
-
camera: Camera,
|
|
297
|
-
point: { x: number; y: number }
|
|
298
|
-
): NormalizedPoint {
|
|
299
|
-
mat2d.invert( _scratchMat, camera );
|
|
300
|
-
const out = _scratchVec;
|
|
301
|
-
vec2.transformMat2d( out, [ point.x, point.y ], _scratchMat );
|
|
302
|
-
return { x: out[ 0 ], y: out[ 1 ] };
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* The bounding box of a transformed region in screen (pixel) space.
|
|
307
|
-
*/
|
|
308
|
-
export interface VisualBounds {
|
|
309
|
-
left: number;
|
|
310
|
-
top: number;
|
|
311
|
-
width: number;
|
|
312
|
-
height: number;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Compute the axis-aligned bounding box of a set of corners after
|
|
317
|
-
* transforming them through a camera matrix.
|
|
318
|
-
*
|
|
319
|
-
* @param camera The camera matrix from createCamera.
|
|
320
|
-
* @param corners The corners to transform (each as [x, y]).
|
|
321
|
-
* @return The screen-space bounding box.
|
|
322
|
-
*/
|
|
323
|
-
function aabb( camera: Camera, corners: [ number, number ][] ): VisualBounds {
|
|
324
|
-
const screenCorners = corners.map( ( c ) => {
|
|
325
|
-
const out = vec2.create();
|
|
326
|
-
vec2.transformMat2d( out, c, camera );
|
|
327
|
-
return out;
|
|
328
|
-
} );
|
|
329
|
-
let minX = screenCorners[ 0 ][ 0 ];
|
|
330
|
-
let maxX = screenCorners[ 0 ][ 0 ];
|
|
331
|
-
let minY = screenCorners[ 0 ][ 1 ];
|
|
332
|
-
let maxY = screenCorners[ 0 ][ 1 ];
|
|
333
|
-
for ( let i = 1; i < screenCorners.length; i++ ) {
|
|
334
|
-
const s = screenCorners[ i ];
|
|
335
|
-
if ( s[ 0 ] < minX ) {
|
|
336
|
-
minX = s[ 0 ];
|
|
337
|
-
}
|
|
338
|
-
if ( s[ 0 ] > maxX ) {
|
|
339
|
-
maxX = s[ 0 ];
|
|
340
|
-
}
|
|
341
|
-
if ( s[ 1 ] < minY ) {
|
|
342
|
-
minY = s[ 1 ];
|
|
343
|
-
}
|
|
344
|
-
if ( s[ 1 ] > maxY ) {
|
|
345
|
-
maxY = s[ 1 ];
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return { left: minX, top: minY, width: maxX - minX, height: maxY - minY };
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])
|
|
353
|
-
* after applying the camera transform.
|
|
354
|
-
*
|
|
355
|
-
* @param camera The camera matrix from createCamera.
|
|
356
|
-
* @return The screen-space bounding box of the full image.
|
|
357
|
-
*/
|
|
358
|
-
export function getVisibleBounds( camera: Camera ): VisualBounds {
|
|
359
|
-
return aabb( camera, [
|
|
360
|
-
[ 0, 0 ],
|
|
361
|
-
[ 1, 0 ],
|
|
362
|
-
[ 1, 1 ],
|
|
363
|
-
[ 0, 1 ],
|
|
364
|
-
] );
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Compose a camera matrix for exporting to a canvas.
|
|
369
|
-
*
|
|
370
|
-
* The resulting matrix maps image-pixel coordinates directly to output-canvas
|
|
371
|
-
* coordinates. Apply it with `ctx.setTransform( ...camera )` then
|
|
372
|
-
* `ctx.drawImage( image, 0, 0 )`.
|
|
373
|
-
*
|
|
374
|
-
* The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:
|
|
375
|
-
* translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)
|
|
376
|
-
*
|
|
377
|
-
* @param state The current cropper state.
|
|
378
|
-
* @param imageSize The natural size of the source image in pixels.
|
|
379
|
-
* @param outputSize The desired output canvas size in pixels.
|
|
380
|
-
* @return The composed export camera matrix.
|
|
381
|
-
*/
|
|
382
|
-
export function createExportCamera(
|
|
383
|
-
state: CropperState,
|
|
384
|
-
imageSize: Size,
|
|
385
|
-
outputSize: Size
|
|
386
|
-
): Camera {
|
|
387
|
-
const m = mat2d.create();
|
|
388
|
-
if ( ! isValidSize( imageSize ) || ! isValidSize( outputSize ) ) {
|
|
389
|
-
return m;
|
|
390
|
-
}
|
|
391
|
-
const { rotation, flip, cropRect, zoom, pan } =
|
|
392
|
-
sanitizeCropperState( state );
|
|
393
|
-
// Reference frame for cropRect/pan is the snap-rotation bbox — that's
|
|
394
|
-
// what the stencil and CSS matrix use in the preview (see createCamera
|
|
395
|
-
// and getImageFit). Using the true rotation here would position the
|
|
396
|
-
// crop window at a different offset than the stencil framed, and show
|
|
397
|
-
// a shifted region after any fine rotation.
|
|
398
|
-
const snapRotation = Math.round( rotation / 90 ) * 90;
|
|
399
|
-
const { width: rotW, height: rotH } = getRotatedBBox(
|
|
400
|
-
imageSize.width,
|
|
401
|
-
imageSize.height,
|
|
402
|
-
snapRotation
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
// Scale factor to map the natural crop region to the output canvas size.
|
|
406
|
-
const naturalCropW = cropRect.width * rotW;
|
|
407
|
-
const naturalCropH = cropRect.height * rotH;
|
|
408
|
-
const outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;
|
|
409
|
-
const outputScaleY =
|
|
410
|
-
naturalCropH > 0 ? outputSize.height / naturalCropH : 1;
|
|
411
|
-
|
|
412
|
-
const cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;
|
|
413
|
-
const cropOffsetY =
|
|
414
|
-
cropRect.y * rotH + outputSize.height / 2 / outputScaleY;
|
|
415
|
-
const visualCenterX = rotW / 2 + pan.x * rotW;
|
|
416
|
-
const visualCenterY = rotH / 2 + pan.y * rotH;
|
|
417
|
-
mat2d.scale( m, m, [ outputScaleX, outputScaleY ] );
|
|
418
|
-
mat2d.translate( m, m, [
|
|
419
|
-
visualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,
|
|
420
|
-
visualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY,
|
|
421
|
-
] );
|
|
422
|
-
// Flip is composed outside rotation so it acts in viewport/output space —
|
|
423
|
-
// must match createCamera's order for preview and export to agree.
|
|
424
|
-
mat2d.scale( m, m, [ flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1 ] );
|
|
425
|
-
mat2d.rotate( m, m, degreesToRadians( rotation ) );
|
|
426
|
-
mat2d.scale( m, m, [ zoom, zoom ] );
|
|
427
|
-
mat2d.translate( m, m, [ -imageSize.width / 2, -imageSize.height / 2 ] );
|
|
428
|
-
return m;
|
|
429
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { __ } from '@wordpress/i18n';
|
|
2
|
-
import type { NormalizedRect, Flip, CropperState } from './types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Default/resting zoom. A full, unrotated crop needs at least 1x to cover the
|
|
6
|
-
* crop area, but smaller/fine-rotated crops can be valid below 1x — the true
|
|
7
|
-
* floor for those comes from `getMinZoom`.
|
|
8
|
-
*/
|
|
9
|
-
export const MIN_ZOOM = 1;
|
|
10
|
-
/**
|
|
11
|
-
* Safety floor for coverage-aware zoom. Degenerate crops can have a geometric
|
|
12
|
-
* coverage minimum of 0, but camera and inverse-matrix math need a stable,
|
|
13
|
-
* positive scale.
|
|
14
|
-
*/
|
|
15
|
-
export const ABSOLUTE_MIN_ZOOM = 0.1;
|
|
16
|
-
export const MAX_ZOOM = 10;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Minimum crop rect dimension in source-image pixels, enforced per axis
|
|
20
|
-
* during resize. Prevents accidental sub-pixel crops while staying small
|
|
21
|
-
* enough to allow tight crops (favicons, icons). Adjust here to tune the
|
|
22
|
-
* floor globally.
|
|
23
|
-
*/
|
|
24
|
-
export const MIN_CROP_PIXELS = 16;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Minimum on-screen crop rect dimension in CSS pixels. The source-pixel
|
|
28
|
-
* floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large
|
|
29
|
-
* image fit into a small canvas it can render only a few CSS pixels wide —
|
|
30
|
-
* too small to grab the resize handles. This floor keeps the crop operable
|
|
31
|
-
* regardless of display scale; it binds when zoomed out and yields to the
|
|
32
|
-
* source-pixel floor once the image is shown large enough. Sized to one
|
|
33
|
-
* handle touch target (`$handle-touch-target-size` in `cropper.scss`).
|
|
34
|
-
*/
|
|
35
|
-
export const MIN_CROP_SCREEN_PX = 44;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Fraction of the constraining canvas axis the settled crop should occupy on
|
|
39
|
-
* screen. When a crop is shown smaller than this (e.g. a square crop in a tall
|
|
40
|
-
* image, capped by the contain-fit footprint's narrow axis), the view magnifies
|
|
41
|
-
* to fill the canvas. `1` = always fill the canvas; lower = rescue only the
|
|
42
|
-
* under-filled cases. See `getViewScale`.
|
|
43
|
-
*/
|
|
44
|
-
export const SETTLE_TARGET_CANVAS_FILL = 0.8;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Upper bound on the presentational view magnification (`getViewScale`).
|
|
48
|
-
* Prevents a near-degenerate crop from magnifying the scene without limit.
|
|
49
|
-
*/
|
|
50
|
-
export const MAX_VIEW_SCALE = 8;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* CSS pixels per source pixel required before resize handles snap the selected
|
|
54
|
-
* source region to whole-pixel edges. Below 1:1, a source pixel is sub-pixel on
|
|
55
|
-
* screen, so snapping would feel notchy without a visible pixel boundary.
|
|
56
|
-
*/
|
|
57
|
-
export const PIXEL_SNAP_DISPLAY_SCALE = 1;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.
|
|
61
|
-
* This could be made configurable as a prop to the Cropper component.
|
|
62
|
-
*/
|
|
63
|
-
export const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;
|
|
64
|
-
|
|
65
|
-
/** Fine step for keyboard-driven cropper movement, in normalized coordinates. */
|
|
66
|
-
export const DEFAULT_KEYBOARD_STEP = 0.01;
|
|
67
|
-
|
|
68
|
-
/** Coarse keyboard movement multiplier when Shift is held. */
|
|
69
|
-
export const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Maximum free-rotation offset in degrees from the nearest 90° step.
|
|
73
|
-
* The rotation slider allows ±45° around the current cardinal angle.
|
|
74
|
-
*/
|
|
75
|
-
export const MAX_ROTATION_OFFSET = 45;
|
|
76
|
-
|
|
77
|
-
const DEFAULT_CROP_RECT: NormalizedRect = {
|
|
78
|
-
x: 0,
|
|
79
|
-
y: 0,
|
|
80
|
-
width: 1,
|
|
81
|
-
height: 1,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const DEFAULT_FLIP: Flip = {
|
|
85
|
-
horizontal: false,
|
|
86
|
-
vertical: false,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const DEFAULT_PAN: { x: number; y: number } = {
|
|
90
|
-
x: 0,
|
|
91
|
-
y: 0,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export const DEFAULT_STATE: CropperState = {
|
|
95
|
-
image: null,
|
|
96
|
-
pan: { ...DEFAULT_PAN },
|
|
97
|
-
zoom: MIN_ZOOM,
|
|
98
|
-
rotation: 0,
|
|
99
|
-
basePan: { ...DEFAULT_PAN },
|
|
100
|
-
baseZoom: MIN_ZOOM,
|
|
101
|
-
baseRotation: 0,
|
|
102
|
-
flip: { ...DEFAULT_FLIP },
|
|
103
|
-
cropRect: { ...DEFAULT_CROP_RECT },
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* An aspect ratio preset with a human-readable label.
|
|
108
|
-
*/
|
|
109
|
-
export interface AspectRatioPreset {
|
|
110
|
-
/** Display label (e.g., "Square (1:1)"). */
|
|
111
|
-
label: string;
|
|
112
|
-
/** The aspect ratio value (width / height). 0 = free / original. */
|
|
113
|
-
value: number;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Default aspect ratio presets. Consumers can use these as-is, override
|
|
118
|
-
* with their own list, or extend with additional presets.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* // Use defaults:
|
|
122
|
-
* <CropControls presets={ DEFAULT_ASPECT_RATIOS } />
|
|
123
|
-
*
|
|
124
|
-
* // Custom presets:
|
|
125
|
-
* const socialPresets = [
|
|
126
|
-
* { label: 'Instagram Post', value: 1 },
|
|
127
|
-
* { label: 'Instagram Story', value: 9 / 16 },
|
|
128
|
-
* { label: 'YouTube Thumbnail', value: 16 / 9 },
|
|
129
|
-
* ];
|
|
130
|
-
*
|
|
131
|
-
* // Extend defaults:
|
|
132
|
-
* const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];
|
|
133
|
-
*/
|
|
134
|
-
/**
|
|
135
|
-
* Sentinel value for "Original" aspect ratio — resolved at runtime
|
|
136
|
-
* to the image's natural width / height.
|
|
137
|
-
*/
|
|
138
|
-
export const ORIGINAL_ASPECT_RATIO = -1;
|
|
139
|
-
|
|
140
|
-
export const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [
|
|
141
|
-
{ label: __( 'Free' ), value: 0 },
|
|
142
|
-
{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },
|
|
143
|
-
{ label: __( 'Square (1:1)' ), value: 1 },
|
|
144
|
-
{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },
|
|
145
|
-
{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },
|
|
146
|
-
{ label: __( 'Classic (4:3)' ), value: 4 / 3 },
|
|
147
|
-
{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },
|
|
148
|
-
{ label: __( 'Photo (3:2)' ), value: 3 / 2 },
|
|
149
|
-
{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },
|
|
150
|
-
];
|