@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,27 +1,38 @@
|
|
|
1
|
-
// packages/media-editor/src/image-editor/core/transform-style.ts
|
|
2
1
|
import { degreesToRadians } from "./math/rotation.mjs";
|
|
3
2
|
import { isValidSize, sanitizeCropperState } from "./math/sanitize.mjs";
|
|
4
|
-
|
|
3
|
+
// packages/media-editor/src/image-editor/core/transform-style.ts
|
|
4
|
+
/** Identity CSS transform — applied when inputs aren't safe to compose. */
|
|
5
|
+
const IDENTITY_MATRIX_STYLE = "matrix(1, 0, 0, 1, 0, 0)";
|
|
6
|
+
/**
|
|
7
|
+
* Computes a CSS matrix() transform string from the cropper state.
|
|
8
|
+
*
|
|
9
|
+
* The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)
|
|
10
|
+
* expressed as a 2D CSS matrix(a, b, c, d, tx, ty).
|
|
11
|
+
*
|
|
12
|
+
* Flip is composed outside rotation so it is viewport-relative — horizontal
|
|
13
|
+
* flip mirrors across the viewport's vertical axis regardless of rotation.
|
|
14
|
+
* Must match the matrix order in `createCamera` / `getImageCropBounds`.
|
|
15
|
+
*
|
|
16
|
+
* This is a pure function with no framework dependencies. The React hook
|
|
17
|
+
* `useTransformStyle` wraps this in `useMemo` for memoization.
|
|
18
|
+
*
|
|
19
|
+
* @param state The current cropper state.
|
|
20
|
+
* @param imageSize The rendered image dimensions in pixels.
|
|
21
|
+
* @return A CSS transform string.
|
|
22
|
+
*/
|
|
5
23
|
function computeTransformStyle(state, imageSize) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const z = safeState.zoom;
|
|
18
|
-
const a = sx * cos * z;
|
|
19
|
-
const b = sy * sin * z;
|
|
20
|
-
const c = -sx * sin * z;
|
|
21
|
-
const d = sy * cos * z;
|
|
22
|
-
return `matrix(${a}, ${b}, ${c}, ${d}, ${translateX}, ${translateY})`;
|
|
24
|
+
if (!isValidSize(imageSize)) return IDENTITY_MATRIX_STYLE;
|
|
25
|
+
const safeState = sanitizeCropperState(state);
|
|
26
|
+
const translateX = safeState.pan.x * imageSize.width;
|
|
27
|
+
const translateY = safeState.pan.y * imageSize.height;
|
|
28
|
+
const rad = degreesToRadians(safeState.rotation);
|
|
29
|
+
const cos = Math.cos(rad);
|
|
30
|
+
const sin = Math.sin(rad);
|
|
31
|
+
const sx = safeState.flip.horizontal ? -1 : 1;
|
|
32
|
+
const sy = safeState.flip.vertical ? -1 : 1;
|
|
33
|
+
const z = safeState.zoom;
|
|
34
|
+
return `matrix(${sx * cos * z}, ${sy * sin * z}, ${-sx * sin * z}, ${sy * cos * z}, ${translateX}, ${translateY})`;
|
|
23
35
|
}
|
|
24
|
-
export {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=transform-style.mjs.map
|
|
36
|
+
export { computeTransformStyle };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=transform-style.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/image-editor/core/transform-style.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CropperState, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { isValidSize, sanitizeCropperState } from './math/sanitize';\n\n/** Identity CSS transform — applied when inputs aren't safe to compose. */\nconst IDENTITY_MATRIX_STYLE = 'matrix(1, 0, 0, 1, 0, 0)';\n\n/**\n * Computes a CSS matrix() transform string from the cropper state.\n *\n * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)\n * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).\n *\n * Flip is composed outside rotation so it is viewport-relative — horizontal\n * flip mirrors across the viewport's vertical axis regardless of rotation.\n * Must match the matrix order in `createCamera` / `getImageCropBounds`.\n *\n * This is a pure function with no framework dependencies. The React hook\n * `useTransformStyle` wraps this in `useMemo` for memoization.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function computeTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\t// Match the identity short-circuit used by `createCamera` and\n\t// `getSourceRegion` so the preview path stays consistent with the math\n\t// path when `imageSize` itself is hostile (state sanitization below\n\t// only guards the state fields, not these size arguments).\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn IDENTITY_MATRIX_STYLE;\n\t}\n\t// Sanitize so hostile state can't produce `matrix(NaN, NaN, ...)` here\n\t// while the parallel `createCamera` path returns a finite matrix. Both\n\t// paths must agree under defense-in-depth conditions.\n\tconst safeState = sanitizeCropperState( state );\n\tconst translateX = safeState.pan.x * imageSize.width;\n\tconst translateY = safeState.pan.y * imageSize.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\n\t// Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)\n\tconst a = sx * cos * z;\n\tconst b = sy * sin * z;\n\tconst c = -sx * sin * z;\n\tconst d = sy * cos * z;\n\n\treturn `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;\n}\n"],
|
|
5
|
-
"mappings": ";AACA,SAAS,wBAAwB;AACjC,SAAS,aAAa,4BAA4B;AAGlD,IAAM,wBAAwB;AAmBvB,SAAS,sBACf,OACA,WACS;AAKT,MAAK,CAAE,YAAa,SAAU,GAAI;AACjC,WAAO;AAAA,EACR;AAIA,QAAM,YAAY,qBAAsB,KAAM;AAC9C,QAAM,aAAa,UAAU,IAAI,IAAI,UAAU;AAC/C,QAAM,aAAa,UAAU,IAAI,IAAI,UAAU;AAC/C,QAAM,MAAM,iBAAkB,UAAU,QAAS;AACjD,QAAM,MAAM,KAAK,IAAK,GAAI;AAC1B,QAAM,MAAM,KAAK,IAAK,GAAI;AAC1B,QAAM,KAAK,UAAU,KAAK,aAAa,KAAK;AAC5C,QAAM,KAAK,UAAU,KAAK,WAAW,KAAK;AAC1C,QAAM,IAAI,UAAU;AAGpB,QAAM,IAAI,KAAK,MAAM;AACrB,QAAM,IAAI,KAAK,MAAM;AACrB,QAAM,IAAI,CAAC,KAAK,MAAM;AACtB,QAAM,IAAI,KAAK,MAAM;AAErB,SAAO,UAAW,CAAE,KAAM,CAAE,KAAM,CAAE,KAAM,CAAE,KAAM,UAAW,KAAM,UAAW;AAC/E;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"transform-style.mjs","names":[],"sources":["../../../src/image-editor/core/transform-style.ts"],"sourcesContent":["import type { CropperState, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { isValidSize, sanitizeCropperState } from './math/sanitize';\n\n/** Identity CSS transform — applied when inputs aren't safe to compose. */\nconst IDENTITY_MATRIX_STYLE = 'matrix(1, 0, 0, 1, 0, 0)';\n\n/**\n * Computes a CSS matrix() transform string from the cropper state.\n *\n * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)\n * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).\n *\n * Flip is composed outside rotation so it is viewport-relative — horizontal\n * flip mirrors across the viewport's vertical axis regardless of rotation.\n * Must match the matrix order in `createCamera` / `getImageCropBounds`.\n *\n * This is a pure function with no framework dependencies. The React hook\n * `useTransformStyle` wraps this in `useMemo` for memoization.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function computeTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\t// Match the identity short-circuit used by `createCamera` and\n\t// `getSourceRegion` so the preview path stays consistent with the math\n\t// path when `imageSize` itself is hostile (state sanitization below\n\t// only guards the state fields, not these size arguments).\n\tif ( ! isValidSize( imageSize ) ) {\n\t\treturn IDENTITY_MATRIX_STYLE;\n\t}\n\t// Sanitize so hostile state can't produce `matrix(NaN, NaN, ...)` here\n\t// while the parallel `createCamera` path returns a finite matrix. Both\n\t// paths must agree under defense-in-depth conditions.\n\tconst safeState = sanitizeCropperState( state );\n\tconst translateX = safeState.pan.x * imageSize.width;\n\tconst translateY = safeState.pan.y * imageSize.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\n\t// Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)\n\tconst a = sx * cos * z;\n\tconst b = sy * sin * z;\n\tconst c = -sx * sin * z;\n\tconst d = sy * cos * z;\n\n\treturn `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;\n}\n"],"mappings":";;;;AAKA,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;AAmB9B,SAAgB,sBACf,OACA,WACS;CAKT,IAAK,CAAE,YAAa,SAAU,GAC7B,OAAO;CAKR,MAAM,YAAY,qBAAsB,KAAM;CAC9C,MAAM,aAAa,UAAU,IAAI,IAAI,UAAU;CAC/C,MAAM,aAAa,UAAU,IAAI,IAAI,UAAU;CAC/C,MAAM,MAAM,iBAAkB,UAAU,QAAS;CACjD,MAAM,MAAM,KAAK,IAAK,GAAI;CAC1B,MAAM,MAAM,KAAK,IAAK,GAAI;CAC1B,MAAM,KAAK,UAAU,KAAK,aAAa,KAAK;CAC5C,MAAM,KAAK,UAAU,KAAK,WAAW,KAAK;CAC1C,MAAM,IAAI,UAAU;CAQpB,OAAO,UALG,KAAK,MAAM,EAKA,IAJX,KAAK,MAAM,EAIQ,IAHnB,CAAC,KAAK,MAAM,EAGe,IAF3B,KAAK,MAAM,EAEwB,IAAK,WAAY,IAAK,WAAY;AAChF"}
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
// packages/media-editor/src/image-editor/core/transforms/pipeline.ts
|
|
2
1
|
import { DEFAULT_STATE } from "../constants.mjs";
|
|
3
2
|
import { cropperReducer } from "../state.mjs";
|
|
3
|
+
// packages/media-editor/src/image-editor/core/transforms/pipeline.ts
|
|
4
|
+
/**
|
|
5
|
+
* Apply a single transform operation to a cropper state, returning
|
|
6
|
+
* a new state with the containment invariant enforced.
|
|
7
|
+
*
|
|
8
|
+
* Delegates to the reducer via APPLY_OPERATION so pipeline replay
|
|
9
|
+
* produces identical bounded state to UI interaction or setter
|
|
10
|
+
* calls. The same logical operation yields the same result
|
|
11
|
+
* regardless of entrypoint.
|
|
12
|
+
*
|
|
13
|
+
* @param state The current cropper state.
|
|
14
|
+
* @param op The operation to apply.
|
|
15
|
+
* @return A new cropper state with the operation applied.
|
|
16
|
+
*/
|
|
4
17
|
function applyOperationToState(state, op) {
|
|
5
|
-
|
|
18
|
+
return cropperReducer(state, {
|
|
19
|
+
type: "APPLY_OPERATION",
|
|
20
|
+
payload: op
|
|
21
|
+
});
|
|
6
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Replay all operations from an initial state to produce the final state.
|
|
25
|
+
*
|
|
26
|
+
* @param pipeline The array of transform operations to replay.
|
|
27
|
+
* @param initialState The starting state. Defaults to DEFAULT_STATE.
|
|
28
|
+
* @return The resulting cropper state after all operations are applied.
|
|
29
|
+
*/
|
|
7
30
|
function stateFromPipeline(pipeline, initialState = { ...DEFAULT_STATE }) {
|
|
8
|
-
|
|
9
|
-
(state, op) => applyOperationToState(state, op),
|
|
10
|
-
initialState
|
|
11
|
-
);
|
|
31
|
+
return pipeline.reduce((state, op) => applyOperationToState(state, op), initialState);
|
|
12
32
|
}
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=pipeline.mjs.map
|
|
33
|
+
export { applyOperationToState, stateFromPipeline };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=pipeline.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/image-editor/core/transforms/pipeline.ts"],
|
|
4
|
-
"sourcesContent": ["import type { TransformOperation, CropperState } from '../types';\nimport { DEFAULT_STATE } from '../constants';\nimport { cropperReducer } from '../state';\n\n/**\n * Apply a single transform operation to a cropper state, returning\n * a new state with the containment invariant enforced.\n *\n * Delegates to the reducer via APPLY_OPERATION so pipeline replay\n * produces identical bounded state to UI interaction or setter\n * calls. The same logical operation yields the same result\n * regardless of entrypoint.\n *\n * @param state The current cropper state.\n * @param op The operation to apply.\n * @return A new cropper state with the operation applied.\n */\nexport function applyOperationToState(\n\tstate: CropperState,\n\top: TransformOperation\n): CropperState {\n\treturn cropperReducer( state, { type: 'APPLY_OPERATION', payload: op } );\n}\n\n/**\n * Replay all operations from an initial state to produce the final state.\n *\n * @param pipeline The array of transform operations to replay.\n * @param initialState The starting state. Defaults to DEFAULT_STATE.\n * @return The resulting cropper state after all operations are applied.\n */\nexport function stateFromPipeline(\n\tpipeline: TransformOperation[],\n\tinitialState: CropperState = { ...DEFAULT_STATE }\n): CropperState {\n\treturn pipeline.reduce(\n\t\t( state, op ) => applyOperationToState( state, op ),\n\t\tinitialState\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AACA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAexB,SAAS,sBACf,OACA,IACe;AACf,SAAO,eAAgB,OAAO,EAAE,MAAM,mBAAmB,SAAS,GAAG,CAAE;AACxE;AASO,SAAS,kBACf,UACA,eAA6B,EAAE,GAAG,cAAc,GACjC;AACf,SAAO,SAAS;AAAA,IACf,CAAE,OAAO,OAAQ,sBAAuB,OAAO,EAAG;AAAA,IAClD;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"pipeline.mjs","names":[],"sources":["../../../../src/image-editor/core/transforms/pipeline.ts"],"sourcesContent":["import type { TransformOperation, CropperState } from '../types';\nimport { DEFAULT_STATE } from '../constants';\nimport { cropperReducer } from '../state';\n\n/**\n * Apply a single transform operation to a cropper state, returning\n * a new state with the containment invariant enforced.\n *\n * Delegates to the reducer via APPLY_OPERATION so pipeline replay\n * produces identical bounded state to UI interaction or setter\n * calls. The same logical operation yields the same result\n * regardless of entrypoint.\n *\n * @param state The current cropper state.\n * @param op The operation to apply.\n * @return A new cropper state with the operation applied.\n */\nexport function applyOperationToState(\n\tstate: CropperState,\n\top: TransformOperation\n): CropperState {\n\treturn cropperReducer( state, { type: 'APPLY_OPERATION', payload: op } );\n}\n\n/**\n * Replay all operations from an initial state to produce the final state.\n *\n * @param pipeline The array of transform operations to replay.\n * @param initialState The starting state. Defaults to DEFAULT_STATE.\n * @return The resulting cropper state after all operations are applied.\n */\nexport function stateFromPipeline(\n\tpipeline: TransformOperation[],\n\tinitialState: CropperState = { ...DEFAULT_STATE }\n): CropperState {\n\treturn pipeline.reduce(\n\t\t( state, op ) => applyOperationToState( state, op ),\n\t\tinitialState\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,sBACf,OACA,IACe;CACf,OAAO,eAAgB,OAAO;EAAE,MAAM;EAAmB,SAAS;CAAG,CAAE;AACxE;;;;;;;;AASA,SAAgB,kBACf,UACA,eAA6B,EAAE,GAAG,cAAc,GACjC;CACf,OAAO,SAAS,QACb,OAAO,OAAQ,sBAAuB,OAAO,EAAG,GAClD,YACD;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.mjs.map
|
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
// packages/media-editor/src/image-editor/core/viewport-state.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const DEFAULT_VIEWPORT_STATE = {
|
|
3
|
+
zoom: 1,
|
|
4
|
+
pan: {
|
|
5
|
+
x: 0,
|
|
6
|
+
y: 0
|
|
7
|
+
}
|
|
5
8
|
};
|
|
6
9
|
function viewportReducer(state, action) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case "SET_VIEWPORT_ZOOM": {
|
|
12
|
+
const zoom = Math.min(4, Math.max(.1, action.payload));
|
|
13
|
+
return zoom === state.zoom ? state : {
|
|
14
|
+
...state,
|
|
15
|
+
zoom
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
case "SET_VIEWPORT_PAN": {
|
|
19
|
+
const { x, y } = action.payload;
|
|
20
|
+
return x === state.pan.x && y === state.pan.y ? state : {
|
|
21
|
+
...state,
|
|
22
|
+
pan: action.payload
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
case "RESET_VIEWPORT": return state.zoom === DEFAULT_VIEWPORT_STATE.zoom && state.pan.x === DEFAULT_VIEWPORT_STATE.pan.x && state.pan.y === DEFAULT_VIEWPORT_STATE.pan.y ? state : DEFAULT_VIEWPORT_STATE;
|
|
26
|
+
}
|
|
19
27
|
}
|
|
20
|
-
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=viewport-state.mjs.map
|
|
28
|
+
export { DEFAULT_VIEWPORT_STATE, viewportReducer };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=viewport-state.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/image-editor/core/viewport-state.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ViewportState, ViewportAction } from './types';\n\nexport const DEFAULT_VIEWPORT_STATE: ViewportState = {\n\tzoom: 1,\n\tpan: { x: 0, y: 0 },\n};\n\nexport function viewportReducer(\n\tstate: ViewportState,\n\taction: ViewportAction\n): ViewportState {\n\tswitch ( action.type ) {\n\t\tcase 'SET_VIEWPORT_ZOOM': {\n\t\t\tconst zoom = Math.min( 4, Math.max( 0.1, action.payload ) );\n\t\t\treturn zoom === state.zoom ? state : { ...state, zoom };\n\t\t}\n\t\tcase 'SET_VIEWPORT_PAN': {\n\t\t\tconst { x, y } = action.payload;\n\t\t\treturn x === state.pan.x && y === state.pan.y\n\t\t\t\t? state\n\t\t\t\t: { ...state, pan: action.payload };\n\t\t}\n\t\tcase 'RESET_VIEWPORT':\n\t\t\treturn state.zoom === DEFAULT_VIEWPORT_STATE.zoom &&\n\t\t\t\tstate.pan.x === DEFAULT_VIEWPORT_STATE.pan.x &&\n\t\t\t\tstate.pan.y === DEFAULT_VIEWPORT_STATE.pan.y\n\t\t\t\t? state\n\t\t\t\t: DEFAULT_VIEWPORT_STATE;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";AAEO,IAAM,yBAAwC;AAAA,EACpD,MAAM;AAAA,EACN,KAAK,EAAE,GAAG,GAAG,GAAG,EAAE;AACnB;AAEO,SAAS,gBACf,OACA,QACgB;AAChB,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,qBAAqB;AACzB,YAAM,OAAO,KAAK,IAAK,GAAG,KAAK,IAAK,KAAK,OAAO,OAAQ,CAAE;AAC1D,aAAO,SAAS,MAAM,OAAO,QAAQ,EAAE,GAAG,OAAO,KAAK;AAAA,IACvD;AAAA,IACA,KAAK,oBAAoB;AACxB,YAAM,EAAE,GAAG,EAAE,IAAI,OAAO;AACxB,aAAO,MAAM,MAAM,IAAI,KAAK,MAAM,MAAM,IAAI,IACzC,QACA,EAAE,GAAG,OAAO,KAAK,OAAO,QAAQ;AAAA,IACpC;AAAA,IACA,KAAK;AACJ,aAAO,MAAM,SAAS,uBAAuB,QAC5C,MAAM,IAAI,MAAM,uBAAuB,IAAI,KAC3C,MAAM,IAAI,MAAM,uBAAuB,IAAI,IACzC,QACA;AAAA,EACL;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"viewport-state.mjs","names":[],"sources":["../../../src/image-editor/core/viewport-state.ts"],"sourcesContent":["import type { ViewportState, ViewportAction } from './types';\n\nexport const DEFAULT_VIEWPORT_STATE: ViewportState = {\n\tzoom: 1,\n\tpan: { x: 0, y: 0 },\n};\n\nexport function viewportReducer(\n\tstate: ViewportState,\n\taction: ViewportAction\n): ViewportState {\n\tswitch ( action.type ) {\n\t\tcase 'SET_VIEWPORT_ZOOM': {\n\t\t\tconst zoom = Math.min( 4, Math.max( 0.1, action.payload ) );\n\t\t\treturn zoom === state.zoom ? state : { ...state, zoom };\n\t\t}\n\t\tcase 'SET_VIEWPORT_PAN': {\n\t\t\tconst { x, y } = action.payload;\n\t\t\treturn x === state.pan.x && y === state.pan.y\n\t\t\t\t? state\n\t\t\t\t: { ...state, pan: action.payload };\n\t\t}\n\t\tcase 'RESET_VIEWPORT':\n\t\t\treturn state.zoom === DEFAULT_VIEWPORT_STATE.zoom &&\n\t\t\t\tstate.pan.x === DEFAULT_VIEWPORT_STATE.pan.x &&\n\t\t\t\tstate.pan.y === DEFAULT_VIEWPORT_STATE.pan.y\n\t\t\t\t? state\n\t\t\t\t: DEFAULT_VIEWPORT_STATE;\n\t}\n}\n"],"mappings":";AAEA,MAAa,yBAAwC;CACpD,MAAM;CACN,KAAK;EAAE,GAAG;EAAG,GAAG;CAAE;AACnB;AAEA,SAAgB,gBACf,OACA,QACgB;CAChB,QAAS,OAAO,MAAhB;EACC,KAAK,qBAAqB;GACzB,MAAM,OAAO,KAAK,IAAK,GAAG,KAAK,IAAK,IAAK,OAAO,OAAQ,CAAE;GAC1D,OAAO,SAAS,MAAM,OAAO,QAAQ;IAAE,GAAG;IAAO;GAAK;EACvD;EACA,KAAK,oBAAoB;GACxB,MAAM,EAAE,GAAG,MAAM,OAAO;GACxB,OAAO,MAAM,MAAM,IAAI,KAAK,MAAM,MAAM,IAAI,IACzC,QACA;IAAE,GAAG;IAAO,KAAK,OAAO;GAAQ;EACpC;EACA,KAAK,kBACJ,OAAO,MAAM,SAAS,uBAAuB,QAC5C,MAAM,IAAI,MAAM,uBAAuB,IAAI,KAC3C,MAAM,IAAI,MAAM,uBAAuB,IAAI,IACzC,QACA;CACL;AACD"}
|
|
@@ -1,39 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { useCropperReducer, buildCropperSetters } from "./react/hooks/index.mjs";
|
|
1
|
+
import { useCropperController } from "./react/hooks/index.mjs";
|
|
3
2
|
import { Cropper, CropperProvider, useCropper } from "./react/components/index.mjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
DEFAULT_ASPECT_RATIOS,
|
|
7
|
-
ORIGINAL_ASPECT_RATIO,
|
|
8
|
-
cropperReducer,
|
|
9
|
-
enforceContainment,
|
|
10
|
-
areCropperStatesEqual,
|
|
11
|
-
computeInscribedRect,
|
|
12
|
-
getSourceRegion,
|
|
13
|
-
getSourceRegionPercent,
|
|
14
|
-
applyOperationToState,
|
|
15
|
-
stateFromPipeline,
|
|
16
|
-
exportCroppedImage,
|
|
17
|
-
applyToCanvas
|
|
18
|
-
} from "./core/index.mjs";
|
|
19
|
-
export {
|
|
20
|
-
Cropper,
|
|
21
|
-
CropperProvider,
|
|
22
|
-
DEFAULT_ASPECT_RATIOS,
|
|
23
|
-
DEFAULT_STATE,
|
|
24
|
-
ORIGINAL_ASPECT_RATIO,
|
|
25
|
-
applyOperationToState,
|
|
26
|
-
applyToCanvas,
|
|
27
|
-
areCropperStatesEqual,
|
|
28
|
-
buildCropperSetters,
|
|
29
|
-
computeInscribedRect,
|
|
30
|
-
cropperReducer,
|
|
31
|
-
enforceContainment,
|
|
32
|
-
exportCroppedImage,
|
|
33
|
-
getSourceRegion,
|
|
34
|
-
getSourceRegionPercent,
|
|
35
|
-
stateFromPipeline,
|
|
36
|
-
useCropper,
|
|
37
|
-
useCropperReducer
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=index.mjs.map
|
|
3
|
+
import { ORIGINAL_ASPECT_RATIO, applyToCanvas, exportCroppedImage, getSourceRegion, getSourceRegionPercent, stateFromPipeline } from "./core/index.mjs";
|
|
4
|
+
export { Cropper, CropperProvider, ORIGINAL_ASPECT_RATIO, applyToCanvas, exportCroppedImage, getSourceRegion, getSourceRegionPercent, stateFromPipeline, useCropper, useCropperController };
|
|
@@ -1,26 +1,43 @@
|
|
|
1
|
-
// packages/media-editor/src/image-editor/react/components/cropper-provider.tsx
|
|
2
1
|
import { createContext, useContext } from "@wordpress/element";
|
|
3
|
-
import {
|
|
4
|
-
useCropperReducer
|
|
5
|
-
} from "../hooks/use-cropper-reducer.mjs";
|
|
2
|
+
import { useCropperController } from "../hooks/use-cropper-controller.mjs";
|
|
6
3
|
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
// packages/media-editor/src/image-editor/react/components/cropper-provider.tsx
|
|
5
|
+
const CropperContext = createContext(null);
|
|
6
|
+
/**
|
|
7
|
+
* Convenience context provider that wraps `useCropperController`.
|
|
8
|
+
*
|
|
9
|
+
* Provides the pure cropper controller (state + setters, NO undo
|
|
10
|
+
* history) to all descendant components via React context.
|
|
11
|
+
*
|
|
12
|
+
* History is a higher-layer concern owned by composite stores
|
|
13
|
+
* (see `useMediaEditorState` in media-editor/state for the media
|
|
14
|
+
* editor's composite controller with undo/redo).
|
|
15
|
+
*
|
|
16
|
+
* @param props
|
|
17
|
+
* @param props.initialState
|
|
18
|
+
* @param props.children
|
|
19
|
+
* @return The provider element wrapping children.
|
|
20
|
+
*/
|
|
21
|
+
function CropperProvider({ initialState, children }) {
|
|
22
|
+
const cropperReturn = useCropperController(initialState);
|
|
23
|
+
return /* @__PURE__ */ jsx(CropperContext.Provider, {
|
|
24
|
+
value: cropperReturn,
|
|
25
|
+
children
|
|
26
|
+
});
|
|
14
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Hook to consume the CropperProvider context.
|
|
30
|
+
*
|
|
31
|
+
* Must be used within a CropperProvider. Throws if used outside
|
|
32
|
+
* of the provider tree.
|
|
33
|
+
*
|
|
34
|
+
* @return The cropper controller.
|
|
35
|
+
*/
|
|
15
36
|
function useCropper() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return context;
|
|
37
|
+
const context = useContext(CropperContext);
|
|
38
|
+
if (!context) throw new Error("useCropper must be used within a CropperProvider.");
|
|
39
|
+
return context;
|
|
21
40
|
}
|
|
22
|
-
export {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=cropper-provider.mjs.map
|
|
41
|
+
export { CropperProvider, useCropper };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=cropper-provider.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/image-editor/react/components/cropper-provider.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseCropperReducer,\n\ttype CropperController,\n} from '../hooks/use-cropper-reducer';\nimport type { CropperState } from '../../core/types';\n\n/**\n * The context value type for the CropperProvider.\n * Contains the cropper controller from useCropperReducer.\n */\ntype CropperContextValue = CropperController | null;\n\nconst CropperContext = createContext< CropperContextValue >( null );\n\n/**\n * Props for the CropperProvider component.\n */\ninterface CropperProviderProps {\n\t/** Optional partial initial state to merge with defaults. */\n\tinitialState?: Partial< CropperState >;\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Convenience context provider that wraps `useCropperReducer`.\n *\n * Provides the pure cropper controller (state + setters, NO undo\n * history) to all descendant components via React context.\n *\n * History is a higher-layer concern owned by composite stores\n * (see `useMediaEditorState` in media-editor/state for the media\n * editor's composite controller with undo/redo).\n *\n * @param props\n * @param props.initialState\n * @param props.children\n * @return The provider element wrapping children.\n */\nexport function CropperProvider( {\n\tinitialState,\n\tchildren,\n}: CropperProviderProps ) {\n\tconst cropperReturn = useCropperReducer( initialState );\n\n\treturn (\n\t\t<CropperContext.Provider value={ cropperReturn }>\n\t\t\t{ children }\n\t\t</CropperContext.Provider>\n\t);\n}\n\n/**\n * Hook to consume the CropperProvider context.\n *\n * Must be used within a CropperProvider. Throws if used outside\n * of the provider tree.\n *\n * @return The cropper controller.\n */\nexport function useCropper(): CropperController {\n\tconst context = useContext( CropperContext );\n\n\tif ( ! context ) {\n\t\tthrow new Error( 'useCropper must be used within a CropperProvider.' );\n\t}\n\n\treturn context;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,eAAe,kBAAkB;AAC1C;AAAA,EACC;AAAA,OAEM;AA2CL;AAlCF,IAAM,iBAAiB,cAAsC,IAAK;AA2B3D,SAAS,gBAAiB;AAAA,EAChC;AAAA,EACA;AACD,GAA0B;AACzB,QAAM,gBAAgB,kBAAmB,YAAa;AAEtD,SACC,oBAAC,eAAe,UAAf,EAAwB,OAAQ,eAC9B,UACH;AAEF;AAUO,SAAS,aAAgC;AAC/C,QAAM,UAAU,WAAY,cAAe;AAE3C,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI,MAAO,mDAAoD;AAAA,EACtE;AAEA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"cropper-provider.mjs","names":[],"sources":["../../../../src/image-editor/react/components/cropper-provider.tsx"],"sourcesContent":["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseCropperController,\n\ttype CropperController,\n} from '../hooks/use-cropper-controller';\nimport type { CropperState } from '../../core/types';\n\n/**\n * The context value type for the CropperProvider.\n * Contains the cropper controller from useCropperController.\n */\ntype CropperContextValue = CropperController | null;\n\nconst CropperContext = createContext< CropperContextValue >( null );\n\n/**\n * Props for the CropperProvider component.\n */\ninterface CropperProviderProps {\n\t/** Optional partial initial state to merge with defaults. */\n\tinitialState?: Partial< CropperState >;\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Convenience context provider that wraps `useCropperController`.\n *\n * Provides the pure cropper controller (state + setters, NO undo\n * history) to all descendant components via React context.\n *\n * History is a higher-layer concern owned by composite stores\n * (see `useMediaEditorState` in media-editor/state for the media\n * editor's composite controller with undo/redo).\n *\n * @param props\n * @param props.initialState\n * @param props.children\n * @return The provider element wrapping children.\n */\nexport function CropperProvider( {\n\tinitialState,\n\tchildren,\n}: CropperProviderProps ) {\n\tconst cropperReturn = useCropperController( initialState );\n\n\treturn (\n\t\t<CropperContext.Provider value={ cropperReturn }>\n\t\t\t{ children }\n\t\t</CropperContext.Provider>\n\t);\n}\n\n/**\n * Hook to consume the CropperProvider context.\n *\n * Must be used within a CropperProvider. Throws if used outside\n * of the provider tree.\n *\n * @return The cropper controller.\n */\nexport function useCropper(): CropperController {\n\tconst context = useContext( CropperContext );\n\n\tif ( ! context ) {\n\t\tthrow new Error( 'useCropper must be used within a CropperProvider.' );\n\t}\n\n\treturn context;\n}\n"],"mappings":";;;;AAaA,MAAM,iBAAiB,cAAsC,IAAK;;;;;;;;;;;;;;;;AA2BlE,SAAgB,gBAAiB,EAChC,cACA,YACyB;CACzB,MAAM,gBAAgB,qBAAsB,YAAa;CAEzD,OACC,oBAAC,eAAe,UAAhB;EAAyB,OAAQ;EAC9B;CACsB,CAAA;AAE3B;;;;;;;;;AAUA,SAAgB,aAAgC;CAC/C,MAAM,UAAU,WAAY,cAAe;CAE3C,IAAK,CAAE,SACN,MAAM,IAAI,MAAO,mDAAoD;CAGtE,OAAO;AACR"}
|