@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,276 +1,289 @@
|
|
|
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/containment.ts
|
|
21
|
-
var containment_exports = {};
|
|
22
|
-
__export(containment_exports, {
|
|
23
|
-
getImageCropBounds: () => getImageCropBounds,
|
|
24
|
-
getMinZoom: () => getMinZoom,
|
|
25
|
-
restrictCropRect: () => restrictCropRect,
|
|
26
|
-
restrictPanZoom: () => restrictPanZoom
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
27
5
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
6
|
+
let gl_matrix = require("gl-matrix");
|
|
7
|
+
let __constants_ts = require("./constants.cjs");
|
|
8
|
+
let __math_rotation_ts = require("./math/rotation.cjs");
|
|
9
|
+
let __math_sanitize_ts = require("./math/sanitize.cjs");
|
|
10
|
+
let __camera_ts = require("./camera.cjs");
|
|
11
|
+
// packages/media-editor/src/image-editor/core/containment.ts
|
|
12
|
+
/**
|
|
13
|
+
* Compute the visual (rotated) bounding-box dimensions in pixel-proportional
|
|
14
|
+
* units where the unrotated image is `a × 1` (renderedW = a, renderedH = 1).
|
|
15
|
+
*
|
|
16
|
+
* @param rotation Rotation angle in degrees.
|
|
17
|
+
* @param imageAspectRatio Image width / height ratio.
|
|
18
|
+
* @return Visual dimensions and trig helpers.
|
|
19
|
+
*/
|
|
35
20
|
function getVisualDimensions(rotation, imageAspectRatio) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
const rad = (0, __math_rotation_ts.degreesToRadians)(rotation);
|
|
22
|
+
const absC = Math.abs(Math.cos(rad));
|
|
23
|
+
const absS = Math.abs(Math.sin(rad));
|
|
24
|
+
const bbox = (0, __camera_ts.getRotatedBBox)(imageAspectRatio, 1, rotation);
|
|
25
|
+
return {
|
|
26
|
+
visualW: bbox.width,
|
|
27
|
+
visualH: bbox.height,
|
|
28
|
+
absC,
|
|
29
|
+
absS
|
|
30
|
+
};
|
|
46
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* The geometric minimum zoom required for the rotated image to fully cover the
|
|
34
|
+
* crop rectangle. Works in pixel-proportional space where the unrotated image
|
|
35
|
+
* is a×1; the crop rect lives in visual-normalized space and is scaled by the
|
|
36
|
+
* rotation-dependent visual dimensions before projecting into the image-local
|
|
37
|
+
* frame.
|
|
38
|
+
*
|
|
39
|
+
* Returns 0 for a degenerate (zero-area) crop — callers compose the result
|
|
40
|
+
* with their own floor (typically the current zoom or `MIN_ZOOM`).
|
|
41
|
+
*
|
|
42
|
+
* @param rotation Rotation angle in degrees.
|
|
43
|
+
* @param imageAspectRatio Image width / height ratio.
|
|
44
|
+
* @param cropRect The crop rectangle in normalized coordinates.
|
|
45
|
+
* @return The minimum zoom factor needed for coverage.
|
|
46
|
+
*/
|
|
47
47
|
function getMinZoomForCover(rotation, imageAspectRatio, cropRect) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const spanBeta = cropHalfW * absS + cropHalfH * absC;
|
|
59
|
-
const zoomFromAlpha = 2 * spanAlpha / aspectRatio;
|
|
60
|
-
const zoomFromBeta = 2 * spanBeta;
|
|
61
|
-
return Math.max(zoomFromAlpha, zoomFromBeta);
|
|
48
|
+
const aspectRatio = Math.max(imageAspectRatio, Number.EPSILON);
|
|
49
|
+
const { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(Math.round(rotation / 90) * 90, aspectRatio);
|
|
50
|
+
const { absC, absS } = getVisualDimensions(rotation, aspectRatio);
|
|
51
|
+
const cropHalfW = cropRect.width * snapVisualW / 2;
|
|
52
|
+
const cropHalfH = cropRect.height * snapVisualH / 2;
|
|
53
|
+
const spanAlpha = cropHalfW * absC + cropHalfH * absS;
|
|
54
|
+
const spanBeta = cropHalfW * absS + cropHalfH * absC;
|
|
55
|
+
const zoomFromAlpha = 2 * spanAlpha / aspectRatio;
|
|
56
|
+
const zoomFromBeta = 2 * spanBeta;
|
|
57
|
+
return Math.max(zoomFromAlpha, zoomFromBeta);
|
|
62
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Resolves the effective minimum zoom for the current state — the coverage-
|
|
61
|
+
* aware floor when an image is loaded, falling back to `MIN_ZOOM` otherwise.
|
|
62
|
+
* Used by both the cropper's interaction layer and the zoom slider so the
|
|
63
|
+
* floor stays consistent across surfaces.
|
|
64
|
+
*
|
|
65
|
+
* @param state The current cropper state.
|
|
66
|
+
* @return The minimum zoom factor.
|
|
67
|
+
*/
|
|
63
68
|
function getMinZoom(state) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
const safeState = (0, import_sanitize.sanitizeCropperState)(state);
|
|
75
|
-
const aspectRatio = imageSize.width / imageSize.height;
|
|
76
|
-
return Math.max(
|
|
77
|
-
import_constants.ABSOLUTE_MIN_ZOOM,
|
|
78
|
-
getMinZoomForCover(
|
|
79
|
-
safeState.rotation,
|
|
80
|
-
aspectRatio,
|
|
81
|
-
safeState.cropRect
|
|
82
|
-
)
|
|
83
|
-
);
|
|
69
|
+
if (!state.image) return __constants_ts.MIN_ZOOM;
|
|
70
|
+
const imageSize = {
|
|
71
|
+
width: state.image.naturalWidth,
|
|
72
|
+
height: state.image.naturalHeight
|
|
73
|
+
};
|
|
74
|
+
if (!(0, __math_sanitize_ts.isValidSize)(imageSize)) return __constants_ts.MIN_ZOOM;
|
|
75
|
+
const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
|
|
76
|
+
const aspectRatio = imageSize.width / imageSize.height;
|
|
77
|
+
return Math.max(__constants_ts.ABSOLUTE_MIN_ZOOM, getMinZoomForCover(safeState.rotation, aspectRatio, safeState.cropRect));
|
|
84
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Compute the crop handle bounds in normalized visual space — the
|
|
81
|
+
* axis-aligned bounding box (AABB) of the actual image footprint at the
|
|
82
|
+
* current pan/zoom/rotation.
|
|
83
|
+
*
|
|
84
|
+
* Returns the full image AABB without intersecting with the container
|
|
85
|
+
* viewport. The viewport pan mechanism in the Cropper component allows
|
|
86
|
+
* the canvas to scroll so handles can reach the image edge even when it
|
|
87
|
+
* lies outside the visible canvas area.
|
|
88
|
+
*
|
|
89
|
+
* Unlike a static centerline-based calculation, this accounts for the
|
|
90
|
+
* current pan position — if the user pans right, the left bound tightens
|
|
91
|
+
* because the image's left edge has moved right.
|
|
92
|
+
*
|
|
93
|
+
* @param state The current cropper state (crop, zoom, rotation, flip).
|
|
94
|
+
* @param elementSize The fitted (unrotated) image element dimensions in pixels.
|
|
95
|
+
* @param visualSize The visual (rotated) image bounding box in pixels.
|
|
96
|
+
* @return The min/max x and y that a crop rect edge can reach in normalized space.
|
|
97
|
+
*/
|
|
85
98
|
function getImageCropBounds(state, elementSize, visualSize) {
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
99
|
+
if (!(0, __math_sanitize_ts.isValidSize)(elementSize) || !(0, __math_sanitize_ts.isValidSize)(visualSize)) return {
|
|
100
|
+
minX: 0,
|
|
101
|
+
minY: 0,
|
|
102
|
+
maxX: 1,
|
|
103
|
+
maxY: 1
|
|
104
|
+
};
|
|
105
|
+
const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
|
|
106
|
+
const tx = safeState.pan.x * visualSize.width;
|
|
107
|
+
const ty = safeState.pan.y * visualSize.height;
|
|
108
|
+
const rad = (0, __math_rotation_ts.degreesToRadians)(safeState.rotation);
|
|
109
|
+
const cos = Math.cos(rad);
|
|
110
|
+
const sin = Math.sin(rad);
|
|
111
|
+
const sx = safeState.flip.horizontal ? -1 : 1;
|
|
112
|
+
const sy = safeState.flip.vertical ? -1 : 1;
|
|
113
|
+
const z = safeState.zoom;
|
|
114
|
+
const ma = sx * cos * z;
|
|
115
|
+
const mb = sy * sin * z;
|
|
116
|
+
const mc = -sx * sin * z;
|
|
117
|
+
const md = sy * cos * z;
|
|
118
|
+
const hw = elementSize.width / 2;
|
|
119
|
+
const hh = elementSize.height / 2;
|
|
120
|
+
const corners = [
|
|
121
|
+
[-hw, -hh],
|
|
122
|
+
[hw, -hh],
|
|
123
|
+
[hw, hh],
|
|
124
|
+
[-hw, hh]
|
|
125
|
+
];
|
|
126
|
+
let imgMinX = Infinity;
|
|
127
|
+
let imgMaxX = -Infinity;
|
|
128
|
+
let imgMinY = Infinity;
|
|
129
|
+
let imgMaxY = -Infinity;
|
|
130
|
+
for (const [cx, cy] of corners) {
|
|
131
|
+
const screenX = ma * cx + mc * cy + tx;
|
|
132
|
+
const screenY = mb * cx + md * cy + ty;
|
|
133
|
+
const nx = screenX / visualSize.width + .5;
|
|
134
|
+
const ny = screenY / visualSize.height + .5;
|
|
135
|
+
imgMinX = Math.min(imgMinX, nx);
|
|
136
|
+
imgMaxX = Math.max(imgMaxX, nx);
|
|
137
|
+
imgMinY = Math.min(imgMinY, ny);
|
|
138
|
+
imgMaxY = Math.max(imgMaxY, ny);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
minX: imgMinX,
|
|
142
|
+
minY: imgMinY,
|
|
143
|
+
maxX: imgMaxX,
|
|
144
|
+
maxY: imgMaxY
|
|
145
|
+
};
|
|
130
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.
|
|
149
|
+
* If the crop rect is too large for the current zoom and rotation, it is scaled
|
|
150
|
+
* down proportionally and re-centered.
|
|
151
|
+
*
|
|
152
|
+
* Works in pixel-proportional space where the unrotated image is a×1.
|
|
153
|
+
*
|
|
154
|
+
* @param cropRect The crop rectangle in normalized coordinates.
|
|
155
|
+
* @param zoom The current zoom factor.
|
|
156
|
+
* @param rotation The rotation angle in degrees.
|
|
157
|
+
* @param imageAspectRatio The image width / height ratio.
|
|
158
|
+
* @return The restricted crop rectangle.
|
|
159
|
+
*/
|
|
131
160
|
function restrictCropRect(cropRect, zoom, rotation, imageAspectRatio) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
let newX = centerX - newW / 2;
|
|
167
|
-
let newY = centerY - newH / 2;
|
|
168
|
-
newX = Math.max(0, Math.min(newX, 1 - newW));
|
|
169
|
-
newY = Math.max(0, Math.min(newY, 1 - newH));
|
|
170
|
-
return { x: newX, y: newY, width: newW, height: newH };
|
|
161
|
+
const safeRect = (0, __math_sanitize_ts.sanitizeRect)(cropRect);
|
|
162
|
+
const zoomCandidate = (0, __math_sanitize_ts.safeBoundedNumber)(zoom, 1);
|
|
163
|
+
const safeZoom = zoomCandidate >= Number.EPSILON ? zoomCandidate : 1;
|
|
164
|
+
const safeRotation = (0, __math_sanitize_ts.safeBoundedNumber)(rotation, 0);
|
|
165
|
+
const safeAspect = (0, __math_sanitize_ts.safeBoundedNumber)(imageAspectRatio, 1);
|
|
166
|
+
const aspectRatio = Math.max(safeAspect, Number.EPSILON);
|
|
167
|
+
const { visualW, visualH } = getVisualDimensions(Math.round(safeRotation / 90) * 90, aspectRatio);
|
|
168
|
+
const { absC, absS } = getVisualDimensions(safeRotation, aspectRatio);
|
|
169
|
+
const W = safeRect.width;
|
|
170
|
+
const H = safeRect.height;
|
|
171
|
+
const cropWPx = W * visualW;
|
|
172
|
+
const cropHPx = H * visualH;
|
|
173
|
+
const spanAlpha = cropWPx * absC + cropHPx * absS;
|
|
174
|
+
const spanBeta = cropWPx * absS + cropHPx * absC;
|
|
175
|
+
const limitAlpha = aspectRatio * safeZoom;
|
|
176
|
+
const limitBeta = safeZoom;
|
|
177
|
+
let t = 1;
|
|
178
|
+
if (spanAlpha > 0) t = Math.min(t, limitAlpha / spanAlpha);
|
|
179
|
+
if (spanBeta > 0) t = Math.min(t, limitBeta / spanBeta);
|
|
180
|
+
if (t >= .999999999) return safeRect;
|
|
181
|
+
const newW = W * t;
|
|
182
|
+
const newH = H * t;
|
|
183
|
+
const centerX = safeRect.x + W / 2;
|
|
184
|
+
const centerY = safeRect.y + H / 2;
|
|
185
|
+
let newX = centerX - newW / 2;
|
|
186
|
+
let newY = centerY - newH / 2;
|
|
187
|
+
newX = Math.max(0, Math.min(newX, 1 - newW));
|
|
188
|
+
newY = Math.max(0, Math.min(newY, 1 - newH));
|
|
189
|
+
return {
|
|
190
|
+
x: newX,
|
|
191
|
+
y: newY,
|
|
192
|
+
width: newW,
|
|
193
|
+
height: newH
|
|
194
|
+
};
|
|
171
195
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Canonical container used internally by restrictPanZoom.
|
|
198
|
+
* Containment is scale-invariant, so the actual size doesn't matter —
|
|
199
|
+
* only the relative geometry between stencil and image matters.
|
|
200
|
+
*/
|
|
201
|
+
const CANONICAL_CONTAINER = {
|
|
202
|
+
width: 1e3,
|
|
203
|
+
height: 1e3
|
|
204
|
+
};
|
|
205
|
+
const _scratchMat = gl_matrix.mat2d.create();
|
|
206
|
+
const _scratchVec = gl_matrix.vec2.create();
|
|
207
|
+
/**
|
|
208
|
+
* Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers
|
|
209
|
+
* the crop rectangle.
|
|
210
|
+
*
|
|
211
|
+
* Uses the camera matrix to project: builds a camera from the candidate state,
|
|
212
|
+
* maps the stencil corners (axis-aligned in the visual bounding box) to world
|
|
213
|
+
* space via the inverse camera, and checks that all world points lie within
|
|
214
|
+
* [0,1]×[0,1]. If any point is outside, computes the minimal pan correction.
|
|
215
|
+
*
|
|
216
|
+
* @param state The current cropper state.
|
|
217
|
+
* @param imageSize The natural size of the image in pixels.
|
|
218
|
+
* @param cropRect The crop rectangle in normalized coordinates.
|
|
219
|
+
* @return The restricted crop pan and zoom values.
|
|
220
|
+
*/
|
|
175
221
|
function restrictPanZoom(state, imageSize, cropRect) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (w[1] > maxWy) {
|
|
238
|
-
maxWy = w[1];
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
if (minWx >= -EPSILON && maxWx <= 1 + EPSILON && minWy >= -EPSILON && maxWy <= 1 + EPSILON) {
|
|
242
|
-
return { pan: safeState.pan, zoom };
|
|
243
|
-
}
|
|
244
|
-
let dwx = 0;
|
|
245
|
-
let dwy = 0;
|
|
246
|
-
if (minWx < 0 && maxWx <= 1 + EPSILON) {
|
|
247
|
-
dwx = -minWx;
|
|
248
|
-
} else if (maxWx > 1 && minWx >= -EPSILON) {
|
|
249
|
-
dwx = 1 - maxWx;
|
|
250
|
-
} else if (minWx < 0 && maxWx > 1) {
|
|
251
|
-
dwx = (1 - maxWx - minWx) / 2;
|
|
252
|
-
}
|
|
253
|
-
if (minWy < 0 && maxWy <= 1 + EPSILON) {
|
|
254
|
-
dwy = -minWy;
|
|
255
|
-
} else if (maxWy > 1 && minWy >= -EPSILON) {
|
|
256
|
-
dwy = 1 - maxWy;
|
|
257
|
-
} else if (minWy < 0 && maxWy > 1) {
|
|
258
|
-
dwy = (1 - maxWy - minWy) / 2;
|
|
259
|
-
}
|
|
260
|
-
const dsx = camera[0] * dwx + camera[2] * dwy;
|
|
261
|
-
const dsy = camera[1] * dwx + camera[3] * dwy;
|
|
262
|
-
const newPanX = safeState.pan.x - (visibleBounds.width > 0 ? dsx / visibleBounds.width : 0);
|
|
263
|
-
const newPanY = safeState.pan.y - (visibleBounds.height > 0 ? dsy / visibleBounds.height : 0);
|
|
264
|
-
return {
|
|
265
|
-
pan: { x: newPanX, y: newPanY },
|
|
266
|
-
zoom
|
|
267
|
-
};
|
|
222
|
+
const safeState = (0, __math_sanitize_ts.sanitizeCropperState)(state);
|
|
223
|
+
const safeCropRect = (0, __math_sanitize_ts.sanitizeRect)(cropRect);
|
|
224
|
+
const aspectRatio = (0, __math_sanitize_ts.isValidSize)(imageSize) ? imageSize.width / imageSize.height : 1;
|
|
225
|
+
const minZoom = Math.max(__constants_ts.ABSOLUTE_MIN_ZOOM, getMinZoomForCover(safeState.rotation, aspectRatio, safeCropRect));
|
|
226
|
+
const zoom = Math.min(__constants_ts.MAX_ZOOM, Math.max(safeState.zoom, minZoom));
|
|
227
|
+
const candidateState = {
|
|
228
|
+
...safeState,
|
|
229
|
+
zoom
|
|
230
|
+
};
|
|
231
|
+
const camera = (0, __camera_ts.createCamera)(candidateState, CANONICAL_CONTAINER, imageSize);
|
|
232
|
+
const snapRotation = Math.round(safeState.rotation / 90) * 90;
|
|
233
|
+
const baseCamera = (0, __camera_ts.createCamera)({
|
|
234
|
+
...candidateState,
|
|
235
|
+
pan: {
|
|
236
|
+
x: 0,
|
|
237
|
+
y: 0
|
|
238
|
+
},
|
|
239
|
+
zoom: 1,
|
|
240
|
+
rotation: snapRotation
|
|
241
|
+
}, CANONICAL_CONTAINER, imageSize);
|
|
242
|
+
const visibleBounds = (0, __camera_ts.getVisibleBounds)(baseCamera);
|
|
243
|
+
const stencilCorners = [
|
|
244
|
+
[visibleBounds.left + safeCropRect.x * visibleBounds.width, visibleBounds.top + safeCropRect.y * visibleBounds.height],
|
|
245
|
+
[visibleBounds.left + (safeCropRect.x + safeCropRect.width) * visibleBounds.width, visibleBounds.top + safeCropRect.y * visibleBounds.height],
|
|
246
|
+
[visibleBounds.left + (safeCropRect.x + safeCropRect.width) * visibleBounds.width, visibleBounds.top + (safeCropRect.y + safeCropRect.height) * visibleBounds.height],
|
|
247
|
+
[visibleBounds.left + safeCropRect.x * visibleBounds.width, visibleBounds.top + (safeCropRect.y + safeCropRect.height) * visibleBounds.height]
|
|
248
|
+
];
|
|
249
|
+
gl_matrix.mat2d.invert(_scratchMat, camera);
|
|
250
|
+
let minWx = Infinity;
|
|
251
|
+
let maxWx = -Infinity;
|
|
252
|
+
let minWy = Infinity;
|
|
253
|
+
let maxWy = -Infinity;
|
|
254
|
+
for (const corner of stencilCorners) {
|
|
255
|
+
gl_matrix.vec2.transformMat2d(_scratchVec, corner, _scratchMat);
|
|
256
|
+
const w = _scratchVec;
|
|
257
|
+
if (w[0] < minWx) minWx = w[0];
|
|
258
|
+
if (w[0] > maxWx) maxWx = w[0];
|
|
259
|
+
if (w[1] < minWy) minWy = w[1];
|
|
260
|
+
if (w[1] > maxWy) maxWy = w[1];
|
|
261
|
+
}
|
|
262
|
+
if (minWx >= -1e-9 && maxWx <= 1.000000001 && minWy >= -1e-9 && maxWy <= 1.000000001) return {
|
|
263
|
+
pan: safeState.pan,
|
|
264
|
+
zoom
|
|
265
|
+
};
|
|
266
|
+
let dwx = 0;
|
|
267
|
+
let dwy = 0;
|
|
268
|
+
if (minWx < 0 && maxWx <= 1.000000001) dwx = -minWx;
|
|
269
|
+
else if (maxWx > 1 && minWx >= -1e-9) dwx = 1 - maxWx;
|
|
270
|
+
else if (minWx < 0 && maxWx > 1) dwx = (1 - maxWx - minWx) / 2;
|
|
271
|
+
if (minWy < 0 && maxWy <= 1.000000001) dwy = -minWy;
|
|
272
|
+
else if (maxWy > 1 && minWy >= -1e-9) dwy = 1 - maxWy;
|
|
273
|
+
else if (minWy < 0 && maxWy > 1) dwy = (1 - maxWy - minWy) / 2;
|
|
274
|
+
const dsx = camera[0] * dwx + camera[2] * dwy;
|
|
275
|
+
const dsy = camera[1] * dwx + camera[3] * dwy;
|
|
276
|
+
return {
|
|
277
|
+
pan: {
|
|
278
|
+
x: safeState.pan.x - (visibleBounds.width > 0 ? dsx / visibleBounds.width : 0),
|
|
279
|
+
y: safeState.pan.y - (visibleBounds.height > 0 ? dsy / visibleBounds.height : 0)
|
|
280
|
+
},
|
|
281
|
+
zoom
|
|
282
|
+
};
|
|
268
283
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
});
|
|
276
|
-
//# sourceMappingURL=containment.cjs.map
|
|
284
|
+
exports.getImageCropBounds = getImageCropBounds;
|
|
285
|
+
exports.getMinZoom = getMinZoom;
|
|
286
|
+
exports.restrictCropRect = restrictCropRect;
|
|
287
|
+
exports.restrictPanZoom = restrictPanZoom;
|
|
288
|
+
|
|
289
|
+
//# sourceMappingURL=containment.cjs.map
|