@wordpress/media-editor 0.21.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 +12 -0
- package/build/components/media-editor/index.cjs +533 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -57
- 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 -72
- 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 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +76 -77
- 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 -710
- 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 +134 -112
- 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 -294
- 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 -673
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +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 +98 -96
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -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 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +68 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +106 -90
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/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 -686
- 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 -90
- 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 -286
- 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 +4 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -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-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-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 +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +1 -0
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +2 -1
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/components/media-editor/index.tsx +215 -162
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -2
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +16 -26
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-preview/index.tsx +66 -23
- 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 +1 -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 +19 -27
- 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 +2 -2
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +2 -6
- package/src/state/use-media-editor-state.ts +7 -5
- 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
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/image-editor/core/containment.ts"],
|
|
4
|
-
"sourcesContent": ["import { mat2d, vec2 } from 'gl-matrix';\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 × 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×1; 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 — 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 — 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 —\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 — 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 — 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 — 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×1.\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/±Infinity\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 — 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 —\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]×[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→screen 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 — 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° 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) — 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×2 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;AAAA,uBAA4B;AAE5B,uBAAsD;AACtD,sBAAiC;AACjC,sBAKO;AACP,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;AAiBA,SAAS,mBACR,UACA,kBACA,UACS;AACT,QAAM,cAAc,KAAK,IAAK,kBAAkB,OAAO,OAAQ;AAI/D,QAAM,eAAe,KAAK,MAAO,WAAW,EAAG,IAAI;AACnD,QAAM,EAAE,SAAS,aAAa,SAAS,YAAY,IAAI;AAAA,IACtD;AAAA,IACA;AAAA,EACD;AAGA,QAAM,EAAE,MAAM,KAAK,IAAI,oBAAqB,UAAU,WAAY;AAGlE,QAAM,YAAc,SAAS,QAAQ,cAAgB;AACrD,QAAM,YAAc,SAAS,SAAS,cAAgB;AAGtD,QAAM,YAAY,YAAY,OAAO,YAAY;AACjD,QAAM,WAAW,YAAY,OAAO,YAAY;AAIhD,QAAM,gBAAkB,IAAI,YAAc;AAC1C,QAAM,eAAe,IAAI;AAEzB,SAAO,KAAK,IAAK,eAAe,YAAa;AAC9C;AAWO,SAAS,WAAY,OAA8B;AACzD,MAAK,CAAE,MAAM,OA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CAAC,WACV,SAAS,IAAI,SACZ;AACD,WAAO,EAAE,KAAK,UAAU,KAAK,KAAK;AAAA,EACnC;AAOA,MAAI,MAAM;AACV,MAAI,MAAM;AAEV,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;AAEpC,WAAQ,IAAI,QAAQ,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
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"containment.cjs","names":["degreesToRadians","getRotatedBBox","MIN_ZOOM","isValidSize","sanitizeCropperState","ABSOLUTE_MIN_ZOOM","sanitizeRect","safeBoundedNumber","mat2d","vec2","MAX_ZOOM","createCamera","getVisibleBounds"],"sources":["../../../src/image-editor/core/containment.ts"],"sourcesContent":["import { mat2d, vec2 } from 'gl-matrix';\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 × 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×1; 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 — 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 — 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 —\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 — 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 — 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 — 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×1.\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/±Infinity\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 — 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 —\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]×[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→screen 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 — 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° 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) — 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×2 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"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,SAAS,oBACR,UACA,kBACmE;CACnE,MAAM,OAAA,GAAMA,mBAAAA,iBAAAA,CAAkB,QAAS;CACvC,MAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;CACvC,MAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;CACvC,MAAM,QAAA,GAAOC,YAAAA,eAAAA,CAAgB,kBAAkB,GAAG,QAAS;CAC3D,OAAO;EACN,SAAS,KAAK;EACd,SAAS,KAAK;EACd;EACA;CACD;AACD;;;;;;;;;;;;;;;;AAiBA,SAAS,mBACR,UACA,kBACA,UACS;CACT,MAAM,cAAc,KAAK,IAAK,kBAAkB,OAAO,OAAQ;CAK/D,MAAM,EAAE,SAAS,aAAa,SAAS,gBAAgB,oBADlC,KAAK,MAAO,WAAW,EAAG,IAAI,IAGlD,WACD;CAGA,MAAM,EAAE,MAAM,SAAS,oBAAqB,UAAU,WAAY;CAGlE,MAAM,YAAc,SAAS,QAAQ,cAAgB;CACrD,MAAM,YAAc,SAAS,SAAS,cAAgB;CAG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G,KAAM,OACb,QAAQ,EAAG;EAEZ,IAAK,EAAG,KAAM,OACb,QAAQ,EAAG;CAEb;CAGA,IACC,SAAS,SACT,SAAS,eACT,SAAS,SACT,SAAS,aAET,OAAO;EAAE,KAAK,UAAU;EAAK;CAAK;CAQnC,IAAI,MAAM;CACV,IAAI,MAAM;CAEV,IAAK,QAAQ,KAAK,SAAS,aAC1B,MAAM,CAAC;MACD,IAAK,QAAQ,KAAK,SAAS,OACjC,MAAM,IAAI;MACJ,IAAK,QAAQ,KAAK,QAAQ,GAEhC,OAAQ,IAAI,QAAQ,SAAU;CAG/B,IAAK,QAAQ,KAAK,SAAS,aAC1B,MAAM,CAAC;MACD,IAAK,QAAQ,KAAK,SAAS,OACjC,MAAM,IAAI;MACJ,IAAK,QAAQ,KAAK,QAAQ,GAChC,OAAQ,IAAI,QAAQ,SAAU;CAM/B,MAAM,MAAM,OAAQ,KAAM,MAAM,OAAQ,KAAM;CAC9C,MAAM,MAAM,OAAQ,KAAM,MAAM,OAAQ,KAAM;CAa9C,OAAO;EACN,KAAK;GAAE,GAPP,UAAU,IAAI,KACZ,cAAc,QAAQ,IAAI,MAAM,cAAc,QAAQ;GAMrC,GAJnB,UAAU,IAAI,KACZ,cAAc,SAAS,IAAI,MAAM,cAAc,SAAS;EAG5B;EAC9B;CACD;AACD"}
|
|
@@ -1,48 +1,37 @@
|
|
|
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/crop-rect.ts
|
|
21
|
-
var crop_rect_exports = {};
|
|
22
|
-
__export(crop_rect_exports, {
|
|
23
|
-
computeInscribedRect: () => computeInscribedRect
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
6
|
+
// packages/media-editor/src/image-editor/core/crop-rect.ts
|
|
7
|
+
/**
|
|
8
|
+
* Largest rect of the given pixel aspect ratio that fits inside the
|
|
9
|
+
* visual bounds, centered in [0,1] × [0,1] normalized space. Returns
|
|
10
|
+
* a full-frame rect (1×1) if `aspectRatio` is unset or non-positive.
|
|
11
|
+
*
|
|
12
|
+
* The returned rect is the same in either freeform or fixed-crop
|
|
13
|
+
* mode — it's the canonical "centered crop for this ratio at this
|
|
14
|
+
* canvas size".
|
|
15
|
+
*
|
|
16
|
+
* @param aspectRatio Desired pixel width/height ratio. `undefined`
|
|
17
|
+
* (or 0/negative) means no lock — returns full frame.
|
|
18
|
+
* @param visualSize Rendered image dimensions in pixels.
|
|
19
|
+
*/
|
|
26
20
|
function computeInscribedRect(aspectRatio, visualSize) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
width: w,
|
|
41
|
-
height: h
|
|
42
|
-
};
|
|
21
|
+
let w = 1;
|
|
22
|
+
let h = 1;
|
|
23
|
+
if (aspectRatio && aspectRatio > 0 && visualSize.width > 0) {
|
|
24
|
+
const normalizedRatio = aspectRatio * visualSize.height / visualSize.width;
|
|
25
|
+
if (normalizedRatio <= 1) w = normalizedRatio;
|
|
26
|
+
else h = 1 / normalizedRatio;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
x: (1 - w) / 2,
|
|
30
|
+
y: (1 - h) / 2,
|
|
31
|
+
width: w,
|
|
32
|
+
height: h
|
|
33
|
+
};
|
|
43
34
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
//# sourceMappingURL=crop-rect.cjs.map
|
|
35
|
+
exports.computeInscribedRect = computeInscribedRect;
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=crop-rect.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/image-editor/core/crop-rect.ts"],
|
|
4
|
-
"sourcesContent": ["import 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] × [0,1] normalized space. Returns\n * a full-frame rect (1×1) if `aspectRatio` is unset or non-positive.\n *\n * The returned rect is the same in either freeform or fixed-crop\n * mode — 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 — 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;AAeO,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
|
-
}
|
|
1
|
+
{"version":3,"file":"crop-rect.cjs","names":[],"sources":["../../../src/image-editor/core/crop-rect.ts"],"sourcesContent":["import 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] × [0,1] normalized space. Returns\n * a full-frame rect (1×1) if `aspectRatio` is unset or non-positive.\n *\n * The returned rect is the same in either freeform or fixed-crop\n * mode — 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 — 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"],"mappings":";;;;;;;;;;;;;;;;;;;AAeA,SAAgB,qBACf,aACA,YACiB;CACjB,IAAI,IAAI;CACR,IAAI,IAAI;CACR,IAAK,eAAe,cAAc,KAAK,WAAW,QAAQ,GAAI;EAM7D,MAAM,kBACH,cAAc,WAAW,SAAW,WAAW;EAClD,IAAK,mBAAmB,GACvB,IAAI;OAEJ,IAAI,IAAI;CAEV;CACA,OAAO;EACN,IAAK,IAAI,KAAM;EACf,IAAK,IAAI,KAAM;EACf,OAAO;EACP,QAAQ;CACT;AACD"}
|
|
@@ -1,151 +1,181 @@
|
|
|
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/export/canvas-renderer.ts
|
|
21
|
-
var canvas_renderer_exports = {};
|
|
22
|
-
__export(canvas_renderer_exports, {
|
|
23
|
-
applyToCanvas: () => applyToCanvas,
|
|
24
|
-
canvasToBlob: () => canvasToBlob,
|
|
25
|
-
canvasToDataURL: () => canvasToDataURL,
|
|
26
|
-
downloadCroppedImage: () => downloadCroppedImage,
|
|
27
|
-
exportCroppedImage: () => exportCroppedImage,
|
|
28
|
-
loadImage: () => loadImage,
|
|
29
|
-
renderToCanvas: () => renderToCanvas
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
30
5
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
6
|
+
let ___camera_ts = require("../camera.cjs");
|
|
7
|
+
// packages/media-editor/src/image-editor/core/export/canvas-renderer.ts
|
|
8
|
+
/** Default export quality for lossy formats (JPEG, WebP). */
|
|
9
|
+
const DEFAULT_QUALITY = .92;
|
|
10
|
+
/**
|
|
11
|
+
* Load an image from a URL with CORS support.
|
|
12
|
+
*
|
|
13
|
+
* @param src - The image URL to load.
|
|
14
|
+
* @return A promise that resolves to the loaded HTMLImageElement.
|
|
15
|
+
*/
|
|
34
16
|
function loadImage(src) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const image = new Image();
|
|
19
|
+
image.addEventListener("load", () => resolve(image));
|
|
20
|
+
image.addEventListener("error", (error) => reject(error));
|
|
21
|
+
image.crossOrigin = "anonymous";
|
|
22
|
+
image.src = src;
|
|
23
|
+
});
|
|
42
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Apply rectangular crop, rotation, and flip transforms to produce a canvas.
|
|
27
|
+
*
|
|
28
|
+
* Uses createExportCamera to compose the full transform matrix, then applies
|
|
29
|
+
* it in a single ctx.setTransform call before drawing the image.
|
|
30
|
+
*
|
|
31
|
+
* @param image - The source image element.
|
|
32
|
+
* @param state - The full cropper state containing crop, rotation, and flip settings.
|
|
33
|
+
* @return A canvas element containing the transformed and cropped image.
|
|
34
|
+
*/
|
|
43
35
|
function renderToCanvas(image, state) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
camera[1],
|
|
67
|
-
camera[2],
|
|
68
|
-
camera[3],
|
|
69
|
-
camera[4],
|
|
70
|
-
camera[5]
|
|
71
|
-
);
|
|
72
|
-
ctx.drawImage(image, 0, 0);
|
|
73
|
-
return canvas;
|
|
36
|
+
const { naturalWidth, naturalHeight } = image;
|
|
37
|
+
const { rotation, cropRect } = state;
|
|
38
|
+
const imageSize = {
|
|
39
|
+
width: naturalWidth,
|
|
40
|
+
height: naturalHeight
|
|
41
|
+
};
|
|
42
|
+
const snapRotation = Math.round(rotation / 90) * 90;
|
|
43
|
+
const rotBBox = (0, ___camera_ts.getRotatedBBox)(naturalWidth, naturalHeight, snapRotation);
|
|
44
|
+
const outW = Math.round(cropRect.width * rotBBox.width);
|
|
45
|
+
const outH = Math.round(cropRect.height * rotBBox.height);
|
|
46
|
+
const canvas = document.createElement("canvas");
|
|
47
|
+
canvas.width = outW;
|
|
48
|
+
canvas.height = outH;
|
|
49
|
+
const ctx = canvas.getContext("2d");
|
|
50
|
+
if (!ctx) throw new Error("Could not obtain a 2D context for the export canvas.");
|
|
51
|
+
const camera = (0, ___camera_ts.createExportCamera)(state, imageSize, {
|
|
52
|
+
width: outW,
|
|
53
|
+
height: outH
|
|
54
|
+
});
|
|
55
|
+
ctx.setTransform(camera[0], camera[1], camera[2], camera[3], camera[4], camera[5]);
|
|
56
|
+
ctx.drawImage(image, 0, 0);
|
|
57
|
+
return canvas;
|
|
74
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Convert a canvas to a Blob with configurable MIME type and quality.
|
|
61
|
+
*
|
|
62
|
+
* @param canvas - The canvas to export.
|
|
63
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
64
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
65
|
+
* @return A promise that resolves to the canvas content as a Blob.
|
|
66
|
+
*/
|
|
75
67
|
function canvasToBlob(canvas, mimeType = "image/png", quality = DEFAULT_QUALITY) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
reject(new Error("Canvas toBlob returned null."));
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
mimeType,
|
|
86
|
-
quality
|
|
87
|
-
);
|
|
88
|
-
});
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
canvas.toBlob((blob) => {
|
|
70
|
+
if (blob) resolve(blob);
|
|
71
|
+
else reject(/* @__PURE__ */ new Error("Canvas toBlob returned null."));
|
|
72
|
+
}, mimeType, quality);
|
|
73
|
+
});
|
|
89
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert a canvas to a data URL string.
|
|
77
|
+
*
|
|
78
|
+
* @param canvas - The canvas to export.
|
|
79
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
80
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
81
|
+
* @return The canvas content as a data URL string.
|
|
82
|
+
*/
|
|
90
83
|
function canvasToDataURL(canvas, mimeType = "image/png", quality = DEFAULT_QUALITY) {
|
|
91
|
-
|
|
84
|
+
return canvas.toDataURL(mimeType, quality);
|
|
92
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Load an image, render with transforms, and export as a Blob.
|
|
88
|
+
*
|
|
89
|
+
* Throws on failure so callers can distinguish error cases:
|
|
90
|
+
* - Image load failures (network errors, 404s) throw the native
|
|
91
|
+
* load error from the Image element.
|
|
92
|
+
* - Cross-origin failures manifest as tainted-canvas errors from
|
|
93
|
+
* `canvas.toBlob()` — the browser rejects reading pixel data
|
|
94
|
+
* from a canvas that drew an image without valid CORS headers.
|
|
95
|
+
* Ensure the source server sets `Access-Control-Allow-Origin`.
|
|
96
|
+
* - Canvas context creation failures throw a descriptive Error.
|
|
97
|
+
*
|
|
98
|
+
* Only works in browser environments (needs DOM / HTMLCanvasElement).
|
|
99
|
+
*
|
|
100
|
+
* @param src - The image URL to load.
|
|
101
|
+
* @param state - The cropper state with all transform settings.
|
|
102
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
103
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
104
|
+
* @return A promise that resolves to the exported Blob.
|
|
105
|
+
* @throws If the image fails to load, canvas creation fails, or
|
|
106
|
+
* the resulting canvas is tainted by CORS restrictions.
|
|
107
|
+
*/
|
|
93
108
|
async function exportCroppedImage(src, state, mimeType = "image/png", quality = DEFAULT_QUALITY) {
|
|
94
|
-
|
|
95
|
-
const canvas = renderToCanvas(image, state);
|
|
96
|
-
return canvasToBlob(canvas, mimeType, quality);
|
|
109
|
+
return canvasToBlob(renderToCanvas(await loadImage(src), state), mimeType, quality);
|
|
97
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Apply the cropper's transform (crop, rotation, flip, zoom) to an existing
|
|
113
|
+
* canvas or image source. This is the bridge for multi-step editing pipelines
|
|
114
|
+
* where an upstream tool (e.g., brightness/color adjustment) has already
|
|
115
|
+
* processed the image and you want to apply the crop on top.
|
|
116
|
+
*
|
|
117
|
+
* Accepts any CanvasImageSource: HTMLImageElement, HTMLCanvasElement,
|
|
118
|
+
* OffscreenCanvas, ImageBitmap, HTMLVideoElement, etc.
|
|
119
|
+
*
|
|
120
|
+
* @param source - The image source to crop/transform.
|
|
121
|
+
* @param sourceSize - The dimensions of the source (natural width/height).
|
|
122
|
+
* @param sourceSize.width - The width of the source in pixels.
|
|
123
|
+
* @param sourceSize.height - The height of the source in pixels.
|
|
124
|
+
* @param state - The cropper state with all transform settings.
|
|
125
|
+
* @param outputSize - Optional output size. Defaults to the crop region's natural pixel size.
|
|
126
|
+
* @param outputSize.width - The width of the output in pixels.
|
|
127
|
+
* @param outputSize.height - The height of the output in pixels.
|
|
128
|
+
* @return A canvas with the transforms applied.
|
|
129
|
+
*/
|
|
98
130
|
function applyToCanvas(source, sourceSize, state, outputSize) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
const camera = (0, import_camera.createExportCamera)(state, sourceSize, {
|
|
117
|
-
width: outW,
|
|
118
|
-
height: outH
|
|
119
|
-
});
|
|
120
|
-
ctx.setTransform(
|
|
121
|
-
camera[0],
|
|
122
|
-
camera[1],
|
|
123
|
-
camera[2],
|
|
124
|
-
camera[3],
|
|
125
|
-
camera[4],
|
|
126
|
-
camera[5]
|
|
127
|
-
);
|
|
128
|
-
ctx.drawImage(source, 0, 0);
|
|
129
|
-
return canvas;
|
|
131
|
+
const snapRotation = Math.round(state.rotation / 90) * 90;
|
|
132
|
+
const rotBBox = (0, ___camera_ts.getRotatedBBox)(sourceSize.width, sourceSize.height, snapRotation);
|
|
133
|
+
const outW = outputSize?.width ?? Math.round(state.cropRect.width * rotBBox.width);
|
|
134
|
+
const outH = outputSize?.height ?? Math.round(state.cropRect.height * rotBBox.height);
|
|
135
|
+
const canvas = document.createElement("canvas");
|
|
136
|
+
canvas.width = outW;
|
|
137
|
+
canvas.height = outH;
|
|
138
|
+
const ctx = canvas.getContext("2d");
|
|
139
|
+
if (!ctx) throw new Error("Could not obtain a 2D context for the export canvas.");
|
|
140
|
+
const camera = (0, ___camera_ts.createExportCamera)(state, sourceSize, {
|
|
141
|
+
width: outW,
|
|
142
|
+
height: outH
|
|
143
|
+
});
|
|
144
|
+
ctx.setTransform(camera[0], camera[1], camera[2], camera[3], camera[4], camera[5]);
|
|
145
|
+
ctx.drawImage(source, 0, 0);
|
|
146
|
+
return canvas;
|
|
130
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Download the cropped image as a file.
|
|
150
|
+
*
|
|
151
|
+
* Loads the source image, applies all transforms, and triggers a
|
|
152
|
+
* browser download via exportCroppedImage() + object URL + anchor click.
|
|
153
|
+
*
|
|
154
|
+
* Throws on export failure (see `exportCroppedImage`).
|
|
155
|
+
*
|
|
156
|
+
* @param src - The image URL to load.
|
|
157
|
+
* @param state - The cropper state with all transform settings.
|
|
158
|
+
* @param filename - The download filename. Defaults to 'cropped-image'.
|
|
159
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
160
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
161
|
+
* @return A promise that resolves when the download is triggered.
|
|
162
|
+
*/
|
|
131
163
|
async function downloadCroppedImage(src, state, filename = "cropped-image", mimeType = "image/png", quality = DEFAULT_QUALITY) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
164
|
+
const blob = await exportCroppedImage(src, state, mimeType, quality);
|
|
165
|
+
const ext = mimeType.split("/")[1] ?? "png";
|
|
166
|
+
const url = URL.createObjectURL(blob);
|
|
167
|
+
const a = document.createElement("a");
|
|
168
|
+
a.href = url;
|
|
169
|
+
a.download = `${filename}.${ext}`;
|
|
170
|
+
a.click();
|
|
171
|
+
URL.revokeObjectURL(url);
|
|
140
172
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
//# sourceMappingURL=canvas-renderer.cjs.map
|
|
173
|
+
exports.applyToCanvas = applyToCanvas;
|
|
174
|
+
exports.canvasToBlob = canvasToBlob;
|
|
175
|
+
exports.canvasToDataURL = canvasToDataURL;
|
|
176
|
+
exports.downloadCroppedImage = downloadCroppedImage;
|
|
177
|
+
exports.exportCroppedImage = exportCroppedImage;
|
|
178
|
+
exports.loadImage = loadImage;
|
|
179
|
+
exports.renderToCanvas = renderToCanvas;
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=canvas-renderer.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/image-editor/core/export/canvas-renderer.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CropperState } from '../types';\nimport { createExportCamera, getRotatedBBox } from '../camera';\n\n/** Default export quality for lossy formats (JPEG, WebP). */\nconst DEFAULT_QUALITY = 0.92;\n\n/**\n * Load an image from a URL with CORS support.\n *\n * @param src - The image URL to load.\n * @return A promise that resolves to the loaded HTMLImageElement.\n */\nexport function loadImage( src: string ): Promise< HTMLImageElement > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tconst image = new Image();\n\t\timage.addEventListener( 'load', () => resolve( image ) );\n\t\timage.addEventListener( 'error', ( error ) => reject( error ) );\n\t\timage.crossOrigin = 'anonymous';\n\t\timage.src = src;\n\t} );\n}\n\n/**\n * Apply rectangular crop, rotation, and flip transforms to produce a canvas.\n *\n * Uses createExportCamera to compose the full transform matrix, then applies\n * it in a single ctx.setTransform call before drawing the image.\n *\n * @param image - The source image element.\n * @param state - The full cropper state containing crop, rotation, and flip settings.\n * @return A canvas element containing the transformed and cropped image.\n */\nexport function renderToCanvas(\n\timage: HTMLImageElement,\n\tstate: CropperState\n): HTMLCanvasElement {\n\tconst { naturalWidth, naturalHeight } = image;\n\tconst { rotation, cropRect } = state;\n\tconst imageSize = { width: naturalWidth, height: naturalHeight };\n\n\t// Output size is the crop region in the snap-rotation bbox — matches\n\t// the preview's reference frame so the exported pixels track exactly\n\t// what the stencil framed, even at fine rotation angles.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst rotBBox = getRotatedBBox( naturalWidth, naturalHeight, snapRotation );\n\tconst outW = Math.round( cropRect.width * rotBBox.width );\n\tconst outH = Math.round( cropRect.height * rotBBox.height );\n\n\tconst canvas = document.createElement( 'canvas' );\n\tcanvas.width = outW;\n\tcanvas.height = outH;\n\tconst ctx = canvas.getContext( '2d' );\n\tif ( ! ctx ) {\n\t\tthrow new Error(\n\t\t\t'Could not obtain a 2D context for the export canvas.'\n\t\t);\n\t}\n\n\tconst camera = createExportCamera( state, imageSize, {\n\t\twidth: outW,\n\t\theight: outH,\n\t} );\n\tctx.setTransform(\n\t\tcamera[ 0 ],\n\t\tcamera[ 1 ],\n\t\tcamera[ 2 ],\n\t\tcamera[ 3 ],\n\t\tcamera[ 4 ],\n\t\tcamera[ 5 ]\n\t);\n\tctx.drawImage( image, 0, 0 );\n\treturn canvas;\n}\n\n/**\n * Convert a canvas to a Blob with configurable MIME type and quality.\n *\n * @param canvas - The canvas to export.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves to the canvas content as a Blob.\n */\nexport function canvasToBlob(\n\tcanvas: HTMLCanvasElement,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< Blob > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tcanvas.toBlob(\n\t\t\t( blob ) => {\n\t\t\t\tif ( blob ) {\n\t\t\t\t\tresolve( blob );\n\t\t\t\t} else {\n\t\t\t\t\treject( new Error( 'Canvas toBlob returned null.' ) );\n\t\t\t\t}\n\t\t\t},\n\t\t\tmimeType,\n\t\t\tquality\n\t\t);\n\t} );\n}\n\n/**\n * Convert a canvas to a data URL string.\n *\n * @param canvas - The canvas to export.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return The canvas content as a data URL string.\n */\nexport function canvasToDataURL(\n\tcanvas: HTMLCanvasElement,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): string {\n\treturn canvas.toDataURL( mimeType, quality );\n}\n\n/**\n * Load an image, render with transforms, and export as a Blob.\n *\n * Throws on failure so callers can distinguish error cases:\n * - Image load failures (network errors, 404s) throw the native\n * load error from the Image element.\n * - Cross-origin failures manifest as tainted-canvas errors from\n * `canvas.toBlob()` — the browser rejects reading pixel data\n * from a canvas that drew an image without valid CORS headers.\n * Ensure the source server sets `Access-Control-Allow-Origin`.\n * - Canvas context creation failures throw a descriptive Error.\n *\n * Only works in browser environments (needs DOM / HTMLCanvasElement).\n *\n * @param src - The image URL to load.\n * @param state - The cropper state with all transform settings.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves to the exported Blob.\n * @throws If the image fails to load, canvas creation fails, or\n * the resulting canvas is tainted by CORS restrictions.\n */\nexport async function exportCroppedImage(\n\tsrc: string,\n\tstate: CropperState,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< Blob > {\n\tconst image = await loadImage( src );\n\tconst canvas = renderToCanvas( image, state );\n\treturn canvasToBlob( canvas, mimeType, quality );\n}\n\n/**\n * Apply the cropper's transform (crop, rotation, flip, zoom) to an existing\n * canvas or image source. This is the bridge for multi-step editing pipelines\n * where an upstream tool (e.g., brightness/color adjustment) has already\n * processed the image and you want to apply the crop on top.\n *\n * Accepts any CanvasImageSource: HTMLImageElement, HTMLCanvasElement,\n * OffscreenCanvas, ImageBitmap, HTMLVideoElement, etc.\n *\n * @param source - The image source to crop/transform.\n * @param sourceSize - The dimensions of the source (natural width/height).\n * @param sourceSize.width - The width of the source in pixels.\n * @param sourceSize.height - The height of the source in pixels.\n * @param state - The cropper state with all transform settings.\n * @param outputSize - Optional output size. Defaults to the crop region's natural pixel size.\n * @param outputSize.width - The width of the output in pixels.\n * @param outputSize.height - The height of the output in pixels.\n * @return A canvas with the transforms applied.\n */\nexport function applyToCanvas(\n\tsource: CanvasImageSource,\n\tsourceSize: { width: number; height: number },\n\tstate: CropperState,\n\toutputSize?: { width: number; height: number }\n): HTMLCanvasElement {\n\t// Use snap-rotation bbox for default sizing so the default output\n\t// matches the preview's reference frame at fine rotation angles\n\t// (see renderToCanvas / createExportCamera).\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst rotBBox = getRotatedBBox(\n\t\tsourceSize.width,\n\t\tsourceSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Default output size: the crop region in natural pixels.\n\tconst outW =\n\t\toutputSize?.width ?? Math.round( state.cropRect.width * rotBBox.width );\n\tconst outH =\n\t\toutputSize?.height ??\n\t\tMath.round( state.cropRect.height * rotBBox.height );\n\n\tconst canvas = document.createElement( 'canvas' );\n\tcanvas.width = outW;\n\tcanvas.height = outH;\n\tconst ctx = canvas.getContext( '2d' );\n\tif ( ! ctx ) {\n\t\tthrow new Error(\n\t\t\t'Could not obtain a 2D context for the export canvas.'\n\t\t);\n\t}\n\n\tconst camera = createExportCamera( state, sourceSize, {\n\t\twidth: outW,\n\t\theight: outH,\n\t} );\n\tctx.setTransform(\n\t\tcamera[ 0 ],\n\t\tcamera[ 1 ],\n\t\tcamera[ 2 ],\n\t\tcamera[ 3 ],\n\t\tcamera[ 4 ],\n\t\tcamera[ 5 ]\n\t);\n\tctx.drawImage( source, 0, 0 );\n\treturn canvas;\n}\n\n/**\n * Download the cropped image as a file.\n *\n * Loads the source image, applies all transforms, and triggers a\n * browser download via exportCroppedImage() + object URL + anchor click.\n *\n * Throws on export failure (see `exportCroppedImage`).\n *\n * @param src - The image URL to load.\n * @param state - The cropper state with all transform settings.\n * @param filename - The download filename. Defaults to 'cropped-image'.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves when the download is triggered.\n */\nexport async function downloadCroppedImage(\n\tsrc: string,\n\tstate: CropperState,\n\tfilename: string = 'cropped-image',\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< void > {\n\tconst blob = await exportCroppedImage( src, state, mimeType, quality );\n\tconst ext = mimeType.split( '/' )[ 1 ] ?? 'png';\n\tconst url = URL.createObjectURL( blob );\n\tconst a = document.createElement( 'a' );\n\ta.href = url;\n\ta.download = `${ filename }.${ ext }`;\n\ta.click();\n\tURL.revokeObjectURL( url );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAmD;AAGnD,IAAM,kBAAkB;AAQjB,SAAS,UAAW,KAA2C;AACrE,SAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAC1C,UAAM,QAAQ,IAAI,MAAM;AACxB,UAAM,iBAAkB,QAAQ,MAAM,QAAS,KAAM,CAAE;AACvD,UAAM,iBAAkB,SAAS,CAAE,UAAW,OAAQ,KAAM,CAAE;AAC9D,UAAM,cAAc;AACpB,UAAM,MAAM;AAAA,EACb,CAAE;AACH;AAYO,SAAS,eACf,OACA,OACoB;AACpB,QAAM,EAAE,cAAc,cAAc,IAAI;AACxC,QAAM,EAAE,UAAU,SAAS,IAAI;AAC/B,QAAM,YAAY,EAAE,OAAO,cAAc,QAAQ,cAAc;AAK/D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7
|
-
}
|
|
1
|
+
{"version":3,"file":"canvas-renderer.cjs","names":["getRotatedBBox","createExportCamera"],"sources":["../../../../src/image-editor/core/export/canvas-renderer.ts"],"sourcesContent":["import type { CropperState } from '../types';\nimport { createExportCamera, getRotatedBBox } from '../camera';\n\n/** Default export quality for lossy formats (JPEG, WebP). */\nconst DEFAULT_QUALITY = 0.92;\n\n/**\n * Load an image from a URL with CORS support.\n *\n * @param src - The image URL to load.\n * @return A promise that resolves to the loaded HTMLImageElement.\n */\nexport function loadImage( src: string ): Promise< HTMLImageElement > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tconst image = new Image();\n\t\timage.addEventListener( 'load', () => resolve( image ) );\n\t\timage.addEventListener( 'error', ( error ) => reject( error ) );\n\t\timage.crossOrigin = 'anonymous';\n\t\timage.src = src;\n\t} );\n}\n\n/**\n * Apply rectangular crop, rotation, and flip transforms to produce a canvas.\n *\n * Uses createExportCamera to compose the full transform matrix, then applies\n * it in a single ctx.setTransform call before drawing the image.\n *\n * @param image - The source image element.\n * @param state - The full cropper state containing crop, rotation, and flip settings.\n * @return A canvas element containing the transformed and cropped image.\n */\nexport function renderToCanvas(\n\timage: HTMLImageElement,\n\tstate: CropperState\n): HTMLCanvasElement {\n\tconst { naturalWidth, naturalHeight } = image;\n\tconst { rotation, cropRect } = state;\n\tconst imageSize = { width: naturalWidth, height: naturalHeight };\n\n\t// Output size is the crop region in the snap-rotation bbox — matches\n\t// the preview's reference frame so the exported pixels track exactly\n\t// what the stencil framed, even at fine rotation angles.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst rotBBox = getRotatedBBox( naturalWidth, naturalHeight, snapRotation );\n\tconst outW = Math.round( cropRect.width * rotBBox.width );\n\tconst outH = Math.round( cropRect.height * rotBBox.height );\n\n\tconst canvas = document.createElement( 'canvas' );\n\tcanvas.width = outW;\n\tcanvas.height = outH;\n\tconst ctx = canvas.getContext( '2d' );\n\tif ( ! ctx ) {\n\t\tthrow new Error(\n\t\t\t'Could not obtain a 2D context for the export canvas.'\n\t\t);\n\t}\n\n\tconst camera = createExportCamera( state, imageSize, {\n\t\twidth: outW,\n\t\theight: outH,\n\t} );\n\tctx.setTransform(\n\t\tcamera[ 0 ],\n\t\tcamera[ 1 ],\n\t\tcamera[ 2 ],\n\t\tcamera[ 3 ],\n\t\tcamera[ 4 ],\n\t\tcamera[ 5 ]\n\t);\n\tctx.drawImage( image, 0, 0 );\n\treturn canvas;\n}\n\n/**\n * Convert a canvas to a Blob with configurable MIME type and quality.\n *\n * @param canvas - The canvas to export.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves to the canvas content as a Blob.\n */\nexport function canvasToBlob(\n\tcanvas: HTMLCanvasElement,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< Blob > {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tcanvas.toBlob(\n\t\t\t( blob ) => {\n\t\t\t\tif ( blob ) {\n\t\t\t\t\tresolve( blob );\n\t\t\t\t} else {\n\t\t\t\t\treject( new Error( 'Canvas toBlob returned null.' ) );\n\t\t\t\t}\n\t\t\t},\n\t\t\tmimeType,\n\t\t\tquality\n\t\t);\n\t} );\n}\n\n/**\n * Convert a canvas to a data URL string.\n *\n * @param canvas - The canvas to export.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return The canvas content as a data URL string.\n */\nexport function canvasToDataURL(\n\tcanvas: HTMLCanvasElement,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): string {\n\treturn canvas.toDataURL( mimeType, quality );\n}\n\n/**\n * Load an image, render with transforms, and export as a Blob.\n *\n * Throws on failure so callers can distinguish error cases:\n * - Image load failures (network errors, 404s) throw the native\n * load error from the Image element.\n * - Cross-origin failures manifest as tainted-canvas errors from\n * `canvas.toBlob()` — the browser rejects reading pixel data\n * from a canvas that drew an image without valid CORS headers.\n * Ensure the source server sets `Access-Control-Allow-Origin`.\n * - Canvas context creation failures throw a descriptive Error.\n *\n * Only works in browser environments (needs DOM / HTMLCanvasElement).\n *\n * @param src - The image URL to load.\n * @param state - The cropper state with all transform settings.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves to the exported Blob.\n * @throws If the image fails to load, canvas creation fails, or\n * the resulting canvas is tainted by CORS restrictions.\n */\nexport async function exportCroppedImage(\n\tsrc: string,\n\tstate: CropperState,\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< Blob > {\n\tconst image = await loadImage( src );\n\tconst canvas = renderToCanvas( image, state );\n\treturn canvasToBlob( canvas, mimeType, quality );\n}\n\n/**\n * Apply the cropper's transform (crop, rotation, flip, zoom) to an existing\n * canvas or image source. This is the bridge for multi-step editing pipelines\n * where an upstream tool (e.g., brightness/color adjustment) has already\n * processed the image and you want to apply the crop on top.\n *\n * Accepts any CanvasImageSource: HTMLImageElement, HTMLCanvasElement,\n * OffscreenCanvas, ImageBitmap, HTMLVideoElement, etc.\n *\n * @param source - The image source to crop/transform.\n * @param sourceSize - The dimensions of the source (natural width/height).\n * @param sourceSize.width - The width of the source in pixels.\n * @param sourceSize.height - The height of the source in pixels.\n * @param state - The cropper state with all transform settings.\n * @param outputSize - Optional output size. Defaults to the crop region's natural pixel size.\n * @param outputSize.width - The width of the output in pixels.\n * @param outputSize.height - The height of the output in pixels.\n * @return A canvas with the transforms applied.\n */\nexport function applyToCanvas(\n\tsource: CanvasImageSource,\n\tsourceSize: { width: number; height: number },\n\tstate: CropperState,\n\toutputSize?: { width: number; height: number }\n): HTMLCanvasElement {\n\t// Use snap-rotation bbox for default sizing so the default output\n\t// matches the preview's reference frame at fine rotation angles\n\t// (see renderToCanvas / createExportCamera).\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst rotBBox = getRotatedBBox(\n\t\tsourceSize.width,\n\t\tsourceSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Default output size: the crop region in natural pixels.\n\tconst outW =\n\t\toutputSize?.width ?? Math.round( state.cropRect.width * rotBBox.width );\n\tconst outH =\n\t\toutputSize?.height ??\n\t\tMath.round( state.cropRect.height * rotBBox.height );\n\n\tconst canvas = document.createElement( 'canvas' );\n\tcanvas.width = outW;\n\tcanvas.height = outH;\n\tconst ctx = canvas.getContext( '2d' );\n\tif ( ! ctx ) {\n\t\tthrow new Error(\n\t\t\t'Could not obtain a 2D context for the export canvas.'\n\t\t);\n\t}\n\n\tconst camera = createExportCamera( state, sourceSize, {\n\t\twidth: outW,\n\t\theight: outH,\n\t} );\n\tctx.setTransform(\n\t\tcamera[ 0 ],\n\t\tcamera[ 1 ],\n\t\tcamera[ 2 ],\n\t\tcamera[ 3 ],\n\t\tcamera[ 4 ],\n\t\tcamera[ 5 ]\n\t);\n\tctx.drawImage( source, 0, 0 );\n\treturn canvas;\n}\n\n/**\n * Download the cropped image as a file.\n *\n * Loads the source image, applies all transforms, and triggers a\n * browser download via exportCroppedImage() + object URL + anchor click.\n *\n * Throws on export failure (see `exportCroppedImage`).\n *\n * @param src - The image URL to load.\n * @param state - The cropper state with all transform settings.\n * @param filename - The download filename. Defaults to 'cropped-image'.\n * @param mimeType - The output MIME type. Defaults to 'image/png'.\n * @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.\n * @return A promise that resolves when the download is triggered.\n */\nexport async function downloadCroppedImage(\n\tsrc: string,\n\tstate: CropperState,\n\tfilename: string = 'cropped-image',\n\tmimeType: string = 'image/png',\n\tquality: number = DEFAULT_QUALITY\n): Promise< void > {\n\tconst blob = await exportCroppedImage( src, state, mimeType, quality );\n\tconst ext = mimeType.split( '/' )[ 1 ] ?? 'png';\n\tconst url = URL.createObjectURL( blob );\n\tconst a = document.createElement( 'a' );\n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