@wordpress/media-editor 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +2 -1
- package/build/components/media-editor/index.cjs +533 -695
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -58
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -68
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -153
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -54
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +77 -78
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -720
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +136 -89
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -281
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -682
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -33
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +97 -95
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -122
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -28
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +69 -54
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -89
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -696
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -75
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -273
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +6 -1
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +7 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +7 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +5 -2
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +2 -2
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -1
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +36 -6
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +16 -5
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +35 -24
- package/src/components/media-editor/index.tsx +226 -183
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -4
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +18 -28
- package/src/components/media-editor-crop-panel/index.tsx +17 -9
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-image-controls/style.scss +1 -1
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/index.tsx +8 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-editor-provider/index.tsx +8 -1
- package/src/components/media-form/index.tsx +48 -42
- package/src/components/media-preview/index.tsx +68 -25
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +5 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +20 -42
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +26 -13
- package/src/state/index.ts +3 -0
- package/src/state/types.ts +39 -11
- package/src/state/use-media-editor-state.ts +53 -16
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/global.d.ts +0 -5
- package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
- package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
- package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
- package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
- package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
- package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
- package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
- package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
- package/src/image-editor/core/math/test/sanitize.ts +0 -242
- package/src/image-editor/core/test/camera.ts +0 -1218
- package/src/image-editor/core/test/interaction-controller.ts +0 -1299
- package/src/image-editor/core/test/preview-export-parity.ts +0 -249
- package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
- package/src/image-editor/core/test/state.ts +0 -876
- package/src/image-editor/core/test/stencil-math.ts +0 -665
- package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
- package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
- package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
- package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
- package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
- package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
- package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
- package/src/image-editor/stories/style.module.css +0 -65
- package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
- package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
- package/src/store/test/reducer.ts +0 -64
- package/tsconfig.build.json +0 -26
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -37
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
// packages/media-editor/src/image-editor/core/crop-rect.ts
|
|
2
|
+
/**
|
|
3
|
+
* Largest rect of the given pixel aspect ratio that fits inside the
|
|
4
|
+
* visual bounds, centered in [0,1] × [0,1] normalized space. Returns
|
|
5
|
+
* a full-frame rect (1×1) if `aspectRatio` is unset or non-positive.
|
|
6
|
+
*
|
|
7
|
+
* The returned rect is the same in either freeform or fixed-crop
|
|
8
|
+
* mode — it's the canonical "centered crop for this ratio at this
|
|
9
|
+
* canvas size".
|
|
10
|
+
*
|
|
11
|
+
* @param aspectRatio Desired pixel width/height ratio. `undefined`
|
|
12
|
+
* (or 0/negative) means no lock — returns full frame.
|
|
13
|
+
* @param visualSize Rendered image dimensions in pixels.
|
|
14
|
+
*/
|
|
2
15
|
function computeInscribedRect(aspectRatio, visualSize) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
width: w,
|
|
17
|
-
height: h
|
|
18
|
-
};
|
|
16
|
+
let w = 1;
|
|
17
|
+
let h = 1;
|
|
18
|
+
if (aspectRatio && aspectRatio > 0 && visualSize.width > 0) {
|
|
19
|
+
const normalizedRatio = aspectRatio * visualSize.height / visualSize.width;
|
|
20
|
+
if (normalizedRatio <= 1) w = normalizedRatio;
|
|
21
|
+
else h = 1 / normalizedRatio;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
x: (1 - w) / 2,
|
|
25
|
+
y: (1 - h) / 2,
|
|
26
|
+
width: w,
|
|
27
|
+
height: h
|
|
28
|
+
};
|
|
19
29
|
}
|
|
20
|
-
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=crop-rect.mjs.map
|
|
30
|
+
export { computeInscribedRect };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=crop-rect.mjs.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": ";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.mjs","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,120 +1,170 @@
|
|
|
1
|
-
// packages/media-editor/src/image-editor/core/export/canvas-renderer.ts
|
|
2
1
|
import { createExportCamera, getRotatedBBox } from "../camera.mjs";
|
|
3
|
-
|
|
2
|
+
// packages/media-editor/src/image-editor/core/export/canvas-renderer.ts
|
|
3
|
+
/** Default export quality for lossy formats (JPEG, WebP). */
|
|
4
|
+
const DEFAULT_QUALITY = .92;
|
|
5
|
+
/**
|
|
6
|
+
* Load an image from a URL with CORS support.
|
|
7
|
+
*
|
|
8
|
+
* @param src - The image URL to load.
|
|
9
|
+
* @return A promise that resolves to the loaded HTMLImageElement.
|
|
10
|
+
*/
|
|
4
11
|
function loadImage(src) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const image = new Image();
|
|
14
|
+
image.addEventListener("load", () => resolve(image));
|
|
15
|
+
image.addEventListener("error", (error) => reject(error));
|
|
16
|
+
image.crossOrigin = "anonymous";
|
|
17
|
+
image.src = src;
|
|
18
|
+
});
|
|
12
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Apply rectangular crop, rotation, and flip transforms to produce a canvas.
|
|
22
|
+
*
|
|
23
|
+
* Uses createExportCamera to compose the full transform matrix, then applies
|
|
24
|
+
* it in a single ctx.setTransform call before drawing the image.
|
|
25
|
+
*
|
|
26
|
+
* @param image - The source image element.
|
|
27
|
+
* @param state - The full cropper state containing crop, rotation, and flip settings.
|
|
28
|
+
* @return A canvas element containing the transformed and cropped image.
|
|
29
|
+
*/
|
|
13
30
|
function renderToCanvas(image, state) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
camera[1],
|
|
37
|
-
camera[2],
|
|
38
|
-
camera[3],
|
|
39
|
-
camera[4],
|
|
40
|
-
camera[5]
|
|
41
|
-
);
|
|
42
|
-
ctx.drawImage(image, 0, 0);
|
|
43
|
-
return canvas;
|
|
31
|
+
const { naturalWidth, naturalHeight } = image;
|
|
32
|
+
const { rotation, cropRect } = state;
|
|
33
|
+
const imageSize = {
|
|
34
|
+
width: naturalWidth,
|
|
35
|
+
height: naturalHeight
|
|
36
|
+
};
|
|
37
|
+
const snapRotation = Math.round(rotation / 90) * 90;
|
|
38
|
+
const rotBBox = getRotatedBBox(naturalWidth, naturalHeight, snapRotation);
|
|
39
|
+
const outW = Math.round(cropRect.width * rotBBox.width);
|
|
40
|
+
const outH = Math.round(cropRect.height * rotBBox.height);
|
|
41
|
+
const canvas = document.createElement("canvas");
|
|
42
|
+
canvas.width = outW;
|
|
43
|
+
canvas.height = outH;
|
|
44
|
+
const ctx = canvas.getContext("2d");
|
|
45
|
+
if (!ctx) throw new Error("Could not obtain a 2D context for the export canvas.");
|
|
46
|
+
const camera = createExportCamera(state, imageSize, {
|
|
47
|
+
width: outW,
|
|
48
|
+
height: outH
|
|
49
|
+
});
|
|
50
|
+
ctx.setTransform(camera[0], camera[1], camera[2], camera[3], camera[4], camera[5]);
|
|
51
|
+
ctx.drawImage(image, 0, 0);
|
|
52
|
+
return canvas;
|
|
44
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Convert a canvas to a Blob with configurable MIME type and quality.
|
|
56
|
+
*
|
|
57
|
+
* @param canvas - The canvas to export.
|
|
58
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
59
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
60
|
+
* @return A promise that resolves to the canvas content as a Blob.
|
|
61
|
+
*/
|
|
45
62
|
function canvasToBlob(canvas, mimeType = "image/png", quality = DEFAULT_QUALITY) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
reject(new Error("Canvas toBlob returned null."));
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
mimeType,
|
|
56
|
-
quality
|
|
57
|
-
);
|
|
58
|
-
});
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
canvas.toBlob((blob) => {
|
|
65
|
+
if (blob) resolve(blob);
|
|
66
|
+
else reject(/* @__PURE__ */ new Error("Canvas toBlob returned null."));
|
|
67
|
+
}, mimeType, quality);
|
|
68
|
+
});
|
|
59
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Convert a canvas to a data URL string.
|
|
72
|
+
*
|
|
73
|
+
* @param canvas - The canvas to export.
|
|
74
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
75
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
76
|
+
* @return The canvas content as a data URL string.
|
|
77
|
+
*/
|
|
60
78
|
function canvasToDataURL(canvas, mimeType = "image/png", quality = DEFAULT_QUALITY) {
|
|
61
|
-
|
|
79
|
+
return canvas.toDataURL(mimeType, quality);
|
|
62
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Load an image, render with transforms, and export as a Blob.
|
|
83
|
+
*
|
|
84
|
+
* Throws on failure so callers can distinguish error cases:
|
|
85
|
+
* - Image load failures (network errors, 404s) throw the native
|
|
86
|
+
* load error from the Image element.
|
|
87
|
+
* - Cross-origin failures manifest as tainted-canvas errors from
|
|
88
|
+
* `canvas.toBlob()` — the browser rejects reading pixel data
|
|
89
|
+
* from a canvas that drew an image without valid CORS headers.
|
|
90
|
+
* Ensure the source server sets `Access-Control-Allow-Origin`.
|
|
91
|
+
* - Canvas context creation failures throw a descriptive Error.
|
|
92
|
+
*
|
|
93
|
+
* Only works in browser environments (needs DOM / HTMLCanvasElement).
|
|
94
|
+
*
|
|
95
|
+
* @param src - The image URL to load.
|
|
96
|
+
* @param state - The cropper state with all transform settings.
|
|
97
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
98
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
99
|
+
* @return A promise that resolves to the exported Blob.
|
|
100
|
+
* @throws If the image fails to load, canvas creation fails, or
|
|
101
|
+
* the resulting canvas is tainted by CORS restrictions.
|
|
102
|
+
*/
|
|
63
103
|
async function exportCroppedImage(src, state, mimeType = "image/png", quality = DEFAULT_QUALITY) {
|
|
64
|
-
|
|
65
|
-
const canvas = renderToCanvas(image, state);
|
|
66
|
-
return canvasToBlob(canvas, mimeType, quality);
|
|
104
|
+
return canvasToBlob(renderToCanvas(await loadImage(src), state), mimeType, quality);
|
|
67
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Apply the cropper's transform (crop, rotation, flip, zoom) to an existing
|
|
108
|
+
* canvas or image source. This is the bridge for multi-step editing pipelines
|
|
109
|
+
* where an upstream tool (e.g., brightness/color adjustment) has already
|
|
110
|
+
* processed the image and you want to apply the crop on top.
|
|
111
|
+
*
|
|
112
|
+
* Accepts any CanvasImageSource: HTMLImageElement, HTMLCanvasElement,
|
|
113
|
+
* OffscreenCanvas, ImageBitmap, HTMLVideoElement, etc.
|
|
114
|
+
*
|
|
115
|
+
* @param source - The image source to crop/transform.
|
|
116
|
+
* @param sourceSize - The dimensions of the source (natural width/height).
|
|
117
|
+
* @param sourceSize.width - The width of the source in pixels.
|
|
118
|
+
* @param sourceSize.height - The height of the source in pixels.
|
|
119
|
+
* @param state - The cropper state with all transform settings.
|
|
120
|
+
* @param outputSize - Optional output size. Defaults to the crop region's natural pixel size.
|
|
121
|
+
* @param outputSize.width - The width of the output in pixels.
|
|
122
|
+
* @param outputSize.height - The height of the output in pixels.
|
|
123
|
+
* @return A canvas with the transforms applied.
|
|
124
|
+
*/
|
|
68
125
|
function applyToCanvas(source, sourceSize, state, outputSize) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
const camera = createExportCamera(state, sourceSize, {
|
|
87
|
-
width: outW,
|
|
88
|
-
height: outH
|
|
89
|
-
});
|
|
90
|
-
ctx.setTransform(
|
|
91
|
-
camera[0],
|
|
92
|
-
camera[1],
|
|
93
|
-
camera[2],
|
|
94
|
-
camera[3],
|
|
95
|
-
camera[4],
|
|
96
|
-
camera[5]
|
|
97
|
-
);
|
|
98
|
-
ctx.drawImage(source, 0, 0);
|
|
99
|
-
return canvas;
|
|
126
|
+
const snapRotation = Math.round(state.rotation / 90) * 90;
|
|
127
|
+
const rotBBox = getRotatedBBox(sourceSize.width, sourceSize.height, snapRotation);
|
|
128
|
+
const outW = outputSize?.width ?? Math.round(state.cropRect.width * rotBBox.width);
|
|
129
|
+
const outH = outputSize?.height ?? Math.round(state.cropRect.height * rotBBox.height);
|
|
130
|
+
const canvas = document.createElement("canvas");
|
|
131
|
+
canvas.width = outW;
|
|
132
|
+
canvas.height = outH;
|
|
133
|
+
const ctx = canvas.getContext("2d");
|
|
134
|
+
if (!ctx) throw new Error("Could not obtain a 2D context for the export canvas.");
|
|
135
|
+
const camera = createExportCamera(state, sourceSize, {
|
|
136
|
+
width: outW,
|
|
137
|
+
height: outH
|
|
138
|
+
});
|
|
139
|
+
ctx.setTransform(camera[0], camera[1], camera[2], camera[3], camera[4], camera[5]);
|
|
140
|
+
ctx.drawImage(source, 0, 0);
|
|
141
|
+
return canvas;
|
|
100
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Download the cropped image as a file.
|
|
145
|
+
*
|
|
146
|
+
* Loads the source image, applies all transforms, and triggers a
|
|
147
|
+
* browser download via exportCroppedImage() + object URL + anchor click.
|
|
148
|
+
*
|
|
149
|
+
* Throws on export failure (see `exportCroppedImage`).
|
|
150
|
+
*
|
|
151
|
+
* @param src - The image URL to load.
|
|
152
|
+
* @param state - The cropper state with all transform settings.
|
|
153
|
+
* @param filename - The download filename. Defaults to 'cropped-image'.
|
|
154
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
155
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
156
|
+
* @return A promise that resolves when the download is triggered.
|
|
157
|
+
*/
|
|
101
158
|
async function downloadCroppedImage(src, state, filename = "cropped-image", mimeType = "image/png", quality = DEFAULT_QUALITY) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
159
|
+
const blob = await exportCroppedImage(src, state, mimeType, quality);
|
|
160
|
+
const ext = mimeType.split("/")[1] ?? "png";
|
|
161
|
+
const url = URL.createObjectURL(blob);
|
|
162
|
+
const a = document.createElement("a");
|
|
163
|
+
a.href = url;
|
|
164
|
+
a.download = `${filename}.${ext}`;
|
|
165
|
+
a.click();
|
|
166
|
+
URL.revokeObjectURL(url);
|
|
110
167
|
}
|
|
111
|
-
export {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
canvasToDataURL,
|
|
115
|
-
downloadCroppedImage,
|
|
116
|
-
exportCroppedImage,
|
|
117
|
-
loadImage,
|
|
118
|
-
renderToCanvas
|
|
119
|
-
};
|
|
120
|
-
//# sourceMappingURL=canvas-renderer.mjs.map
|
|
168
|
+
export { applyToCanvas, canvasToBlob, canvasToDataURL, downloadCroppedImage, exportCroppedImage, loadImage, renderToCanvas };
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=canvas-renderer.mjs.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": "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",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"canvas-renderer.mjs","names":[],"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\ta.href = url;\n\ta.download = `${ filename }.${ ext }`;\n\ta.click();\n\tURL.revokeObjectURL( url );\n}\n"],"mappings":"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"}
|
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_STATE,
|
|
4
|
-
DEFAULT_ASPECT_RATIOS,
|
|
5
|
-
ORIGINAL_ASPECT_RATIO
|
|
6
|
-
} from "./constants.mjs";
|
|
7
|
-
import {
|
|
8
|
-
cropperReducer,
|
|
9
|
-
enforceContainment,
|
|
10
|
-
areCropperStatesEqual,
|
|
11
|
-
isStateDirty
|
|
12
|
-
} from "./state.mjs";
|
|
1
|
+
import { DEFAULT_STATE, ORIGINAL_ASPECT_RATIO } from "./constants.mjs";
|
|
2
|
+
import { areCropperStatesEqual, cropperReducer, enforceContainment, isStateDirty } from "./state.mjs";
|
|
13
3
|
import { getSourceRegion, getSourceRegionPercent } from "./source-region.mjs";
|
|
14
4
|
import { computeInscribedRect } from "./crop-rect.mjs";
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from "./transforms/pipeline.mjs";
|
|
19
|
-
import { exportCroppedImage, applyToCanvas } from "./export/canvas-renderer.mjs";
|
|
20
|
-
export {
|
|
21
|
-
DEFAULT_ASPECT_RATIOS,
|
|
22
|
-
DEFAULT_STATE,
|
|
23
|
-
ORIGINAL_ASPECT_RATIO,
|
|
24
|
-
applyOperationToState,
|
|
25
|
-
applyToCanvas,
|
|
26
|
-
areCropperStatesEqual,
|
|
27
|
-
computeInscribedRect,
|
|
28
|
-
cropperReducer,
|
|
29
|
-
enforceContainment,
|
|
30
|
-
exportCroppedImage,
|
|
31
|
-
getSourceRegion,
|
|
32
|
-
getSourceRegionPercent,
|
|
33
|
-
isStateDirty,
|
|
34
|
-
stateFromPipeline
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=index.mjs.map
|
|
5
|
+
import { applyOperationToState, stateFromPipeline } from "./transforms/pipeline.mjs";
|
|
6
|
+
import { applyToCanvas, exportCroppedImage } from "./export/canvas-renderer.mjs";
|
|
7
|
+
export { DEFAULT_STATE, ORIGINAL_ASPECT_RATIO, applyOperationToState, applyToCanvas, areCropperStatesEqual, computeInscribedRect, cropperReducer, enforceContainment, exportCroppedImage, getSourceRegion, getSourceRegionPercent, isStateDirty, stateFromPipeline };
|