@wordpress/media-editor 0.9.0 → 0.10.1
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/build/components/media-editor/index.cjs +212 -170
- package/build/components/media-editor/index.cjs.map +3 -3
- package/build/components/media-editor/use-crop-options.cjs +63 -0
- package/build/components/media-editor/use-crop-options.cjs.map +7 -0
- package/build/components/media-editor/use-save-media-editor.cjs +185 -0
- package/build/components/media-editor/use-save-media-editor.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +33 -12
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +70 -84
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-fine-rotation/index.cjs +81 -0
- package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +63 -16
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-transform-controls/index.cjs +84 -0
- package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
- package/build/components/media-form/index.cjs +19 -1
- package/build/components/media-form/index.cjs.map +3 -3
- package/build/components/media-form/sidebar-datetime-view.cjs +53 -0
- package/build/components/media-form/sidebar-datetime-view.cjs.map +7 -0
- package/build/components/rotation-ruler/index.cjs +8 -2
- package/build/components/rotation-ruler/index.cjs.map +2 -2
- package/build/hooks/use-crop-gesture-handlers.cjs +41 -4
- package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
- package/build/image-editor/core/camera.cjs +29 -11
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs +6 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +71 -34
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/crop-rect.cjs +48 -0
- package/build/image-editor/core/crop-rect.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +12 -0
- package/build/image-editor/core/index.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs +92 -0
- package/build/image-editor/core/math/sanitize.cjs.map +7 -0
- package/build/image-editor/core/setter-helpers.cjs +64 -0
- package/build/image-editor/core/setter-helpers.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +16 -14
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +20 -10
- package/build/image-editor/core/state.cjs.map +2 -2
- package/build/image-editor/core/stencil-math.cjs +31 -20
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs +12 -6
- package/build/image-editor/core/transform-style.cjs.map +2 -2
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/index.cjs +12 -2
- package/build/image-editor/index.cjs.map +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs +2 -2
- package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
- package/build/image-editor/react/components/cropper.cjs +120 -47
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +172 -0
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +19 -9
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +71 -0
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +6 -3
- package/build/image-editor/react/hooks/index.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +113 -0
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +7 -0
- package/build/state/composite-reducer.cjs +103 -0
- package/build/state/composite-reducer.cjs.map +7 -0
- package/build/state/index.cjs +48 -0
- package/build/state/index.cjs.map +7 -0
- package/build/state/media-editor-state-provider.cjs +58 -0
- package/build/state/media-editor-state-provider.cjs.map +7 -0
- package/build/state/types.cjs +33 -0
- package/build/state/types.cjs.map +7 -0
- package/build/state/use-media-editor-state.cjs +287 -0
- package/build/state/use-media-editor-state.cjs.map +7 -0
- package/build/store/actions.cjs +4 -2
- package/build/store/actions.cjs.map +2 -2
- package/build/store/reducer.cjs +5 -3
- package/build/store/reducer.cjs.map +2 -2
- package/build/store/selectors.cjs +5 -0
- package/build/store/selectors.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +224 -177
- package/build-module/components/media-editor/index.mjs.map +2 -2
- package/build-module/components/media-editor/use-crop-options.mjs +37 -0
- package/build-module/components/media-editor/use-crop-options.mjs.map +7 -0
- package/build-module/components/media-editor/use-save-media-editor.mjs +151 -0
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +34 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +73 -89
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +64 -17
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
- package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
- package/build-module/components/media-form/index.mjs +9 -1
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/media-form/sidebar-datetime-view.mjs +32 -0
- package/build-module/components/media-form/sidebar-datetime-view.mjs.map +7 -0
- package/build-module/components/rotation-ruler/index.mjs +8 -2
- package/build-module/components/rotation-ruler/index.mjs.map +2 -2
- package/build-module/hooks/use-crop-gesture-handlers.mjs +41 -4
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
- package/build-module/image-editor/core/camera.mjs +34 -11
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +4 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +75 -34
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/crop-rect.mjs +23 -0
- package/build-module/image-editor/core/crop-rect.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +12 -0
- package/build-module/image-editor/core/index.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/math/sanitize.mjs +63 -0
- package/build-module/image-editor/core/math/sanitize.mjs.map +7 -0
- package/build-module/image-editor/core/setter-helpers.mjs +39 -0
- package/build-module/image-editor/core/setter-helpers.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +16 -14
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +25 -11
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/stencil-math.mjs +30 -19
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs +12 -6
- package/build-module/image-editor/core/transform-style.mjs.map +2 -2
- package/build-module/image-editor/index.mjs +11 -2
- package/build-module/image-editor/index.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper-provider.mjs +3 -3
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
- package/build-module/image-editor/react/components/cropper.mjs +121 -48
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +147 -0
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +19 -9
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +46 -0
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +4 -2
- package/build-module/image-editor/react/hooks/index.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +100 -0
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +7 -0
- package/build-module/state/composite-reducer.mjs +82 -0
- package/build-module/state/composite-reducer.mjs.map +7 -0
- package/build-module/state/index.mjs +26 -0
- package/build-module/state/index.mjs.map +7 -0
- package/build-module/state/media-editor-state-provider.mjs +34 -0
- package/build-module/state/media-editor-state-provider.mjs.map +7 -0
- package/build-module/state/types.mjs +8 -0
- package/build-module/state/types.mjs.map +7 -0
- package/build-module/state/use-media-editor-state.mjs +278 -0
- package/build-module/state/use-media-editor-state.mjs.map +7 -0
- package/build-module/store/actions.mjs +4 -2
- package/build-module/store/actions.mjs.map +2 -2
- package/build-module/store/reducer.mjs +5 -3
- package/build-module/store/reducer.mjs.map +2 -2
- package/build-module/store/selectors.mjs +4 -0
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-style/style-rtl.css +97 -44
- package/build-style/style.css +97 -44
- package/build-types/components/media-editor/index.d.ts +14 -5
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +35 -0
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -0
- package/build-types/components/media-editor/use-save-media-editor.d.ts +29 -0
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +5 -10
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +6 -25
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts +14 -0
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +13 -14
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +18 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +10 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/crop-rect.d.ts +19 -0
- package/build-types/image-editor/core/crop-rect.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +3 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +5 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +70 -0
- package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -0
- package/build-types/image-editor/core/setter-helpers.d.ts +24 -0
- package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts +12 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +23 -18
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
- package/build-types/image-editor/core/types.d.ts +23 -4
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/index.d.ts +4 -4
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +11 -7
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +6 -4
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +36 -0
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +2 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +47 -0
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +4 -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 +58 -0
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +39 -0
- package/build-types/state/composite-reducer.d.ts.map +1 -0
- package/build-types/state/index.d.ts +7 -0
- package/build-types/state/index.d.ts.map +1 -0
- package/build-types/state/media-editor-state-provider.d.ts +34 -0
- package/build-types/state/media-editor-state-provider.d.ts.map +1 -0
- package/build-types/state/types.d.ts +96 -0
- package/build-types/state/types.d.ts.map +1 -0
- package/build-types/state/use-media-editor-state.d.ts +101 -0
- package/build-types/state/use-media-editor-state.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +3 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +3 -0
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +1 -0
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +19 -16
- package/src/components/media-editor/index.tsx +262 -229
- package/src/components/media-editor/style.scss +0 -9
- package/src/components/media-editor/test/use-crop-options.tsx +110 -0
- package/src/components/media-editor/use-crop-options.ts +79 -0
- package/src/components/media-editor/use-save-media-editor.ts +214 -0
- package/src/components/media-editor-canvas/index.tsx +57 -25
- package/src/components/media-editor-crop-panel/index.tsx +53 -87
- package/src/components/media-editor-crop-panel/test/index.tsx +46 -53
- package/src/components/media-editor-fine-rotation/index.tsx +74 -0
- package/src/components/media-editor-modal/index.tsx +70 -16
- package/src/components/media-editor-modal/style.scss +80 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +14 -0
- package/src/components/media-editor-modal/test/index.tsx +146 -0
- package/src/components/media-editor-transform-controls/index.tsx +70 -0
- package/src/components/media-editor-transform-controls/style.scss +8 -0
- package/src/components/media-form/index.tsx +15 -1
- package/src/components/media-form/sidebar-datetime-view.tsx +47 -0
- package/src/components/media-form/test/sidebar-datetime-view.test.tsx +96 -0
- package/src/components/rotation-ruler/README.md +11 -25
- package/src/components/rotation-ruler/index.tsx +17 -2
- package/src/components/rotation-ruler/style.scss +49 -13
- package/src/hooks/use-crop-gesture-handlers.ts +64 -17
- package/src/image-editor/README.md +28 -129
- package/src/image-editor/core/camera.ts +51 -26
- package/src/image-editor/core/constants.ts +19 -0
- package/src/image-editor/core/containment.ts +102 -49
- package/src/image-editor/core/crop-rect.ts +45 -0
- package/src/image-editor/core/index.ts +16 -4
- package/src/image-editor/core/interaction-controller.ts +5 -1
- package/src/image-editor/core/math/sanitize.ts +158 -0
- package/src/image-editor/core/math/test/sanitize.ts +244 -0
- package/src/image-editor/core/setter-helpers.ts +66 -0
- package/src/image-editor/core/source-region.ts +21 -14
- package/src/image-editor/core/state.ts +67 -15
- package/src/image-editor/core/stencil-math.ts +55 -35
- package/src/image-editor/core/test/camera.ts +367 -1
- package/src/image-editor/core/test/state.ts +101 -8
- package/src/image-editor/core/test/stencil-math.ts +193 -0
- package/src/image-editor/core/transform-style.ts +21 -6
- package/src/image-editor/core/types.ts +24 -4
- package/src/image-editor/docs/architecture.md +48 -89
- package/src/image-editor/docs/recipes.md +123 -659
- package/src/image-editor/index.ts +12 -3
- package/src/image-editor/react/components/cropper-provider.tsx +16 -12
- package/src/image-editor/react/components/cropper.scss +23 -4
- package/src/image-editor/react/components/cropper.tsx +194 -89
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +269 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +19 -8
- package/src/image-editor/react/components/test/cropper.tsx +55 -13
- package/src/image-editor/react/hooks/build-cropper-setters.ts +105 -0
- package/src/image-editor/react/hooks/index.ts +4 -2
- package/src/image-editor/react/hooks/test/{use-cropper-state.ts → use-cropper-reducer.ts} +142 -286
- package/src/image-editor/react/hooks/use-cropper-reducer.ts +204 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +7 -17
- package/src/state/composite-reducer.ts +137 -0
- package/src/state/index.ts +20 -0
- package/src/state/media-editor-state-provider.tsx +70 -0
- package/src/state/test/use-media-editor-state.ts +330 -0
- package/src/state/types.ts +101 -0
- package/src/state/use-media-editor-state.ts +472 -0
- package/src/store/actions.ts +3 -0
- package/src/store/reducer.ts +6 -1
- package/src/store/selectors.ts +4 -0
- package/src/store/test/reducer.ts +9 -0
- package/src/style.scss +1 -1
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/media-editor-toolbar/index.cjs +0 -214
- package/build/components/media-editor-toolbar/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-state.cjs +0 -277
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +0 -7
- package/build-module/components/media-editor-toolbar/index.mjs +0 -190
- package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +0 -262
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +0 -7
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -97
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
- package/src/components/media-editor-toolbar/index.tsx +0 -209
- package/src/components/media-editor-toolbar/style.scss +0 -49
- package/src/image-editor/docs/roadmap.md +0 -66
- package/src/image-editor/react/hooks/use-cropper-state.ts +0 -457
|
@@ -21,12 +21,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var containment_exports = {};
|
|
22
22
|
__export(containment_exports, {
|
|
23
23
|
getImageCropBounds: () => getImageCropBounds,
|
|
24
|
+
getMinZoom: () => getMinZoom,
|
|
24
25
|
restrictCropRect: () => restrictCropRect,
|
|
25
26
|
restrictPanZoom: () => restrictPanZoom
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(containment_exports);
|
|
28
29
|
var import_gl_matrix = require("gl-matrix");
|
|
30
|
+
var import_constants = require("./constants.cjs");
|
|
29
31
|
var import_rotation = require("./math/rotation.cjs");
|
|
32
|
+
var import_sanitize = require("./math/sanitize.cjs");
|
|
30
33
|
var import_camera = require("./camera.cjs");
|
|
31
34
|
var EPSILON = 1e-9;
|
|
32
35
|
function getVisualDimensions(rotation, imageAspectRatio) {
|
|
@@ -55,20 +58,43 @@ function getMinZoomForCover(rotation, imageAspectRatio, cropRect) {
|
|
|
55
58
|
const spanBeta = cropHalfW * absS + cropHalfH * absC;
|
|
56
59
|
const zoomFromAlpha = 2 * spanAlpha / aspectRatio;
|
|
57
60
|
const zoomFromBeta = 2 * spanBeta;
|
|
58
|
-
return Math.max(
|
|
61
|
+
return Math.max(zoomFromAlpha, zoomFromBeta);
|
|
62
|
+
}
|
|
63
|
+
function getMinZoom(state) {
|
|
64
|
+
if (!state.image) {
|
|
65
|
+
return import_constants.MIN_ZOOM;
|
|
66
|
+
}
|
|
67
|
+
const imageSize = {
|
|
68
|
+
width: state.image.naturalWidth,
|
|
69
|
+
height: state.image.naturalHeight
|
|
70
|
+
};
|
|
71
|
+
if (!(0, import_sanitize.isValidSize)(imageSize)) {
|
|
72
|
+
return import_constants.MIN_ZOOM;
|
|
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
|
+
);
|
|
59
84
|
}
|
|
60
85
|
function getImageCropBounds(state, elementSize, visualSize) {
|
|
61
|
-
if (
|
|
86
|
+
if (!(0, import_sanitize.isValidSize)(elementSize) || !(0, import_sanitize.isValidSize)(visualSize)) {
|
|
62
87
|
return { minX: 0, minY: 0, maxX: 1, maxY: 1 };
|
|
63
88
|
}
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
89
|
+
const safeState = (0, import_sanitize.sanitizeCropperState)(state);
|
|
90
|
+
const tx = safeState.pan.x * visualSize.width;
|
|
91
|
+
const ty = safeState.pan.y * visualSize.height;
|
|
92
|
+
const rad = (0, import_rotation.degreesToRadians)(safeState.rotation);
|
|
67
93
|
const cos = Math.cos(rad);
|
|
68
94
|
const sin = Math.sin(rad);
|
|
69
|
-
const sx =
|
|
70
|
-
const sy =
|
|
71
|
-
const z =
|
|
95
|
+
const sx = safeState.flip.horizontal ? -1 : 1;
|
|
96
|
+
const sy = safeState.flip.vertical ? -1 : 1;
|
|
97
|
+
const z = safeState.zoom;
|
|
72
98
|
const ma = sx * cos * z;
|
|
73
99
|
const mb = sy * sin * z;
|
|
74
100
|
const mc = -sx * sin * z;
|
|
@@ -103,21 +129,26 @@ function getImageCropBounds(state, elementSize, visualSize) {
|
|
|
103
129
|
};
|
|
104
130
|
}
|
|
105
131
|
function restrictCropRect(cropRect, zoom, rotation, imageAspectRatio) {
|
|
106
|
-
const
|
|
107
|
-
const
|
|
132
|
+
const safeRect = (0, import_sanitize.sanitizeRect)(cropRect);
|
|
133
|
+
const zoomCandidate = (0, import_sanitize.safeBoundedNumber)(zoom, 1);
|
|
134
|
+
const safeZoom = zoomCandidate >= Number.EPSILON ? zoomCandidate : 1;
|
|
135
|
+
const safeRotation = (0, import_sanitize.safeBoundedNumber)(rotation, 0);
|
|
136
|
+
const safeAspect = (0, import_sanitize.safeBoundedNumber)(imageAspectRatio, 1);
|
|
137
|
+
const aspectRatio = Math.max(safeAspect, Number.EPSILON);
|
|
138
|
+
const snapRotation = Math.round(safeRotation / 90) * 90;
|
|
108
139
|
const { visualW, visualH } = getVisualDimensions(
|
|
109
140
|
snapRotation,
|
|
110
141
|
aspectRatio
|
|
111
142
|
);
|
|
112
|
-
const { absC, absS } = getVisualDimensions(
|
|
113
|
-
const W =
|
|
114
|
-
const H =
|
|
143
|
+
const { absC, absS } = getVisualDimensions(safeRotation, aspectRatio);
|
|
144
|
+
const W = safeRect.width;
|
|
145
|
+
const H = safeRect.height;
|
|
115
146
|
const cropWPx = W * visualW;
|
|
116
147
|
const cropHPx = H * visualH;
|
|
117
148
|
const spanAlpha = cropWPx * absC + cropHPx * absS;
|
|
118
149
|
const spanBeta = cropWPx * absS + cropHPx * absC;
|
|
119
|
-
const limitAlpha = aspectRatio *
|
|
120
|
-
const limitBeta =
|
|
150
|
+
const limitAlpha = aspectRatio * safeZoom;
|
|
151
|
+
const limitBeta = safeZoom;
|
|
121
152
|
let t = 1;
|
|
122
153
|
if (spanAlpha > 0) {
|
|
123
154
|
t = Math.min(t, limitAlpha / spanAlpha);
|
|
@@ -126,12 +157,12 @@ function restrictCropRect(cropRect, zoom, rotation, imageAspectRatio) {
|
|
|
126
157
|
t = Math.min(t, limitBeta / spanBeta);
|
|
127
158
|
}
|
|
128
159
|
if (t >= 1 - EPSILON) {
|
|
129
|
-
return
|
|
160
|
+
return safeRect;
|
|
130
161
|
}
|
|
131
162
|
const newW = W * t;
|
|
132
163
|
const newH = H * t;
|
|
133
|
-
const centerX =
|
|
134
|
-
const centerY =
|
|
164
|
+
const centerX = safeRect.x + W / 2;
|
|
165
|
+
const centerY = safeRect.y + H / 2;
|
|
135
166
|
let newX = centerX - newW / 2;
|
|
136
167
|
let newY = centerY - newH / 2;
|
|
137
168
|
newX = Math.max(0, Math.min(newX, 1 - newW));
|
|
@@ -142,16 +173,21 @@ var CANONICAL_CONTAINER = { width: 1e3, height: 1e3 };
|
|
|
142
173
|
var _scratchMat = import_gl_matrix.mat2d.create();
|
|
143
174
|
var _scratchVec = import_gl_matrix.vec2.create();
|
|
144
175
|
function restrictPanZoom(state, imageSize, cropRect) {
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
176
|
+
const safeState = (0, import_sanitize.sanitizeCropperState)(state);
|
|
177
|
+
const safeCropRect = (0, import_sanitize.sanitizeRect)(cropRect);
|
|
178
|
+
const aspectRatio = (0, import_sanitize.isValidSize)(imageSize) ? imageSize.width / imageSize.height : 1;
|
|
179
|
+
const minZoom = Math.max(
|
|
180
|
+
import_constants.ABSOLUTE_MIN_ZOOM,
|
|
181
|
+
getMinZoomForCover(safeState.rotation, aspectRatio, safeCropRect)
|
|
182
|
+
);
|
|
183
|
+
const zoom = Math.min(import_constants.MAX_ZOOM, Math.max(safeState.zoom, minZoom));
|
|
184
|
+
const candidateState = { ...safeState, zoom };
|
|
149
185
|
const camera = (0, import_camera.createCamera)(
|
|
150
186
|
candidateState,
|
|
151
187
|
CANONICAL_CONTAINER,
|
|
152
188
|
imageSize
|
|
153
189
|
);
|
|
154
|
-
const snapRotation = Math.round(
|
|
190
|
+
const snapRotation = Math.round(safeState.rotation / 90) * 90;
|
|
155
191
|
const baseCamera = (0, import_camera.createCamera)(
|
|
156
192
|
{
|
|
157
193
|
...candidateState,
|
|
@@ -165,20 +201,20 @@ function restrictPanZoom(state, imageSize, cropRect) {
|
|
|
165
201
|
const visibleBounds = (0, import_camera.getVisibleBounds)(baseCamera);
|
|
166
202
|
const stencilCorners = [
|
|
167
203
|
[
|
|
168
|
-
visibleBounds.left +
|
|
169
|
-
visibleBounds.top +
|
|
204
|
+
visibleBounds.left + safeCropRect.x * visibleBounds.width,
|
|
205
|
+
visibleBounds.top + safeCropRect.y * visibleBounds.height
|
|
170
206
|
],
|
|
171
207
|
[
|
|
172
|
-
visibleBounds.left + (
|
|
173
|
-
visibleBounds.top +
|
|
208
|
+
visibleBounds.left + (safeCropRect.x + safeCropRect.width) * visibleBounds.width,
|
|
209
|
+
visibleBounds.top + safeCropRect.y * visibleBounds.height
|
|
174
210
|
],
|
|
175
211
|
[
|
|
176
|
-
visibleBounds.left + (
|
|
177
|
-
visibleBounds.top + (
|
|
212
|
+
visibleBounds.left + (safeCropRect.x + safeCropRect.width) * visibleBounds.width,
|
|
213
|
+
visibleBounds.top + (safeCropRect.y + safeCropRect.height) * visibleBounds.height
|
|
178
214
|
],
|
|
179
215
|
[
|
|
180
|
-
visibleBounds.left +
|
|
181
|
-
visibleBounds.top + (
|
|
216
|
+
visibleBounds.left + safeCropRect.x * visibleBounds.width,
|
|
217
|
+
visibleBounds.top + (safeCropRect.y + safeCropRect.height) * visibleBounds.height
|
|
182
218
|
]
|
|
183
219
|
];
|
|
184
220
|
import_gl_matrix.mat2d.invert(_scratchMat, camera);
|
|
@@ -203,7 +239,7 @@ function restrictPanZoom(state, imageSize, cropRect) {
|
|
|
203
239
|
}
|
|
204
240
|
}
|
|
205
241
|
if (minWx >= -EPSILON && maxWx <= 1 + EPSILON && minWy >= -EPSILON && maxWy <= 1 + EPSILON) {
|
|
206
|
-
return { pan:
|
|
242
|
+
return { pan: safeState.pan, zoom };
|
|
207
243
|
}
|
|
208
244
|
let dwx = 0;
|
|
209
245
|
let dwy = 0;
|
|
@@ -223,8 +259,8 @@ function restrictPanZoom(state, imageSize, cropRect) {
|
|
|
223
259
|
}
|
|
224
260
|
const dsx = camera[0] * dwx + camera[2] * dwy;
|
|
225
261
|
const dsy = camera[1] * dwx + camera[3] * dwy;
|
|
226
|
-
const newPanX =
|
|
227
|
-
const newPanY =
|
|
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);
|
|
228
264
|
return {
|
|
229
265
|
pan: { x: newPanX, y: newPanY },
|
|
230
266
|
zoom
|
|
@@ -233,6 +269,7 @@ function restrictPanZoom(state, imageSize, cropRect) {
|
|
|
233
269
|
// Annotate the CommonJS export names for ESM import in node:
|
|
234
270
|
0 && (module.exports = {
|
|
235
271
|
getImageCropBounds,
|
|
272
|
+
getMinZoom,
|
|
236
273
|
restrictCropRect,
|
|
237
274
|
restrictPanZoom
|
|
238
275
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/containment.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\n\n/** Floating-point epsilon for \"close enough to equal\" comparisons. */\nconst EPSILON = 1e-9;\n\n/**\n * Compute the visual (rotated) bounding-box dimensions in pixel-proportional\n * units where the unrotated image is `a \u00D7 1` (renderedW = a, renderedH = 1).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @return Visual dimensions and trig helpers.\n */\nfunction getVisualDimensions(\n\trotation: number,\n\timageAspectRatio: number\n): { visualW: number; visualH: number; absC: number; absS: number } {\n\tconst rad = degreesToRadians( rotation );\n\tconst absC = Math.abs( Math.cos( rad ) );\n\tconst absS = Math.abs( Math.sin( rad ) );\n\tconst bbox = getRotatedBBox( imageAspectRatio, 1, rotation );\n\treturn {\n\t\tvisualW: bbox.width,\n\t\tvisualH: bbox.height,\n\t\tabsC,\n\t\tabsS,\n\t};\n}\n\n/**\n * Calculates the minimum zoom factor needed for the rotated image to fully cover\n * the crop rectangle, using normalized coordinates and imageAspectRatio.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n * The crop rect is in visual-normalized space and must be scaled by the\n * rotation-dependent visual dimensions before projecting into the image-local\n * frame.\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The minimum zoom factor (always >= 1).\n */\nfunction getMinZoomForCover(\n\trotation: number,\n\timageAspectRatio: number,\n\tcropRect: NormalizedRect\n): number {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// The crop rect lives in the SNAP-rotation visual bbox \u2014 that's how the\n\t// stencil and preview position it (see createCamera / getImageFit). Use\n\t// the snap-rotation dimensions to convert crop fractions to pixels.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\t// Projection into the image-local frame uses the TRUE rotation angle \u2014\n\t// that's the actual orientation of the image under the stencil.\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\n\t// Crop half-extents in pixel-proportional space.\n\tconst cropHalfW = ( cropRect.width * snapVisualW ) / 2;\n\tconst cropHalfH = ( cropRect.height * snapVisualH ) / 2;\n\n\t// AABB of the crop rect projected into the image-local (unrotated) frame.\n\tconst spanAlpha = cropHalfW * absC + cropHalfH * absS;\n\tconst spanBeta = cropHalfW * absS + cropHalfH * absC;\n\n\t// Image half-extents at zoom z: (aspectRatio*z/2, z/2).\n\t// Coverage requires: aspectRatio*z/2 >= spanAlpha AND z/2 >= spanBeta.\n\tconst zoomFromAlpha = ( 2 * spanAlpha ) / aspectRatio;\n\tconst zoomFromBeta = 2 * spanBeta;\n\n\treturn Math.max( 1, zoomFromAlpha, zoomFromBeta );\n}\n\n/**\n * Compute the crop handle bounds in normalized visual space \u2014 the\n * axis-aligned bounding box (AABB) of the actual image footprint at the\n * current pan/zoom/rotation.\n *\n * Returns the full image AABB without intersecting with the container\n * viewport. The viewport pan mechanism in the Cropper component allows\n * the canvas to scroll so handles can reach the image edge even when it\n * lies outside the visible canvas area.\n *\n * Unlike a static centerline-based calculation, this accounts for the\n * current pan position \u2014 if the user pans right, the left bound tightens\n * because the image's left edge has moved right.\n *\n * @param state The current cropper state (crop, zoom, rotation, flip).\n * @param elementSize The fitted (unrotated) image element dimensions in pixels.\n * @param visualSize The visual (rotated) image bounding box in pixels.\n * @return The min/max x and y that a crop rect edge can reach in normalized space.\n */\nexport function getImageCropBounds(\n\tstate: CropperState,\n\telementSize: Size,\n\tvisualSize: Size\n): { minX: number; minY: number; maxX: number; maxY: number } {\n\tif (\n\t\telementSize.width === 0 ||\n\t\telementSize.height === 0 ||\n\t\tvisualSize.width === 0 ||\n\t\tvisualSize.height === 0\n\t) {\n\t\treturn { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n\t}\n\n\t// Build the same CSS matrix as use-transform-style: flip * rotate * zoom.\n\t// Flip is outside rotation so it acts in viewport axes (see createCamera).\n\tconst tx = state.pan.x * visualSize.width;\n\tconst ty = state.pan.y * visualSize.height;\n\tconst rad = degreesToRadians( state.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = state.flip.horizontal ? -1 : 1;\n\tconst sy = state.flip.vertical ? -1 : 1;\n\tconst z = state.zoom;\n\tconst ma = sx * cos * z;\n\tconst mb = sy * sin * z;\n\tconst mc = -sx * sin * z;\n\tconst md = sy * cos * z;\n\n\t// Image element corners relative to element center.\n\tconst hw = elementSize.width / 2;\n\tconst hh = elementSize.height / 2;\n\tconst corners = [\n\t\t[ -hw, -hh ],\n\t\t[ hw, -hh ],\n\t\t[ hw, hh ],\n\t\t[ -hw, hh ],\n\t];\n\n\tlet imgMinX = Infinity;\n\tlet imgMaxX = -Infinity;\n\tlet imgMinY = Infinity;\n\tlet imgMaxY = -Infinity;\n\n\tfor ( const [ cx, cy ] of corners ) {\n\t\t// Screen offset from element center after CSS matrix.\n\t\tconst screenX = ma * cx + mc * cy + tx;\n\t\tconst screenY = mb * cx + md * cy + ty;\n\t\t// Convert to normalized visual space.\n\t\t// The element center is at the visual image center, which is at\n\t\t// normalized (0.5, 0.5). So screen offset / visualSize + 0.5.\n\t\tconst nx = screenX / visualSize.width + 0.5;\n\t\tconst ny = screenY / visualSize.height + 0.5;\n\t\timgMinX = Math.min( imgMinX, nx );\n\t\timgMaxX = Math.max( imgMaxX, nx );\n\t\timgMinY = Math.min( imgMinY, ny );\n\t\timgMaxY = Math.max( imgMaxY, ny );\n\t}\n\n\treturn {\n\t\tminX: imgMinX,\n\t\tminY: imgMinY,\n\t\tmaxX: imgMaxX,\n\t\tmaxY: imgMaxY,\n\t};\n}\n\n/**\n * Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.\n * If the crop rect is too large for the current zoom and rotation, it is scaled\n * down proportionally and re-centered.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n *\n * @param cropRect The crop rectangle in normalized coordinates.\n * @param zoom The current zoom factor.\n * @param rotation The rotation angle in degrees.\n * @param imageAspectRatio The image width / height ratio.\n * @return The restricted crop rectangle.\n */\nexport function restrictCropRect(\n\tcropRect: NormalizedRect,\n\tzoom: number,\n\trotation: number,\n\timageAspectRatio: number\n): NormalizedRect {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// Crop rect lives in the SNAP-rotation visual bbox (matching the stencil\n\t// layout); projection into the image-local frame uses the TRUE rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW, visualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\tconst W = cropRect.width;\n\tconst H = cropRect.height;\n\n\t// Crop full-extents in pixel-proportional space, projected to image-local frame.\n\tconst cropWPx = W * visualW;\n\tconst cropHPx = H * visualH;\n\tconst spanAlpha = cropWPx * absC + cropHPx * absS;\n\tconst spanBeta = cropWPx * absS + cropHPx * absC;\n\n\t// Image full-extents at zoom z: (aspectRatio*z, z).\n\tconst limitAlpha = aspectRatio * zoom;\n\tconst limitBeta = zoom;\n\n\tlet t = 1;\n\tif ( spanAlpha > 0 ) {\n\t\tt = Math.min( t, limitAlpha / spanAlpha );\n\t}\n\tif ( spanBeta > 0 ) {\n\t\tt = Math.min( t, limitBeta / spanBeta );\n\t}\n\tif ( t >= 1 - EPSILON ) {\n\t\t// Crop fits at the current zoom \u2014 no size change needed.\n\t\t// Position is handled by restrictPanZoom, not here.\n\t\treturn cropRect;\n\t}\n\tconst newW = W * t;\n\tconst newH = H * t;\n\tconst centerX = cropRect.x + W / 2;\n\tconst centerY = cropRect.y + H / 2;\n\tlet newX = centerX - newW / 2;\n\tlet newY = centerY - newH / 2;\n\tnewX = Math.max( 0, Math.min( newX, 1 - newW ) );\n\tnewY = Math.max( 0, Math.min( newY, 1 - newH ) );\n\treturn { x: newX, y: newY, width: newW, height: newH };\n}\n\n/**\n * Canonical container used internally by restrictPanZoom.\n * Containment is scale-invariant, so the actual size doesn't matter \u2014\n * only the relative geometry between stencil and image matters.\n */\nconst CANONICAL_CONTAINER: Size = { width: 1000, height: 1000 };\n\n// Pre-allocated scratch buffers for restrictPanZoom's hot path (runs on\n// every pointermove) to avoid Float32Array allocation per call.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers\n * the crop rectangle.\n *\n * Uses the camera matrix to project: builds a camera from the candidate state,\n * maps the stencil corners (axis-aligned in the visual bounding box) to world\n * space via the inverse camera, and checks that all world points lie within\n * [0,1]\u00D7[0,1]. If any point is outside, computes the minimal pan correction.\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the image in pixels.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The restricted crop pan and zoom values.\n */\nexport function restrictPanZoom(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect\n): { pan: { x: number; y: number }; zoom: number } {\n\t// Algorithm overview:\n\t// 1. Ensure zoom is high enough for the rotated image to cover the crop.\n\t// 2. Build a camera (world\u2192screen matrix) with the candidate state.\n\t// 3. Build a base camera (no pan, zoom=1) to find where the stencil\n\t// sits in screen space \u2014 the stencil is anchored to the container,\n\t// not the image, so it doesn't move with pan or scale with zoom.\n\t// 4. Project the 4 stencil corners through the INVERSE of the main\n\t// camera to get world-space positions. A world point outside [0,1]\n\t// means that corner of the stencil isn't covered by the image.\n\t// 5. Compute the minimal translation in world space to push all corners\n\t// back inside [0,1].\n\t// 6. Convert the world-space correction to a pan-field correction by\n\t// mapping it through the camera's linear part back to screen space,\n\t// then dividing by the visual bounds.\n\tconst aspectRatio =\n\t\timageSize.width > 0 && imageSize.height > 0\n\t\t\t? imageSize.width / imageSize.height\n\t\t\t: 1;\n\tconst minZoom = getMinZoomForCover( state.rotation, aspectRatio, cropRect );\n\tconst zoom = Math.max( state.zoom, minZoom );\n\n\t// Step 2: build camera with candidate pan and corrected zoom.\n\tconst candidateState = { ...state, zoom };\n\tconst camera = createCamera(\n\t\tcandidateState,\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\n\t// Build a base camera (zero pan, zoom=1) to get stencil positions.\n\t// The stencil is anchored to the container and laid out using the\n\t// nearest 90\u00B0 rotation (matching `getImageFit`), so it's stable\n\t// through fine rotation. CSS zoom only affects the <img> element,\n\t// not the stencil.\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst baseCamera = createCamera(\n\t\t{\n\t\t\t...candidateState,\n\t\t\tpan: { x: 0, y: 0 },\n\t\t\tzoom: 1,\n\t\t\trotation: snapRotation,\n\t\t},\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\t// Stencil corners in screen space (axis-aligned rect within visual bounds).\n\tconst stencilCorners: [ number, number ][] = [\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t];\n\n\t// Map stencil corners to world space via inverse camera.\n\t// If a world point is outside [0,1], the image doesn't cover that spot.\n\t// Reuse module-level scratch buffers to avoid allocation per frame.\n\tmat2d.invert( _scratchMat, camera );\n\n\tlet minWx = Infinity;\n\tlet maxWx = -Infinity;\n\tlet minWy = Infinity;\n\tlet maxWy = -Infinity;\n\n\tfor ( const corner of stencilCorners ) {\n\t\tvec2.transformMat2d( _scratchVec, corner, _scratchMat );\n\t\tconst w = _scratchVec;\n\t\tif ( w[ 0 ] < minWx ) {\n\t\t\tminWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 0 ] > maxWx ) {\n\t\t\tmaxWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 1 ] < minWy ) {\n\t\t\tminWy = w[ 1 ];\n\t\t}\n\t\tif ( w[ 1 ] > maxWy ) {\n\t\t\tmaxWy = w[ 1 ];\n\t\t}\n\t}\n\n\t// If all world points are in [0,1], no correction needed.\n\tif (\n\t\tminWx >= -EPSILON &&\n\t\tmaxWx <= 1 + EPSILON &&\n\t\tminWy >= -EPSILON &&\n\t\tmaxWy <= 1 + EPSILON\n\t) {\n\t\treturn { pan: state.pan, zoom };\n\t}\n\n\t// Compute world-space correction needed.\n\t// If minWx < 0, we need to shift world points right by |minWx|.\n\t// If maxWx > 1, we need to shift world points left by (maxWx - 1).\n\t// If both, we're over-constrained (crop too big) \u2014 getMinZoomForCover\n\t// should have prevented this.\n\tlet dwx = 0;\n\tlet dwy = 0;\n\n\tif ( minWx < 0 && maxWx <= 1 + EPSILON ) {\n\t\tdwx = -minWx;\n\t} else if ( maxWx > 1 && minWx >= -EPSILON ) {\n\t\tdwx = 1 - maxWx;\n\t} else if ( minWx < 0 && maxWx > 1 ) {\n\t\t// Over-constrained: center it.\n\t\tdwx = ( 1 - maxWx - minWx ) / 2;\n\t}\n\n\tif ( minWy < 0 && maxWy <= 1 + EPSILON ) {\n\t\tdwy = -minWy;\n\t} else if ( maxWy > 1 && minWy >= -EPSILON ) {\n\t\tdwy = 1 - maxWy;\n\t} else if ( minWy < 0 && maxWy > 1 ) {\n\t\tdwy = ( 1 - maxWy - minWy ) / 2;\n\t}\n\n\t// Convert world-space correction to screen-space correction.\n\t// The camera's 2\u00D72 linear part (indices [0,1,2,3]) maps world deltas\n\t// to screen deltas: screenDelta = linear * worldDelta.\n\tconst dsx = camera[ 0 ] * dwx + camera[ 2 ] * dwy;\n\tconst dsy = camera[ 1 ] * dwx + camera[ 3 ] * dwy;\n\n\t// Convert screen-space correction to pan-field correction.\n\t// Pan in screen pixels = pan.x * visualW, pan.y * visualH.\n\t// The correction is subtractive: a positive world shift (dw > 0) means\n\t// the image needs to move opposite to pan direction, so pan decreases.\n\tconst newPanX =\n\t\tstate.pan.x -\n\t\t( visibleBounds.width > 0 ? dsx / visibleBounds.width : 0 );\n\tconst newPanY =\n\t\tstate.pan.y -\n\t\t( visibleBounds.height > 0 ? dsy / visibleBounds.height : 0 );\n\n\treturn {\n\t\tpan: { x: newPanX, y: newPanY },\n\t\tzoom,\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAA4B;AAM5B,sBAAiC;AACjC,oBAA+D;AAG/D,IAAM,UAAU;AAUhB,SAAS,oBACR,UACA,kBACmE;AACnE,QAAM,UAAM,kCAAkB,QAAS;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,WAAO,8BAAgB,kBAAkB,GAAG,QAAS;AAC3D,SAAO;AAAA,IACN,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,IACd;AAAA,IACA;AAAA,EACD;AACD;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from './types';\nimport { ABSOLUTE_MIN_ZOOM, MAX_ZOOM, MIN_ZOOM } from './constants';\nimport { degreesToRadians } from './math/rotation';\nimport {\n\tisValidSize,\n\tsafeBoundedNumber,\n\tsanitizeCropperState,\n\tsanitizeRect,\n} from './math/sanitize';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\n\n/** Floating-point epsilon for \"close enough to equal\" comparisons. */\nconst EPSILON = 1e-9;\n\n/**\n * Compute the visual (rotated) bounding-box dimensions in pixel-proportional\n * units where the unrotated image is `a \u00D7 1` (renderedW = a, renderedH = 1).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @return Visual dimensions and trig helpers.\n */\nfunction getVisualDimensions(\n\trotation: number,\n\timageAspectRatio: number\n): { visualW: number; visualH: number; absC: number; absS: number } {\n\tconst rad = degreesToRadians( rotation );\n\tconst absC = Math.abs( Math.cos( rad ) );\n\tconst absS = Math.abs( Math.sin( rad ) );\n\tconst bbox = getRotatedBBox( imageAspectRatio, 1, rotation );\n\treturn {\n\t\tvisualW: bbox.width,\n\t\tvisualH: bbox.height,\n\t\tabsC,\n\t\tabsS,\n\t};\n}\n\n/**\n * The geometric minimum zoom required for the rotated image to fully cover the\n * crop rectangle. Works in pixel-proportional space where the unrotated image\n * is a\u00D71; the crop rect lives in visual-normalized space and is scaled by the\n * rotation-dependent visual dimensions before projecting into the image-local\n * frame.\n *\n * Returns 0 for a degenerate (zero-area) crop \u2014 callers compose the result\n * with their own floor (typically the current zoom or `MIN_ZOOM`).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The minimum zoom factor needed for coverage.\n */\nfunction getMinZoomForCover(\n\trotation: number,\n\timageAspectRatio: number,\n\tcropRect: NormalizedRect\n): number {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// The crop rect lives in the SNAP-rotation visual bbox \u2014 that's how the\n\t// stencil and preview position it (see createCamera / getImageFit). Use\n\t// the snap-rotation dimensions to convert crop fractions to pixels.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\t// Projection into the image-local frame uses the TRUE rotation angle \u2014\n\t// that's the actual orientation of the image under the stencil.\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\n\t// Crop half-extents in pixel-proportional space.\n\tconst cropHalfW = ( cropRect.width * snapVisualW ) / 2;\n\tconst cropHalfH = ( cropRect.height * snapVisualH ) / 2;\n\n\t// AABB of the crop rect projected into the image-local (unrotated) frame.\n\tconst spanAlpha = cropHalfW * absC + cropHalfH * absS;\n\tconst spanBeta = cropHalfW * absS + cropHalfH * absC;\n\n\t// Image half-extents at zoom z: (aspectRatio*z/2, z/2).\n\t// Coverage requires: aspectRatio*z/2 >= spanAlpha AND z/2 >= spanBeta.\n\tconst zoomFromAlpha = ( 2 * spanAlpha ) / aspectRatio;\n\tconst zoomFromBeta = 2 * spanBeta;\n\n\treturn Math.max( zoomFromAlpha, zoomFromBeta );\n}\n\n/**\n * Resolves the effective minimum zoom for the current state \u2014 the coverage-\n * aware floor when an image is loaded, falling back to `MIN_ZOOM` otherwise.\n * Used by both the cropper's interaction layer and the zoom slider so the\n * floor stays consistent across surfaces.\n *\n * @param state The current cropper state.\n * @return The minimum zoom factor.\n */\nexport function getMinZoom( state: CropperState ): number {\n\tif ( ! state.image ) {\n\t\treturn MIN_ZOOM;\n\t}\n\tconst imageSize = {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t};\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn MIN_ZOOM;\n\t}\n\tconst safeState = sanitizeCropperState( state );\n\tconst aspectRatio = imageSize.width / imageSize.height;\n\treturn Math.max(\n\t\tABSOLUTE_MIN_ZOOM,\n\t\tgetMinZoomForCover(\n\t\t\tsafeState.rotation,\n\t\t\taspectRatio,\n\t\t\tsafeState.cropRect\n\t\t)\n\t);\n}\n\n/**\n * Compute the crop handle bounds in normalized visual space \u2014 the\n * axis-aligned bounding box (AABB) of the actual image footprint at the\n * current pan/zoom/rotation.\n *\n * Returns the full image AABB without intersecting with the container\n * viewport. The viewport pan mechanism in the Cropper component allows\n * the canvas to scroll so handles can reach the image edge even when it\n * lies outside the visible canvas area.\n *\n * Unlike a static centerline-based calculation, this accounts for the\n * current pan position \u2014 if the user pans right, the left bound tightens\n * because the image's left edge has moved right.\n *\n * @param state The current cropper state (crop, zoom, rotation, flip).\n * @param elementSize The fitted (unrotated) image element dimensions in pixels.\n * @param visualSize The visual (rotated) image bounding box in pixels.\n * @return The min/max x and y that a crop rect edge can reach in normalized space.\n */\nexport function getImageCropBounds(\n\tstate: CropperState,\n\telementSize: Size,\n\tvisualSize: Size\n): { minX: number; minY: number; maxX: number; maxY: number } {\n\tif ( ! isValidSize( elementSize ) || ! isValidSize( visualSize ) ) {\n\t\treturn { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n\t}\n\n\tconst safeState = sanitizeCropperState( state );\n\n\t// Build the same CSS matrix as use-transform-style: flip * rotate * zoom.\n\t// Flip is outside rotation so it acts in viewport axes (see createCamera).\n\tconst tx = safeState.pan.x * visualSize.width;\n\tconst ty = safeState.pan.y * visualSize.height;\n\tconst rad = degreesToRadians( safeState.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = safeState.flip.horizontal ? -1 : 1;\n\tconst sy = safeState.flip.vertical ? -1 : 1;\n\tconst z = safeState.zoom;\n\tconst ma = sx * cos * z;\n\tconst mb = sy * sin * z;\n\tconst mc = -sx * sin * z;\n\tconst md = sy * cos * z;\n\n\t// Image element corners relative to element center.\n\tconst hw = elementSize.width / 2;\n\tconst hh = elementSize.height / 2;\n\tconst corners = [\n\t\t[ -hw, -hh ],\n\t\t[ hw, -hh ],\n\t\t[ hw, hh ],\n\t\t[ -hw, hh ],\n\t];\n\n\tlet imgMinX = Infinity;\n\tlet imgMaxX = -Infinity;\n\tlet imgMinY = Infinity;\n\tlet imgMaxY = -Infinity;\n\n\tfor ( const [ cx, cy ] of corners ) {\n\t\t// Screen offset from element center after CSS matrix.\n\t\tconst screenX = ma * cx + mc * cy + tx;\n\t\tconst screenY = mb * cx + md * cy + ty;\n\t\t// Convert to normalized visual space.\n\t\t// The element center is at the visual image center, which is at\n\t\t// normalized (0.5, 0.5). So screen offset / visualSize + 0.5.\n\t\tconst nx = screenX / visualSize.width + 0.5;\n\t\tconst ny = screenY / visualSize.height + 0.5;\n\t\timgMinX = Math.min( imgMinX, nx );\n\t\timgMaxX = Math.max( imgMaxX, nx );\n\t\timgMinY = Math.min( imgMinY, ny );\n\t\timgMaxY = Math.max( imgMaxY, ny );\n\t}\n\n\treturn {\n\t\tminX: imgMinX,\n\t\tminY: imgMinY,\n\t\tmaxX: imgMaxX,\n\t\tmaxY: imgMaxY,\n\t};\n}\n\n/**\n * Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.\n * If the crop rect is too large for the current zoom and rotation, it is scaled\n * down proportionally and re-centered.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n *\n * @param cropRect The crop rectangle in normalized coordinates.\n * @param zoom The current zoom factor.\n * @param rotation The rotation angle in degrees.\n * @param imageAspectRatio The image width / height ratio.\n * @return The restricted crop rectangle.\n */\nexport function restrictCropRect(\n\tcropRect: NormalizedRect,\n\tzoom: number,\n\trotation: number,\n\timageAspectRatio: number\n): NormalizedRect {\n\t// Guard against non-finite inputs. The reducer normalizes these, but\n\t// programmatic callers or deserialized state could still send NaN/\u00B1Infinity\n\t// through here, where it would silently propagate into the crop rect.\n\tconst safeRect = sanitizeRect( cropRect );\n\tconst zoomCandidate = safeBoundedNumber( zoom, 1 );\n\tconst safeZoom = zoomCandidate >= Number.EPSILON ? zoomCandidate : 1;\n\tconst safeRotation = safeBoundedNumber( rotation, 0 );\n\tconst safeAspect = safeBoundedNumber( imageAspectRatio, 1 );\n\tconst aspectRatio = Math.max( safeAspect, Number.EPSILON );\n\t// Crop rect lives in the SNAP-rotation visual bbox (matching the stencil\n\t// layout); projection into the image-local frame uses the TRUE rotation.\n\tconst snapRotation = Math.round( safeRotation / 90 ) * 90;\n\tconst { visualW, visualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\tconst { absC, absS } = getVisualDimensions( safeRotation, aspectRatio );\n\tconst W = safeRect.width;\n\tconst H = safeRect.height;\n\n\t// Crop full-extents in pixel-proportional space, projected to image-local frame.\n\tconst cropWPx = W * visualW;\n\tconst cropHPx = H * visualH;\n\tconst spanAlpha = cropWPx * absC + cropHPx * absS;\n\tconst spanBeta = cropWPx * absS + cropHPx * absC;\n\n\t// Image full-extents at zoom z: (aspectRatio*z, z).\n\tconst limitAlpha = aspectRatio * safeZoom;\n\tconst limitBeta = safeZoom;\n\n\tlet t = 1;\n\tif ( spanAlpha > 0 ) {\n\t\tt = Math.min( t, limitAlpha / spanAlpha );\n\t}\n\tif ( spanBeta > 0 ) {\n\t\tt = Math.min( t, limitBeta / spanBeta );\n\t}\n\tif ( t >= 1 - EPSILON ) {\n\t\t// Crop fits at the current zoom \u2014 no size change needed.\n\t\t// Return the sanitized rect (not the raw arg) so non-finite fields\n\t\t// don't slip through this path. Position is handled by restrictPanZoom.\n\t\treturn safeRect;\n\t}\n\tconst newW = W * t;\n\tconst newH = H * t;\n\tconst centerX = safeRect.x + W / 2;\n\tconst centerY = safeRect.y + H / 2;\n\tlet newX = centerX - newW / 2;\n\tlet newY = centerY - newH / 2;\n\tnewX = Math.max( 0, Math.min( newX, 1 - newW ) );\n\tnewY = Math.max( 0, Math.min( newY, 1 - newH ) );\n\treturn { x: newX, y: newY, width: newW, height: newH };\n}\n\n/**\n * Canonical container used internally by restrictPanZoom.\n * Containment is scale-invariant, so the actual size doesn't matter \u2014\n * only the relative geometry between stencil and image matters.\n */\nconst CANONICAL_CONTAINER: Size = { width: 1000, height: 1000 };\n\n// Pre-allocated scratch buffers for restrictPanZoom's hot path (runs on\n// every pointermove) to avoid Float32Array allocation per call.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers\n * the crop rectangle.\n *\n * Uses the camera matrix to project: builds a camera from the candidate state,\n * maps the stencil corners (axis-aligned in the visual bounding box) to world\n * space via the inverse camera, and checks that all world points lie within\n * [0,1]\u00D7[0,1]. If any point is outside, computes the minimal pan correction.\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the image in pixels.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The restricted crop pan and zoom values.\n */\nexport function restrictPanZoom(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect\n): { pan: { x: number; y: number }; zoom: number } {\n\t// Algorithm overview:\n\t// 1. Ensure zoom is high enough for the rotated image to cover the crop.\n\t// 2. Build a camera (world\u2192screen matrix) with the candidate state.\n\t// 3. Build a base camera (no pan, zoom=1) to find where the stencil\n\t// sits in screen space \u2014 the stencil is anchored to the container,\n\t// not the image, so it doesn't move with pan or scale with zoom.\n\t// 4. Project the 4 stencil corners through the INVERSE of the main\n\t// camera to get world-space positions. A world point outside [0,1]\n\t// means that corner of the stencil isn't covered by the image.\n\t// 5. Compute the minimal translation in world space to push all corners\n\t// back inside [0,1].\n\t// 6. Convert the world-space correction to a pan-field correction by\n\t// mapping it through the camera's linear part back to screen space,\n\t// then dividing by the visual bounds.\n\tconst safeState = sanitizeCropperState( state );\n\tconst safeCropRect = sanitizeRect( cropRect );\n\t// Use `isValidSize` rather than a bare `> 0` check so Infinity dims\n\t// don't drive `Infinity / Infinity = NaN` into `getMinZoomForCover`\n\t// and leak as `zoom: NaN` through the no-correction early return.\n\tconst aspectRatio = isValidSize( imageSize )\n\t\t? imageSize.width / imageSize.height\n\t\t: 1;\n\tconst minZoom = Math.max(\n\t\tABSOLUTE_MIN_ZOOM,\n\t\tgetMinZoomForCover( safeState.rotation, aspectRatio, safeCropRect )\n\t);\n\tconst zoom = Math.min( MAX_ZOOM, Math.max( safeState.zoom, minZoom ) );\n\n\t// Step 2: build camera with candidate pan and corrected zoom.\n\tconst candidateState = { ...safeState, zoom };\n\tconst camera = createCamera(\n\t\tcandidateState,\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\n\t// Build a base camera (zero pan, zoom=1) to get stencil positions.\n\t// The stencil is anchored to the container and laid out using the\n\t// nearest 90\u00B0 rotation (matching `getImageFit`), so it's stable\n\t// through fine rotation. CSS zoom only affects the <img> element,\n\t// not the stencil.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\tconst baseCamera = createCamera(\n\t\t{\n\t\t\t...candidateState,\n\t\t\tpan: { x: 0, y: 0 },\n\t\t\tzoom: 1,\n\t\t\trotation: snapRotation,\n\t\t},\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\t// Stencil corners in screen space (axis-aligned rect within visual bounds).\n\tconst stencilCorners: [ number, number ][] = [\n\t\t[\n\t\t\tvisibleBounds.left + safeCropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top + safeCropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( safeCropRect.x + safeCropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top + safeCropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( safeCropRect.x + safeCropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( safeCropRect.y + safeCropRect.height ) * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left + safeCropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( safeCropRect.y + safeCropRect.height ) * visibleBounds.height,\n\t\t],\n\t];\n\n\t// Map stencil corners to world space via inverse camera.\n\t// If a world point is outside [0,1], the image doesn't cover that spot.\n\t// Reuse module-level scratch buffers to avoid allocation per frame.\n\tmat2d.invert( _scratchMat, camera );\n\n\tlet minWx = Infinity;\n\tlet maxWx = -Infinity;\n\tlet minWy = Infinity;\n\tlet maxWy = -Infinity;\n\n\tfor ( const corner of stencilCorners ) {\n\t\tvec2.transformMat2d( _scratchVec, corner, _scratchMat );\n\t\tconst w = _scratchVec;\n\t\tif ( w[ 0 ] < minWx ) {\n\t\t\tminWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 0 ] > maxWx ) {\n\t\t\tmaxWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 1 ] < minWy ) {\n\t\t\tminWy = w[ 1 ];\n\t\t}\n\t\tif ( w[ 1 ] > maxWy ) {\n\t\t\tmaxWy = w[ 1 ];\n\t\t}\n\t}\n\n\t// If all world points are in [0,1], no correction needed.\n\tif (\n\t\tminWx >= -EPSILON &&\n\t\tmaxWx <= 1 + EPSILON &&\n\t\tminWy >= -EPSILON &&\n\t\tmaxWy <= 1 + EPSILON\n\t) {\n\t\treturn { pan: safeState.pan, zoom };\n\t}\n\n\t// Compute world-space correction needed.\n\t// If minWx < 0, we need to shift world points right by |minWx|.\n\t// If maxWx > 1, we need to shift world points left by (maxWx - 1).\n\t// If both, we're over-constrained (crop too big) \u2014 getMinZoomForCover\n\t// should have prevented this.\n\tlet dwx = 0;\n\tlet dwy = 0;\n\n\tif ( minWx < 0 && maxWx <= 1 + EPSILON ) {\n\t\tdwx = -minWx;\n\t} else if ( maxWx > 1 && minWx >= -EPSILON ) {\n\t\tdwx = 1 - maxWx;\n\t} else if ( minWx < 0 && maxWx > 1 ) {\n\t\t// Over-constrained: center it.\n\t\tdwx = ( 1 - maxWx - minWx ) / 2;\n\t}\n\n\tif ( minWy < 0 && maxWy <= 1 + EPSILON ) {\n\t\tdwy = -minWy;\n\t} else if ( maxWy > 1 && minWy >= -EPSILON ) {\n\t\tdwy = 1 - maxWy;\n\t} else if ( minWy < 0 && maxWy > 1 ) {\n\t\tdwy = ( 1 - maxWy - minWy ) / 2;\n\t}\n\n\t// Convert world-space correction to screen-space correction.\n\t// The camera's 2\u00D72 linear part (indices [0,1,2,3]) maps world deltas\n\t// to screen deltas: screenDelta = linear * worldDelta.\n\tconst dsx = camera[ 0 ] * dwx + camera[ 2 ] * dwy;\n\tconst dsy = camera[ 1 ] * dwx + camera[ 3 ] * dwy;\n\n\t// Convert screen-space correction to pan-field correction.\n\t// Pan in screen pixels = pan.x * visualW, pan.y * visualH.\n\t// The correction is subtractive: a positive world shift (dw > 0) means\n\t// the image needs to move opposite to pan direction, so pan decreases.\n\tconst newPanX =\n\t\tsafeState.pan.x -\n\t\t( visibleBounds.width > 0 ? dsx / visibleBounds.width : 0 );\n\tconst newPanY =\n\t\tsafeState.pan.y -\n\t\t( visibleBounds.height > 0 ? dsy / visibleBounds.height : 0 );\n\n\treturn {\n\t\tpan: { x: newPanX, y: newPanY },\n\t\tzoom,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAA4B;AAM5B,uBAAsD;AACtD,sBAAiC;AACjC,sBAKO;AACP,oBA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,SAAU;AAAA,EAC/B;AAEA,MAAK,QAAQ,KAAK,SAAS,IAAI,SAAU;AACxC,UAAM,CAAC;AAAA,EACR,WAAY,QAAQ,KAAK,SAAS,CAAC,SAAU;AAC5C,UAAM,IAAI;AAAA,EACX,WAAY,QAAQ,KAAK,QAAQ,GAAI;AACpC,WAAQ,IAAI,QAAQ,SAAU;AAAA,EAC/B;AAKA,QAAM,MAAM,OAAQ,CAAE,IAAI,MAAM,OAAQ,CAAE,IAAI;AAC9C,QAAM,MAAM,OAAQ,CAAE,IAAI,MAAM,OAAQ,CAAE,IAAI;AAM9C,QAAM,UACL,UAAU,IAAI,KACZ,cAAc,QAAQ,IAAI,MAAM,cAAc,QAAQ;AACzD,QAAM,UACL,UAAU,IAAI,KACZ,cAAc,SAAS,IAAI,MAAM,cAAc,SAAS;AAE3D,SAAO;AAAA,IACN,KAAK,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,IAC9B;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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/crop-rect.ts
|
|
21
|
+
var crop_rect_exports = {};
|
|
22
|
+
__export(crop_rect_exports, {
|
|
23
|
+
computeInscribedRect: () => computeInscribedRect
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(crop_rect_exports);
|
|
26
|
+
function computeInscribedRect(aspectRatio, visualSize) {
|
|
27
|
+
let w = 1;
|
|
28
|
+
let h = 1;
|
|
29
|
+
if (aspectRatio && aspectRatio > 0 && visualSize.width > 0) {
|
|
30
|
+
const normalizedRatio = aspectRatio * visualSize.height / visualSize.width;
|
|
31
|
+
if (normalizedRatio <= 1) {
|
|
32
|
+
w = normalizedRatio;
|
|
33
|
+
} else {
|
|
34
|
+
h = 1 / normalizedRatio;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
x: (1 - w) / 2,
|
|
39
|
+
y: (1 - h) / 2,
|
|
40
|
+
width: w,
|
|
41
|
+
height: h
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
computeInscribedRect
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=crop-rect.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/image-editor/core/crop-rect.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Size } from './types';\n\n/**\n * Largest rect of the given pixel aspect ratio that fits inside the\n * visual bounds, centered in [0,1] \u00D7 [0,1] normalized space. Returns\n * a full-frame rect (1\u00D71) if `aspectRatio` is unset or non-positive.\n *\n * The returned rect is the same in either freeform or fixed-crop\n * mode \u2014 it's the canonical \"centered crop for this ratio at this\n * canvas size\".\n *\n * @param aspectRatio Desired pixel width/height ratio. `undefined`\n * (or 0/negative) means no lock \u2014 returns full frame.\n * @param visualSize Rendered image dimensions in pixels.\n */\nexport function computeInscribedRect(\n\taspectRatio: number | undefined,\n\tvisualSize: Size\n): NormalizedRect {\n\tlet w = 1;\n\tlet h = 1;\n\tif ( aspectRatio && aspectRatio > 0 && visualSize.width > 0 ) {\n\t\t// normalizedRatio = w/h in normalized space that produces the\n\t\t// desired pixel aspect ratio.\n\t\t// pixelW = w * visualW, pixelH = h * visualH\n\t\t// pixelW / pixelH = aspectRatio\n\t\t// => w / h = aspectRatio * visualH / visualW\n\t\tconst normalizedRatio =\n\t\t\t( aspectRatio * visualSize.height ) / visualSize.width;\n\t\tif ( normalizedRatio <= 1 ) {\n\t\t\tw = normalizedRatio;\n\t\t} else {\n\t\t\th = 1 / normalizedRatio;\n\t\t}\n\t}\n\treturn {\n\t\tx: ( 1 - w ) / 2,\n\t\ty: ( 1 - h ) / 2,\n\t\twidth: w,\n\t\theight: h,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,qBACf,aACA,YACiB;AACjB,MAAI,IAAI;AACR,MAAI,IAAI;AACR,MAAK,eAAe,cAAc,KAAK,WAAW,QAAQ,GAAI;AAM7D,UAAM,kBACH,cAAc,WAAW,SAAW,WAAW;AAClD,QAAK,mBAAmB,GAAI;AAC3B,UAAI;AAAA,IACL,OAAO;AACN,UAAI,IAAI;AAAA,IACT;AAAA,EACD;AACA,SAAO;AAAA,IACN,IAAK,IAAI,KAAM;AAAA,IACf,IAAK,IAAI,KAAM;AAAA,IACf,OAAO;AAAA,IACP,QAAQ;AAAA,EACT;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -25,14 +25,21 @@ __export(core_exports, {
|
|
|
25
25
|
ORIGINAL_ASPECT_RATIO: () => import_constants.ORIGINAL_ASPECT_RATIO,
|
|
26
26
|
applyOperationToState: () => import_pipeline.applyOperationToState,
|
|
27
27
|
applyToCanvas: () => import_canvas_renderer.applyToCanvas,
|
|
28
|
+
areCropperStatesEqual: () => import_state.areCropperStatesEqual,
|
|
29
|
+
computeInscribedRect: () => import_crop_rect.computeInscribedRect,
|
|
30
|
+
cropperReducer: () => import_state.cropperReducer,
|
|
31
|
+
enforceContainment: () => import_state.enforceContainment,
|
|
28
32
|
exportCroppedImage: () => import_canvas_renderer.exportCroppedImage,
|
|
29
33
|
getSourceRegion: () => import_source_region.getSourceRegion,
|
|
30
34
|
getSourceRegionPercent: () => import_source_region.getSourceRegionPercent,
|
|
35
|
+
isStateDirty: () => import_state.isStateDirty,
|
|
31
36
|
stateFromPipeline: () => import_pipeline.stateFromPipeline
|
|
32
37
|
});
|
|
33
38
|
module.exports = __toCommonJS(core_exports);
|
|
34
39
|
var import_constants = require("./constants.cjs");
|
|
40
|
+
var import_state = require("./state.cjs");
|
|
35
41
|
var import_source_region = require("./source-region.cjs");
|
|
42
|
+
var import_crop_rect = require("./crop-rect.cjs");
|
|
36
43
|
var import_pipeline = require("./transforms/pipeline.cjs");
|
|
37
44
|
var import_canvas_renderer = require("./export/canvas-renderer.cjs");
|
|
38
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -42,9 +49,14 @@ var import_canvas_renderer = require("./export/canvas-renderer.cjs");
|
|
|
42
49
|
ORIGINAL_ASPECT_RATIO,
|
|
43
50
|
applyOperationToState,
|
|
44
51
|
applyToCanvas,
|
|
52
|
+
areCropperStatesEqual,
|
|
53
|
+
computeInscribedRect,
|
|
54
|
+
cropperReducer,
|
|
55
|
+
enforceContainment,
|
|
45
56
|
exportCroppedImage,
|
|
46
57
|
getSourceRegion,
|
|
47
58
|
getSourceRegionPercent,
|
|
59
|
+
isStateDirty,
|
|
48
60
|
stateFromPipeline
|
|
49
61
|
});
|
|
50
62
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Types\nexport type {\n\tCropperState,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tFlip,\n\tStencilProps,\n} from './types';\n//
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// Types\nexport type {\n\tCropperState,\n\tCropperAction,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tFlip,\n\tStencilProps,\n\tHandlePosition,\n} from './types';\n\n// Constants\nexport {\n\tDEFAULT_STATE,\n\tDEFAULT_ASPECT_RATIOS,\n\tORIGINAL_ASPECT_RATIO,\n} from './constants';\nexport type { AspectRatioPreset } from './constants';\n\n// Reducer + state helpers. `CropperAction` and `cropperReducer` are\n// exported so composite stores can delegate cropper actions through the\n// pure reducer (see `useMediaEditorState`). Most consumers should\n// instead drive state through the named setters on `CropperController`.\nexport {\n\tcropperReducer,\n\tenforceContainment,\n\tareCropperStatesEqual,\n\tisStateDirty,\n} from './state';\n\n// Source region (pixel and percentage)\nexport { getSourceRegion, getSourceRegionPercent } from './source-region';\nexport type { SourceRegion, SourceRegionPercent } from './source-region';\n\n// Crop-rect helpers\nexport { computeInscribedRect } from './crop-rect';\n\n// Pipeline\nexport {\n\tapplyOperationToState,\n\tstateFromPipeline,\n} from './transforms/pipeline';\n\n// Export / canvas\nexport { exportCroppedImage, applyToCanvas } from './export/canvas-renderer';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,uBAIO;AAOP,mBAKO;AAGP,2BAAwD;AAIxD,uBAAqC;AAGrC,sBAGO;AAGP,6BAAkD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|