@wordpress/media-editor 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -68
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -720
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +136 -89
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -281
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -696
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -75
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -273
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +5 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +20 -42
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -1,64 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/media-editor/src/image-editor/core/setter-helpers.ts
|
|
21
|
-
var setter_helpers_exports = {};
|
|
22
|
-
__export(setter_helpers_exports, {
|
|
23
|
-
buildFocalPointZoomAction: () => buildFocalPointZoomAction
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
let __constants_ts = require("./constants.cjs");
|
|
7
|
+
let __containment_ts = require("./containment.cjs");
|
|
8
|
+
// packages/media-editor/src/image-editor/core/setter-helpers.ts
|
|
9
|
+
/**
|
|
10
|
+
* Build the reducer action that produces a "cursorless" zoom — zoom
|
|
11
|
+
* anchored at the current crop-rect center, with pan clamped to keep
|
|
12
|
+
* the image covering the crop.
|
|
13
|
+
*
|
|
14
|
+
* The slider, the `+`/`-` keys, and the toolbar buttons have no
|
|
15
|
+
* natural focal point (unlike wheel/pinch zoom), so they default to
|
|
16
|
+
* the crop center. Returns `null` when the clamped zoom matches the
|
|
17
|
+
* current zoom (no-op).
|
|
18
|
+
*
|
|
19
|
+
* Extracted so multiple hooks (the pure `useCropperController` and the
|
|
20
|
+
* composite `useMediaEditorState`) can share the math without
|
|
21
|
+
* duplicating it.
|
|
22
|
+
*
|
|
23
|
+
* @param state The current cropper state.
|
|
24
|
+
* @param requestedZoom The zoom value the caller asked for.
|
|
25
|
+
* @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.
|
|
26
|
+
*/
|
|
28
27
|
function buildFocalPointZoomAction(state, requestedZoom) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
28
|
+
const clampedZoom = Math.min(__constants_ts.MAX_ZOOM, Math.max((0, __containment_ts.getMinZoom)(state), requestedZoom));
|
|
29
|
+
if (clampedZoom === state.zoom) return null;
|
|
30
|
+
const { cropRect } = state;
|
|
31
|
+
const focalNormX = cropRect.x + cropRect.width / 2 - .5;
|
|
32
|
+
const focalNormY = cropRect.y + cropRect.height / 2 - .5;
|
|
33
|
+
const zoomRatio = 1 - clampedZoom / state.zoom;
|
|
34
|
+
const newPanX = state.pan.x + (focalNormX - state.pan.x) * zoomRatio;
|
|
35
|
+
const newPanY = state.pan.y + (focalNormY - state.pan.y) * zoomRatio;
|
|
36
|
+
const imageSize = state.image ? {
|
|
37
|
+
width: state.image.naturalWidth,
|
|
38
|
+
height: state.image.naturalHeight
|
|
39
|
+
} : {
|
|
40
|
+
width: 1,
|
|
41
|
+
height: 1
|
|
42
|
+
};
|
|
43
|
+
const { pan: clampedPan } = (0, __containment_ts.restrictPanZoom)({
|
|
44
|
+
...state,
|
|
45
|
+
zoom: clampedZoom,
|
|
46
|
+
pan: {
|
|
47
|
+
x: newPanX,
|
|
48
|
+
y: newPanY
|
|
49
|
+
}
|
|
50
|
+
}, imageSize, state.cropRect);
|
|
51
|
+
return {
|
|
52
|
+
type: "SET_ZOOM_AT_POINT",
|
|
53
|
+
payload: {
|
|
54
|
+
zoom: clampedZoom,
|
|
55
|
+
pan: clampedPan
|
|
56
|
+
}
|
|
57
|
+
};
|
|
59
58
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
//# sourceMappingURL=setter-helpers.cjs.map
|
|
59
|
+
exports.buildFocalPointZoomAction = buildFocalPointZoomAction;
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=setter-helpers.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/image-editor/core/setter-helpers.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom — zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperReducer` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0–1), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t\t}\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAyB;AACzB,yBAA4C;AAoBrC,SAAS,0BACf,OACA,eACuB;AACvB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,IACA,KAAK,QAAK,+BAAY,KAAM,GAAG,aAAc;AAAA,EAC9C;AACA,MAAK,gBAAgB,MAAM,MAAO;AACjC,WAAO;AAAA,EACR;AAKA,QAAM,EAAE,SAAS,IAAI;AACrB,QAAM,aAAa,SAAS,IAAI,SAAS,QAAQ,IAAI;AACrD,QAAM,aAAa,SAAS,IAAI,SAAS,SAAS,IAAI;AACtD,QAAM,YAAY,IAAI,cAAc,MAAM;AAC1C,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,YAA+C,MAAM,QACxD;AAAA,IACA,OAAO,MAAM,MAAM;AAAA,IACnB,QAAQ,MAAM,MAAM;AAAA,EACrB,IACC,EAAE,OAAO,GAAG,QAAQ,EAAE;AACzB,QAAM,EAAE,KAAK,WAAW,QAA8B;AAAA,IACrD;AAAA,MACC,GAAG;AAAA,MACH,MAAM;AAAA,MACN,KAAK,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,MAAM;AAAA,EACP;AACA,SAAO;AAAA,IACN,MAAM;AAAA,IACN,SAAS,EAAE,MAAM,aAAa,KAAK,WAAW;AAAA,EAC/C;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"setter-helpers.cjs","names":["MAX_ZOOM","getMinZoom","restrictPanZoom"],"sources":["../../../src/image-editor/core/setter-helpers.ts"],"sourcesContent":["import type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom — zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperController` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0–1), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t\t}\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,0BACf,OACA,eACuB;CACvB,MAAM,cAAc,KAAK,IACxBA,eAAAA,UACA,KAAK,KAAA,GAAKC,iBAAAA,WAAAA,CAAY,KAAM,GAAG,aAAc,CAC9C;CACA,IAAK,gBAAgB,MAAM,MAC1B,OAAO;CAMR,MAAM,EAAE,aAAa;CACrB,MAAM,aAAa,SAAS,IAAI,SAAS,QAAQ,IAAI;CACrD,MAAM,aAAa,SAAS,IAAI,SAAS,SAAS,IAAI;CACtD,MAAM,YAAY,IAAI,cAAc,MAAM;CAC1C,MAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;CAC7D,MAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;CAC7D,MAAM,YAA+C,MAAM,QACxD;EACA,OAAO,MAAM,MAAM;EACnB,QAAQ,MAAM,MAAM;CACrB,IACC;EAAE,OAAO;EAAG,QAAQ;CAAE;CACzB,MAAM,EAAE,KAAK,gBAAA,GAAyCC,iBAAAA,gBAAAA,CACrD;EACC,GAAG;EACH,MAAM;EACN,KAAK;GAAE,GAAG;GAAS,GAAG;EAAQ;CAC/B,GACA,WACA,MAAM,QACP;CACA,OAAO;EACN,MAAM;EACN,SAAS;GAAE,MAAM;GAAa,KAAK;EAAW;CAC/C;AACD"}
|
|
@@ -1,206 +1,236 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/media-editor/src/image-editor/core/source-region.ts
|
|
21
|
-
var source_region_exports = {};
|
|
22
|
-
__export(source_region_exports, {
|
|
23
|
-
getSourceRegion: () => getSourceRegion,
|
|
24
|
-
getSourceRegionPercent: () => getSourceRegionPercent,
|
|
25
|
-
snapCropRectToSourcePixelGrid: () => snapCropRectToSourcePixelGrid,
|
|
26
|
-
snapCropRectToSourcePixels: () => snapCropRectToSourcePixels
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
27
5
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
6
|
+
let gl_matrix = require("gl-matrix");
|
|
7
|
+
let __camera_ts = require("./camera.cjs");
|
|
8
|
+
let __math_sanitize_ts = require("./math/sanitize.cjs");
|
|
9
|
+
let __math_rotation_ts = require("./math/rotation.cjs");
|
|
10
|
+
// packages/media-editor/src/image-editor/core/source-region.ts
|
|
11
|
+
/**
|
|
12
|
+
* Get the selected image region in source-pixel coordinates.
|
|
13
|
+
*
|
|
14
|
+
* Converts the current crop state (normalized visual space) to the actual
|
|
15
|
+
* region of the original image that's selected. This is the bridge between
|
|
16
|
+
* the cropper's internal coordinate system and external tools (image
|
|
17
|
+
* processing libraries, AI APIs, server-side processing) that work in
|
|
18
|
+
* source-pixel coordinates.
|
|
19
|
+
*
|
|
20
|
+
* The returned rectangle accounts for pan, zoom, and the crop rect position,
|
|
21
|
+
* but expresses the crop in the unrotated image's coordinate space. Rotation
|
|
22
|
+
* and flip are included as separate fields since they represent transforms,
|
|
23
|
+
* not a region.
|
|
24
|
+
*
|
|
25
|
+
* @param state The current cropper state.
|
|
26
|
+
* @param imageSize The natural dimensions of the source image.
|
|
27
|
+
* @return The selected region in source pixels plus rotation/flip metadata.
|
|
28
|
+
*/
|
|
33
29
|
function getSourceRegion(state, imageSize) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
rotation: safeState.rotation,
|
|
79
|
-
flip: { ...safeState.flip },
|
|
80
|
-
zoom: safeState.zoom
|
|
81
|
-
};
|
|
30
|
+
const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
|
|
31
|
+
if (!(0, __math_sanitize_ts.isValidSize)(imageSize)) return {
|
|
32
|
+
x: 0,
|
|
33
|
+
y: 0,
|
|
34
|
+
width: 0,
|
|
35
|
+
height: 0,
|
|
36
|
+
rotation: safeState.rotation,
|
|
37
|
+
flip: { ...safeState.flip },
|
|
38
|
+
zoom: safeState.zoom
|
|
39
|
+
};
|
|
40
|
+
const syntheticContainer = {
|
|
41
|
+
width: 1e3,
|
|
42
|
+
height: 1e3
|
|
43
|
+
};
|
|
44
|
+
const camera = (0, __camera_ts.createCamera)(safeState, syntheticContainer, imageSize);
|
|
45
|
+
const inv = gl_matrix.mat2d.create();
|
|
46
|
+
gl_matrix.mat2d.invert(inv, camera);
|
|
47
|
+
const baseCamera = (0, __camera_ts.createCamera)({
|
|
48
|
+
...safeState,
|
|
49
|
+
pan: {
|
|
50
|
+
x: 0,
|
|
51
|
+
y: 0
|
|
52
|
+
},
|
|
53
|
+
zoom: 1
|
|
54
|
+
}, syntheticContainer, imageSize);
|
|
55
|
+
const visibleBounds = (0, __camera_ts.getVisibleBounds)(baseCamera);
|
|
56
|
+
const cropRect = safeState.cropRect;
|
|
57
|
+
const cropCenterScreenX = visibleBounds.left + (cropRect.x + cropRect.width / 2) * visibleBounds.width;
|
|
58
|
+
const cropCenterScreenY = visibleBounds.top + (cropRect.y + cropRect.height / 2) * visibleBounds.height;
|
|
59
|
+
const srcCenter = gl_matrix.vec2.create();
|
|
60
|
+
gl_matrix.vec2.transformMat2d(srcCenter, [cropCenterScreenX, cropCenterScreenY], inv);
|
|
61
|
+
const snapRotation = Math.round(safeState.rotation / 90) * 90;
|
|
62
|
+
const { width: rotW, height: rotH } = (0, __camera_ts.getRotatedBBox)(imageSize.width, imageSize.height, snapRotation);
|
|
63
|
+
const sourceW = cropRect.width * rotW / safeState.zoom;
|
|
64
|
+
const sourceH = cropRect.height * rotH / safeState.zoom;
|
|
65
|
+
return {
|
|
66
|
+
x: srcCenter[0] * imageSize.width - sourceW / 2,
|
|
67
|
+
y: srcCenter[1] * imageSize.height - sourceH / 2,
|
|
68
|
+
width: sourceW,
|
|
69
|
+
height: sourceH,
|
|
70
|
+
rotation: safeState.rotation,
|
|
71
|
+
flip: { ...safeState.flip },
|
|
72
|
+
zoom: safeState.zoom
|
|
73
|
+
};
|
|
82
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert a source-pixel region back to the cropper's normalized crop rect.
|
|
77
|
+
*
|
|
78
|
+
* The math intentionally mirrors `getSourceRegion`: map the requested source
|
|
79
|
+
* center through the current camera, then express that screen point inside the
|
|
80
|
+
* same base visible bounds used to position crop overlays.
|
|
81
|
+
*
|
|
82
|
+
* @param state The current cropper state.
|
|
83
|
+
* @param imageSize The natural dimensions of the source image.
|
|
84
|
+
* @param region The source-pixel region to represent as a crop rect.
|
|
85
|
+
* @return The normalized crop rect, or null when inputs cannot be mapped.
|
|
86
|
+
*/
|
|
83
87
|
function getCropRectFromSourceRegion(state, imageSize, region) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const centerY = (screenCenter[1] - visibleBounds.top) / visibleBounds.height;
|
|
118
|
-
return {
|
|
119
|
-
x: centerX - width / 2,
|
|
120
|
-
y: centerY - height / 2,
|
|
121
|
-
width,
|
|
122
|
-
height
|
|
123
|
-
};
|
|
88
|
+
if (!(0, __math_sanitize_ts.isValidSize)(imageSize) || region.width <= 0 || region.height <= 0) return null;
|
|
89
|
+
const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
|
|
90
|
+
const syntheticContainer = {
|
|
91
|
+
width: 1e3,
|
|
92
|
+
height: 1e3
|
|
93
|
+
};
|
|
94
|
+
const baseCamera = (0, __camera_ts.createCamera)({
|
|
95
|
+
...safeState,
|
|
96
|
+
pan: {
|
|
97
|
+
x: 0,
|
|
98
|
+
y: 0
|
|
99
|
+
},
|
|
100
|
+
zoom: 1
|
|
101
|
+
}, syntheticContainer, imageSize);
|
|
102
|
+
const visibleBounds = (0, __camera_ts.getVisibleBounds)(baseCamera);
|
|
103
|
+
if (visibleBounds.width <= 0 || visibleBounds.height <= 0) return null;
|
|
104
|
+
const sourceCenter = gl_matrix.vec2.fromValues((region.x + region.width / 2) / imageSize.width, (region.y + region.height / 2) / imageSize.height);
|
|
105
|
+
const screenCenter = gl_matrix.vec2.create();
|
|
106
|
+
const camera = (0, __camera_ts.createCamera)(safeState, syntheticContainer, imageSize);
|
|
107
|
+
gl_matrix.vec2.transformMat2d(screenCenter, sourceCenter, camera);
|
|
108
|
+
const snapRotation = Math.round(safeState.rotation / 90) * 90;
|
|
109
|
+
const { width: rotW, height: rotH } = (0, __camera_ts.getRotatedBBox)(imageSize.width, imageSize.height, snapRotation);
|
|
110
|
+
if (rotW <= 0 || rotH <= 0) return null;
|
|
111
|
+
const width = region.width * safeState.zoom / rotW;
|
|
112
|
+
const height = region.height * safeState.zoom / rotH;
|
|
113
|
+
const centerX = (screenCenter[0] - visibleBounds.left) / visibleBounds.width;
|
|
114
|
+
const centerY = (screenCenter[1] - visibleBounds.top) / visibleBounds.height;
|
|
115
|
+
return {
|
|
116
|
+
x: centerX - width / 2,
|
|
117
|
+
y: centerY - height / 2,
|
|
118
|
+
width,
|
|
119
|
+
height
|
|
120
|
+
};
|
|
124
121
|
}
|
|
125
|
-
|
|
122
|
+
const CARDINAL_ROTATION_EPSILON = 1e-6;
|
|
123
|
+
/**
|
|
124
|
+
* Check whether a rotation is effectively at a 90-degree stop.
|
|
125
|
+
*
|
|
126
|
+
* @param rotation The rotation angle in degrees.
|
|
127
|
+
* @return Whether the rotation is close enough to a cardinal angle.
|
|
128
|
+
*/
|
|
126
129
|
function isCardinalRotation(rotation) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
const normalizedRotation = (0, __math_rotation_ts.normalizeRotation)(rotation);
|
|
131
|
+
const nearestCardinal = Math.round(normalizedRotation / 90) * 90;
|
|
132
|
+
return Math.abs(normalizedRotation - nearestCardinal) < CARDINAL_ROTATION_EPSILON;
|
|
130
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Snap a crop rect so the selected source-region edges land on whole pixels.
|
|
136
|
+
*
|
|
137
|
+
* This is a display-time affordance for visible pixel grids; it does not alter
|
|
138
|
+
* pan/zoom/rotation. Callers decide when snapping is appropriate.
|
|
139
|
+
*
|
|
140
|
+
* @param state The current cropper state.
|
|
141
|
+
* @param imageSize The natural dimensions of the source image.
|
|
142
|
+
* @param cropRect The candidate crop rect from resize math.
|
|
143
|
+
* @param handle The active resize handle. Only edges moved by the handle snap.
|
|
144
|
+
* @return A crop rect whose selected source-region edges are whole pixels.
|
|
145
|
+
*/
|
|
131
146
|
function snapCropRectToSourcePixels(state, imageSize, cropRect, handle) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
bottom: handle.includes("s")
|
|
141
|
-
});
|
|
147
|
+
const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
|
|
148
|
+
if (!isCardinalRotation(safeState.rotation)) return cropRect;
|
|
149
|
+
return snapCropRectEdgesToSourcePixels(safeState, imageSize, cropRect, {
|
|
150
|
+
left: handle.includes("w"),
|
|
151
|
+
top: handle.includes("n"),
|
|
152
|
+
right: handle.includes("e"),
|
|
153
|
+
bottom: handle.includes("s")
|
|
154
|
+
});
|
|
142
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Snap all source-region edges for a crop rect to the nearest whole pixels.
|
|
158
|
+
*
|
|
159
|
+
* @param state The current cropper state.
|
|
160
|
+
* @param imageSize The natural dimensions of the source image.
|
|
161
|
+
* @param cropRect The crop rect to align to the source-pixel grid.
|
|
162
|
+
* @return A crop rect whose source-region edges are whole pixels.
|
|
163
|
+
*/
|
|
143
164
|
function snapCropRectToSourcePixelGrid(state, imageSize, cropRect) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
165
|
+
return snapCropRectEdgesToSourcePixels(state, imageSize, cropRect, {
|
|
166
|
+
left: true,
|
|
167
|
+
top: true,
|
|
168
|
+
right: true,
|
|
169
|
+
bottom: true
|
|
170
|
+
});
|
|
150
171
|
}
|
|
151
172
|
function snapCropRectEdgesToSourcePixels(state, imageSize, cropRect, edges) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
x: shouldSnapX ? snappedCropRect.x : cropRect.x,
|
|
182
|
-
y: shouldSnapY ? snappedCropRect.y : cropRect.y,
|
|
183
|
-
width: shouldSnapX ? snappedCropRect.width : cropRect.width,
|
|
184
|
-
height: shouldSnapY ? snappedCropRect.height : cropRect.height
|
|
185
|
-
};
|
|
173
|
+
if (!(0, __math_sanitize_ts.isValidSize)(imageSize)) return cropRect;
|
|
174
|
+
const stateWithCrop = (0, __math_sanitize_ts.sanitizeCropperState)({
|
|
175
|
+
...state,
|
|
176
|
+
cropRect
|
|
177
|
+
});
|
|
178
|
+
const region = getSourceRegion(stateWithCrop, imageSize);
|
|
179
|
+
const shouldSnapX = edges.left || edges.right;
|
|
180
|
+
const shouldSnapY = edges.top || edges.bottom;
|
|
181
|
+
const left = edges.left ? Math.round(region.x) : region.x;
|
|
182
|
+
const top = edges.top ? Math.round(region.y) : region.y;
|
|
183
|
+
const right = edges.right ? Math.round(region.x + region.width) : region.x + region.width;
|
|
184
|
+
const bottom = edges.bottom ? Math.round(region.y + region.height) : region.y + region.height;
|
|
185
|
+
if (right <= left || bottom <= top) return cropRect;
|
|
186
|
+
const snappedCropRect = getCropRectFromSourceRegion(stateWithCrop, imageSize, {
|
|
187
|
+
...region,
|
|
188
|
+
x: left,
|
|
189
|
+
y: top,
|
|
190
|
+
width: right - left,
|
|
191
|
+
height: bottom - top
|
|
192
|
+
});
|
|
193
|
+
if (!snappedCropRect) return cropRect;
|
|
194
|
+
return {
|
|
195
|
+
x: shouldSnapX ? snappedCropRect.x : cropRect.x,
|
|
196
|
+
y: shouldSnapY ? snappedCropRect.y : cropRect.y,
|
|
197
|
+
width: shouldSnapX ? snappedCropRect.width : cropRect.width,
|
|
198
|
+
height: shouldSnapY ? snappedCropRect.height : cropRect.height
|
|
199
|
+
};
|
|
186
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Get the selected image region as percentages of the source image dimensions.
|
|
203
|
+
*
|
|
204
|
+
* Returns `{ x, y, width, height }` where each value is a percentage (0–100)
|
|
205
|
+
* of the source image's natural width or height. This format is compatible
|
|
206
|
+
* with the WordPress REST API attachments `/edit` endpoint and CSS-based
|
|
207
|
+
* crop workflows.
|
|
208
|
+
*
|
|
209
|
+
* Internally delegates to `getSourceRegion` and divides by the image
|
|
210
|
+
* dimensions, so accuracy is identical.
|
|
211
|
+
*
|
|
212
|
+
* @param state The current cropper state.
|
|
213
|
+
* @param imageSize The natural dimensions of the source image.
|
|
214
|
+
* @return The crop region as percentages (0–100).
|
|
215
|
+
*/
|
|
187
216
|
function getSourceRegionPercent(state, imageSize) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
217
|
+
if (!(0, __math_sanitize_ts.isValidSize)(imageSize)) return {
|
|
218
|
+
x: 0,
|
|
219
|
+
y: 0,
|
|
220
|
+
width: 0,
|
|
221
|
+
height: 0
|
|
222
|
+
};
|
|
223
|
+
const region = getSourceRegion(state, imageSize);
|
|
224
|
+
return {
|
|
225
|
+
x: region.x / imageSize.width * 100,
|
|
226
|
+
y: region.y / imageSize.height * 100,
|
|
227
|
+
width: region.width / imageSize.width * 100,
|
|
228
|
+
height: region.height / imageSize.height * 100
|
|
229
|
+
};
|
|
198
230
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
});
|
|
206
|
-
//# sourceMappingURL=source-region.cjs.map
|
|
231
|
+
exports.getSourceRegion = getSourceRegion;
|
|
232
|
+
exports.getSourceRegionPercent = getSourceRegionPercent;
|
|
233
|
+
exports.snapCropRectToSourcePixelGrid = snapCropRectToSourcePixelGrid;
|
|
234
|
+
exports.snapCropRectToSourcePixels = snapCropRectToSourcePixels;
|
|
235
|
+
|
|
236
|
+
//# sourceMappingURL=source-region.cjs.map
|