@wordpress/media-editor 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/components/media-editor/index.cjs +533 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +43 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +111 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +122 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +65 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +62 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +183 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
- package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
- package/build/components/media-editor-modal/index.cjs +112 -155
- package/build/components/media-editor-modal/index.cjs.map +1 -7
- package/build/components/media-editor-provider/index.cjs +32 -55
- package/build/components/media-editor-provider/index.cjs.map +1 -7
- package/build/components/media-form/index.cjs +76 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +114 -114
- package/build/components/media-preview/index.cjs.map +1 -7
- package/build/components/rotation-ruler/index.cjs +181 -188
- package/build/components/rotation-ruler/index.cjs.map +1 -7
- package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
- package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
- package/build/image-editor/core/camera.cjs +257 -205
- package/build/image-editor/core/camera.cjs.map +1 -7
- package/build/image-editor/core/constants.cjs +127 -102
- package/build/image-editor/core/constants.cjs.map +1 -7
- package/build/image-editor/core/containment.cjs +275 -262
- package/build/image-editor/core/containment.cjs.map +1 -7
- package/build/image-editor/core/crop-rect.cjs +33 -44
- package/build/image-editor/core/crop-rect.cjs.map +1 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
- package/build/image-editor/core/index.cjs +88 -61
- package/build/image-editor/core/interaction-controller.cjs +583 -646
- package/build/image-editor/core/interaction-controller.cjs.map +1 -7
- package/build/image-editor/core/math/rotation.cjs +26 -35
- package/build/image-editor/core/math/rotation.cjs.map +1 -7
- package/build/image-editor/core/math/sanitize.cjs +124 -80
- package/build/image-editor/core/math/sanitize.cjs.map +1 -7
- package/build/image-editor/core/setter-helpers.cjs +57 -60
- package/build/image-editor/core/setter-helpers.cjs.map +1 -7
- package/build/image-editor/core/source-region.cjs +220 -190
- package/build/image-editor/core/source-region.cjs.map +1 -7
- package/build/image-editor/core/state.cjs +278 -265
- package/build/image-editor/core/state.cjs.map +1 -7
- package/build/image-editor/core/stencil-math.cjs +193 -206
- package/build/image-editor/core/stencil-math.cjs.map +1 -7
- package/build/image-editor/core/transform-style.cjs +39 -48
- package/build/image-editor/core/transform-style.cjs.map +1 -7
- package/build/image-editor/core/transforms/pipeline.cjs +36 -38
- package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
- package/build/image-editor/core/types.cjs +4 -18
- package/build/image-editor/core/viewport-state.cjs +31 -45
- package/build/image-editor/core/viewport-state.cjs.map +1 -7
- package/build/image-editor/index.cjs +65 -64
- package/build/image-editor/react/components/cropper-provider.cjs +44 -45
- package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
- package/build/image-editor/react/components/cropper.cjs +583 -710
- package/build/image-editor/react/components/cropper.cjs.map +1 -7
- package/build/image-editor/react/components/index.cjs +22 -33
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
- package/build/image-editor/react/components/viewport-provider.cjs +21 -46
- package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
- package/build/image-editor/react/hooks/index.cjs +16 -31
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
- package/build/image-editor/react/visually-hidden-style.cjs +21 -38
- package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
- package/build/index.cjs +45 -39
- package/build/lock-unlock.cjs +9 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/private-apis.cjs +16 -37
- package/build/private-apis.cjs.map +1 -7
- package/build/state/aspect-ratio-presets.cjs +53 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +134 -112
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +63 -47
- package/build/state/media-editor-state-provider.cjs +35 -48
- package/build/state/media-editor-state-provider.cjs.map +1 -7
- package/build/state/types.cjs +12 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +261 -294
- package/build/state/use-media-editor-state.cjs.map +1 -7
- package/build/store/actions.cjs +17 -44
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +8 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +33 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +28 -50
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +16 -41
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils/get-media-type.cjs +18 -41
- package/build/utils/get-media-type.cjs.map +1 -7
- package/build/utils/index.cjs +9 -28
- package/build-module/components/media-editor/index.mjs +490 -673
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +38 -32
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
- package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +98 -96
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
- package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +172 -237
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
- package/build-module/components/media-editor-modal/index.mjs +88 -124
- package/build-module/components/media-editor-modal/index.mjs.map +1 -7
- package/build-module/components/media-editor-provider/index.mjs +26 -29
- package/build-module/components/media-editor-provider/index.mjs.map +1 -7
- package/build-module/components/media-form/index.mjs +68 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +106 -90
- package/build-module/components/media-preview/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/index.mjs +161 -164
- package/build-module/components/rotation-ruler/index.mjs.map +1 -7
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
- package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
- package/build-module/image-editor/core/camera.mjs +245 -178
- package/build-module/image-editor/core/camera.mjs.map +1 -7
- package/build-module/image-editor/core/constants.mjs +110 -64
- package/build-module/image-editor/core/constants.mjs.map +1 -7
- package/build-module/image-editor/core/containment.mjs +265 -237
- package/build-module/image-editor/core/containment.mjs.map +1 -7
- package/build-module/image-editor/core/crop-rect.mjs +29 -20
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
- package/build-module/image-editor/core/index.mjs +5 -34
- package/build-module/image-editor/core/interaction-controller.mjs +579 -628
- package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
- package/build-module/image-editor/core/math/rotation.mjs +21 -10
- package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
- package/build-module/image-editor/core/math/sanitize.mjs +116 -52
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
- package/build-module/image-editor/core/setter-helpers.mjs +52 -35
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
- package/build-module/image-editor/core/source-region.mjs +210 -160
- package/build-module/image-editor/core/source-region.mjs.map +1 -7
- package/build-module/image-editor/core/state.mjs +271 -243
- package/build-module/image-editor/core/state.mjs.map +1 -7
- package/build-module/image-editor/core/stencil-math.mjs +185 -178
- package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
- package/build-module/image-editor/core/transform-style.mjs +34 -23
- package/build-module/image-editor/core/transform-style.mjs.map +1 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/viewport-state.mjs +26 -20
- package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
- package/build-module/image-editor/index.mjs +3 -38
- package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
- package/build-module/image-editor/react/components/cropper.mjs +550 -686
- package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
- package/build-module/image-editor/react/components/index.mjs +1 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/index.mjs +2 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
- package/build-module/index.mjs +3 -10
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/private-apis.mjs +8 -9
- package/build-module/private-apis.mjs.map +1 -7
- package/build-module/state/aspect-ratio-presets.mjs +48 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +114 -90
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +5 -25
- package/build-module/state/media-editor-state-provider.mjs +29 -24
- package/build-module/state/media-editor-state-provider.mjs.map +1 -7
- package/build-module/state/types.mjs +8 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +256 -286
- package/build-module/state/use-media-editor-state.mjs.map +1 -7
- package/build-module/store/actions.mjs +12 -19
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +4 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +8 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +23 -26
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +8 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils/get-media-type.mjs +14 -17
- package/build-module/utils/get-media-type.mjs.map +1 -7
- package/build-module/utils/index.mjs +1 -6
- package/build-style/style-rtl.css +41 -4
- package/build-style/style.css +41 -4
- package/build-types/components/media-editor/index.d.ts +4 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +0 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/index.d.ts +1 -1
- package/build-types/image-editor/core/index.d.ts.map +1 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +1 -1
- package/build-types/image-editor/index.d.ts +7 -6
- package/build-types/image-editor/index.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +5 -14
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts +2 -2
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
- package/build-types/state/aspect-ratio-presets.d.ts +7 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +1 -1
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +1 -0
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +2 -1
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/components/media-editor/index.tsx +215 -162
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +5 -2
- package/src/components/media-editor/use-save-media-editor.ts +2 -6
- package/src/components/media-editor-canvas/index.tsx +16 -26
- package/src/components/media-editor-image-controls/index.tsx +4 -2
- package/src/components/media-editor-modal/build-modifiers.ts +13 -7
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-preview/index.tsx +66 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +6 -2
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/image-editor/README.md +8 -8
- package/src/image-editor/core/constants.ts +0 -13
- package/src/image-editor/core/index.ts +1 -5
- package/src/image-editor/core/setter-helpers.ts +1 -1
- package/src/image-editor/core/types.ts +1 -1
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +3 -3
- package/src/image-editor/index.ts +7 -16
- package/src/image-editor/react/components/cropper-provider.tsx +5 -5
- package/src/image-editor/react/components/cropper.tsx +19 -27
- package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
- package/src/image-editor/react/hooks/index.ts +2 -2
- package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
- package/src/state/aspect-ratio-presets.ts +18 -0
- package/src/state/composite-reducer.ts +2 -2
- package/src/state/index.ts +1 -0
- package/src/state/types.ts +2 -6
- package/src/state/use-media-editor-state.ts +7 -5
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
- package/build/index.cjs.map +0 -7
- package/build/state/index.cjs.map +0 -7
- package/build/utils/index.cjs.map +0 -7
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/state/index.mjs.map +0 -7
- package/build-module/utils/index.mjs.map +0 -7
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/image-editor/react/hooks/use-viewport-state.ts"],
|
|
4
|
-
"sourcesContent": ["import { useReducer, useCallback, useMemo } from '@wordpress/element';\nimport type { ViewportState } from '../../core/types';\nimport {\n\tviewportReducer,\n\tDEFAULT_VIEWPORT_STATE,\n} from '../../core/viewport-state';\n\nexport interface UseViewportStateReturn {\n\tviewport: ViewportState;\n\t/**\n\t * Unused in the current Cropper implementation — scaffolded for the\n\t * upcoming navigator panel (viewport zoom slider).\n\t */\n\tsetViewportZoom: ( zoom: number ) => void;\n\tsetViewportPan: ( pan: { x: number; y: number } ) => void;\n\tresetViewport: () => void;\n}\n\nexport function useViewportState(): UseViewportStateReturn {\n\tconst [ viewport, dispatch ] = useReducer(\n\t\tviewportReducer,\n\t\tDEFAULT_VIEWPORT_STATE\n\t);\n\n\tconst setViewportZoom = useCallback( ( zoom: number ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_ZOOM', payload: zoom } );\n\t}, [] );\n\n\tconst setViewportPan = useCallback( ( pan: { x: number; y: number } ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_PAN', payload: pan } );\n\t}, [] );\n\n\tconst resetViewport = useCallback( () => {\n\t\tdispatch( { type: 'RESET_VIEWPORT' } );\n\t}, [] );\n\n\treturn useMemo(\n\t\t() => ( { viewport, setViewportZoom, setViewportPan, resetViewport } ),\n\t\t[ viewport, setViewportZoom, setViewportPan, resetViewport ]\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,YAAY,aAAa,eAAe;AAEjD;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAaA,SAAS,mBAA2C;AAC1D,QAAM,CAAE,UAAU,QAAS,IAAI;AAAA,IAC9B;AAAA,IACA;AAAA,EACD;AAEA,QAAM,kBAAkB,YAAa,CAAE,SAAkB;AACxD,aAAU,EAAE,MAAM,qBAAqB,SAAS,KAAK,CAAE;AAAA,EACxD,GAAG,CAAC,CAAE;AAEN,QAAM,iBAAiB,YAAa,CAAE,QAAmC;AACxE,aAAU,EAAE,MAAM,oBAAoB,SAAS,IAAI,CAAE;AAAA,EACtD,GAAG,CAAC,CAAE;AAEN,QAAM,gBAAgB,YAAa,MAAM;AACxC,aAAU,EAAE,MAAM,iBAAiB,CAAE;AAAA,EACtC,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,OAAQ,EAAE,UAAU,iBAAiB,gBAAgB,cAAc;AAAA,IACnE,CAAE,UAAU,iBAAiB,gBAAgB,aAAc;AAAA,EAC5D;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"use-viewport-state.mjs","names":[],"sources":["../../../../src/image-editor/react/hooks/use-viewport-state.ts"],"sourcesContent":["import { useReducer, useCallback, useMemo } from '@wordpress/element';\nimport type { ViewportState } from '../../core/types';\nimport {\n\tviewportReducer,\n\tDEFAULT_VIEWPORT_STATE,\n} from '../../core/viewport-state';\n\nexport interface UseViewportStateReturn {\n\tviewport: ViewportState;\n\t/**\n\t * Unused in the current Cropper implementation — scaffolded for the\n\t * upcoming navigator panel (viewport zoom slider).\n\t */\n\tsetViewportZoom: ( zoom: number ) => void;\n\tsetViewportPan: ( pan: { x: number; y: number } ) => void;\n\tresetViewport: () => void;\n}\n\nexport function useViewportState(): UseViewportStateReturn {\n\tconst [ viewport, dispatch ] = useReducer(\n\t\tviewportReducer,\n\t\tDEFAULT_VIEWPORT_STATE\n\t);\n\n\tconst setViewportZoom = useCallback( ( zoom: number ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_ZOOM', payload: zoom } );\n\t}, [] );\n\n\tconst setViewportPan = useCallback( ( pan: { x: number; y: number } ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_PAN', payload: pan } );\n\t}, [] );\n\n\tconst resetViewport = useCallback( () => {\n\t\tdispatch( { type: 'RESET_VIEWPORT' } );\n\t}, [] );\n\n\treturn useMemo(\n\t\t() => ( { viewport, setViewportZoom, setViewportPan, resetViewport } ),\n\t\t[ viewport, setViewportZoom, setViewportPan, resetViewport ]\n\t);\n}\n"],"mappings":";;;AAkBA,SAAgB,mBAA2C;CAC1D,MAAM,CAAE,UAAU,YAAa,WAC9B,iBACA,sBACD;CAEA,MAAM,kBAAkB,aAAe,SAAkB;EACxD,SAAU;GAAE,MAAM;GAAqB,SAAS;EAAK,CAAE;CACxD,GAAG,CAAC,CAAE;CAEN,MAAM,iBAAiB,aAAe,QAAmC;EACxE,SAAU;GAAE,MAAM;GAAoB,SAAS;EAAI,CAAE;CACtD,GAAG,CAAC,CAAE;CAEN,MAAM,gBAAgB,kBAAmB;EACxC,SAAU,EAAE,MAAM,iBAAiB,CAAE;CACtC,GAAG,CAAC,CAAE;CAEN,OAAO,eACE;EAAE;EAAU;EAAiB;EAAgB;CAAc,IACnE;EAAE;EAAU;EAAiB;EAAgB;CAAc,CAC5D;AACD"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
// packages/media-editor/src/image-editor/react/visually-hidden-style.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
/**
|
|
3
|
+
* CSS style object that visually hides an element while keeping it accessible
|
|
4
|
+
* to screen readers.
|
|
5
|
+
*/
|
|
6
|
+
const VISUALLY_HIDDEN_STYLE = {
|
|
7
|
+
position: "absolute",
|
|
8
|
+
width: 1,
|
|
9
|
+
height: 1,
|
|
10
|
+
padding: 0,
|
|
11
|
+
margin: -1,
|
|
12
|
+
overflow: "hidden",
|
|
13
|
+
clip: "rect(0, 0, 0, 0)",
|
|
14
|
+
whiteSpace: "nowrap",
|
|
15
|
+
border: 0
|
|
12
16
|
};
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=visually-hidden-style.mjs.map
|
|
17
|
+
export { VISUALLY_HIDDEN_STYLE };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=visually-hidden-style.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/image-editor/react/visually-hidden-style.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * CSS style object that visually hides an element while keeping it accessible\n * to screen readers.\n */\nexport const VISUALLY_HIDDEN_STYLE: React.CSSProperties = {\n\tposition: 'absolute',\n\twidth: 1,\n\theight: 1,\n\tpadding: 0,\n\tmargin: -1,\n\toverflow: 'hidden',\n\tclip: 'rect(0, 0, 0, 0)',\n\twhiteSpace: 'nowrap',\n\tborder: 0,\n};\n"],
|
|
5
|
-
"mappings": ";AAIO,IAAM,wBAA6C;AAAA,EACzD,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,QAAQ;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"visually-hidden-style.mjs","names":[],"sources":["../../../src/image-editor/react/visually-hidden-style.ts"],"sourcesContent":["/**\n * CSS style object that visually hides an element while keeping it accessible\n * to screen readers.\n */\nexport const VISUALLY_HIDDEN_STYLE: React.CSSProperties = {\n\tposition: 'absolute',\n\twidth: 1,\n\theight: 1,\n\tpadding: 0,\n\tmargin: -1,\n\toverflow: 'hidden',\n\tclip: 'rect(0, 0, 0, 0)',\n\twhiteSpace: 'nowrap',\n\tborder: 0,\n};\n"],"mappings":";;;;;AAIA,MAAa,wBAA6C;CACzD,UAAU;CACV,OAAO;CACP,QAAQ;CACR,SAAS;CACT,QAAQ;CACR,UAAU;CACV,MAAM;CACN,YAAY;CACZ,QAAQ;AACT"}
|
package/build-module/index.mjs
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
// packages/media-editor/src/index.ts
|
|
2
1
|
import { MediaEditorProvider } from "./components/media-editor-provider/index.mjs";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import MediaPreview from "./components/media-preview/index.mjs";
|
|
3
|
+
import MediaForm from "./components/media-form/index.mjs";
|
|
5
4
|
import { privateApis } from "./private-apis.mjs";
|
|
6
|
-
export {
|
|
7
|
-
MediaEditorProvider,
|
|
8
|
-
default3 as MediaForm,
|
|
9
|
-
default2 as MediaPreview,
|
|
10
|
-
privateApis
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=index.mjs.map
|
|
5
|
+
export { MediaEditorProvider, MediaForm, MediaPreview, privateApis };
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
// packages/media-editor/src/lock-unlock.ts
|
|
2
1
|
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
lock,
|
|
9
|
-
unlock
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=lock-unlock.mjs.map
|
|
2
|
+
// packages/media-editor/src/lock-unlock.ts
|
|
3
|
+
const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules("I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.", "@wordpress/media-editor");
|
|
4
|
+
export { lock, unlock };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=lock-unlock.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/lock-unlock.ts"],
|
|
4
|
-
"sourcesContent": ["import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/media-editor'\n\t);\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,wDAAwD;AAE1D,IAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"lock-unlock.mjs","names":[],"sources":["../src/lock-unlock.ts"],"sourcesContent":["import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/media-editor'\n\t);\n"],"mappings":";;AAEA,MAAa,EAAE,MAAM,WACpB,iDACC,iIACA,yBACD"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
// packages/media-editor/src/private-apis.ts
|
|
2
1
|
import { lock } from "./lock-unlock.mjs";
|
|
3
2
|
import { store } from "./store/index.mjs";
|
|
4
3
|
import { MediaEditorModal } from "./components/media-editor-modal/index.mjs";
|
|
5
4
|
import { MediaEditor } from "./components/media-editor/index.mjs";
|
|
6
|
-
|
|
5
|
+
// packages/media-editor/src/private-apis.ts
|
|
6
|
+
const privateApis = {};
|
|
7
7
|
lock(privateApis, {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
store,
|
|
9
|
+
MediaEditor,
|
|
10
|
+
MediaEditorModal
|
|
11
11
|
});
|
|
12
|
-
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=private-apis.mjs.map
|
|
12
|
+
export { privateApis };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=private-apis.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/private-apis.ts"],
|
|
4
|
-
"sourcesContent": ["import { lock } from './lock-unlock';\nimport { store } from './store';\nimport { MediaEditorModal } from './components/media-editor-modal';\nimport { MediaEditor } from './components/media-editor';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tstore,\n\tMediaEditor,\n\tMediaEditorModal,\n} );\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,YAAY;AACrB,SAAS,aAAa;AACtB,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAErB,IAAM,cAAc,CAAC;AAC5B,KAAM,aAAa;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"private-apis.mjs","names":[],"sources":["../src/private-apis.ts"],"sourcesContent":["import { lock } from './lock-unlock';\nimport { store } from './store';\nimport { MediaEditorModal } from './components/media-editor-modal';\nimport { MediaEditor } from './components/media-editor';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tstore,\n\tMediaEditor,\n\tMediaEditorModal,\n} );\n"],"mappings":";;;;;AAKA,MAAa,cAAc,CAAC;AAC5B,KAAM,aAAa;CAClB;CACA;CACA;AACD,CAAE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __ } from "@wordpress/i18n";
|
|
2
|
+
import { ORIGINAL_ASPECT_RATIO } from "../image-editor/index.mjs";
|
|
3
|
+
// packages/media-editor/src/state/aspect-ratio-presets.ts
|
|
4
|
+
/**
|
|
5
|
+
* The presets the editor offers by default. The labels live here rather
|
|
6
|
+
* than in the cropper core, which has no user-facing strings.
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_ASPECT_RATIOS = [
|
|
9
|
+
{
|
|
10
|
+
label: __("Free"),
|
|
11
|
+
value: 0
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
label: __("Original"),
|
|
15
|
+
value: ORIGINAL_ASPECT_RATIO
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
label: __("Square (1:1)"),
|
|
19
|
+
value: 1
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: __("Landscape (16:9)"),
|
|
23
|
+
value: 16 / 9
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: __("Portrait (9:16)"),
|
|
27
|
+
value: 9 / 16
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: __("Classic (4:3)"),
|
|
31
|
+
value: 4 / 3
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
label: __("Classic portrait (3:4)"),
|
|
35
|
+
value: 3 / 4
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: __("Photo (3:2)"),
|
|
39
|
+
value: 3 / 2
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
label: __("Photo portrait (2:3)"),
|
|
43
|
+
value: 2 / 3
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
export { DEFAULT_ASPECT_RATIOS };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=aspect-ratio-presets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aspect-ratio-presets.mjs","names":[],"sources":["../../src/state/aspect-ratio-presets.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { ORIGINAL_ASPECT_RATIO, type AspectRatioPreset } from '../image-editor';\n\n/**\n * The presets the editor offers by default. The labels live here rather\n * than in the cropper core, which has no user-facing strings.\n */\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },\n\t{ label: __( 'Photo (3:2)' ), value: 3 / 2 },\n\t{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },\n];\n"],"mappings":";;;;;;;AAOA,MAAa,wBAA6C;CACzD;EAAE,OAAO,GAAI,MAAO;EAAG,OAAO;CAAE;CAChC;EAAE,OAAO,GAAI,UAAW;EAAG,OAAO;CAAsB;CACxD;EAAE,OAAO,GAAI,cAAe;EAAG,OAAO;CAAE;CACxC;EAAE,OAAO,GAAI,kBAAmB;EAAG,OAAO,KAAK;CAAE;CACjD;EAAE,OAAO,GAAI,iBAAkB;EAAG,OAAO,IAAI;CAAG;CAChD;EAAE,OAAO,GAAI,eAAgB;EAAG,OAAO,IAAI;CAAE;CAC7C;EAAE,OAAO,GAAI,wBAAyB;EAAG,OAAO,IAAI;CAAE;CACtD;EAAE,OAAO,GAAI,aAAc;EAAG,OAAO,IAAI;CAAE;CAC3C;EAAE,OAAO,GAAI,sBAAuB;EAAG,OAAO,IAAI;CAAE;AACrD"}
|
|
@@ -1,97 +1,121 @@
|
|
|
1
|
-
// packages/media-editor/src/state/composite-reducer.ts
|
|
2
1
|
import fastDeepEqual from "fast-deep-equal/es6/index.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { areCropperStatesEqual, computeInscribedRect, cropperReducer } from "../image-editor/core/index.mjs";
|
|
3
|
+
import { DEFAULT_CROP_OPTIONS } from "./types.mjs";
|
|
4
|
+
// packages/media-editor/src/state/composite-reducer.ts
|
|
5
|
+
/**
|
|
6
|
+
* Pure composite reducer for the media editor.
|
|
7
|
+
*
|
|
8
|
+
* Delegates `CROPPER`-tagged actions to the framework-agnostic
|
|
9
|
+
* `cropperReducer` and owns first-class transitions for the sidebar
|
|
10
|
+
* `cropOptions` slice. `RESTORE_SNAPSHOT` replaces the whole composite
|
|
11
|
+
* in one transaction (used by undo/redo).
|
|
12
|
+
*
|
|
13
|
+
* Note: this reducer carries NO history of its own. Snapshots and
|
|
14
|
+
* stacks live in the `useMediaEditorState` hook that wraps it.
|
|
15
|
+
*
|
|
16
|
+
* @param state Current composite state.
|
|
17
|
+
* @param action Action to apply.
|
|
18
|
+
* @return Next composite state.
|
|
19
|
+
*/
|
|
11
20
|
function mediaEditorReducer(state, action) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
21
|
+
switch (action.type) {
|
|
22
|
+
case "CROPPER": {
|
|
23
|
+
const nextCropper = cropperReducer(state.cropper, action.action);
|
|
24
|
+
if (nextCropper === state.cropper) return state;
|
|
25
|
+
return {
|
|
26
|
+
...state,
|
|
27
|
+
cropper: nextCropper
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case "SET_ASPECT_RATIO_VALUE": {
|
|
31
|
+
const { presetKey, resolved, visualSize } = action.payload;
|
|
32
|
+
const shouldReshape = resolved !== void 0 && resolved > 0 && visualSize.width > 0 && visualSize.height > 0;
|
|
33
|
+
const nextCropOptions = {
|
|
34
|
+
...state.cropOptions,
|
|
35
|
+
aspectRatioValue: presetKey
|
|
36
|
+
};
|
|
37
|
+
if (!shouldReshape) {
|
|
38
|
+
if (state.cropOptions.aspectRatioValue === presetKey) return state;
|
|
39
|
+
return {
|
|
40
|
+
...state,
|
|
41
|
+
cropOptions: nextCropOptions
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const newCropRect = computeInscribedRect(resolved, visualSize);
|
|
45
|
+
const nextCropper = cropperReducer(state.cropper, {
|
|
46
|
+
type: "SET_CROP_RECT",
|
|
47
|
+
payload: newCropRect
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
51
|
+
cropper: nextCropper,
|
|
52
|
+
cropOptions: nextCropOptions
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
case "RESET": {
|
|
56
|
+
const next = buildInitialMediaEditorState(cropperReducer(state.cropper, { type: "RESET" }));
|
|
57
|
+
return areMediaEditorStatesEqual(state, next) ? state : next;
|
|
58
|
+
}
|
|
59
|
+
case "SET_EDIT": {
|
|
60
|
+
const { name, value } = action.payload;
|
|
61
|
+
if (value === void 0) {
|
|
62
|
+
if (!Object.hasOwn(state.edits, name)) return state;
|
|
63
|
+
const edits = { ...state.edits };
|
|
64
|
+
delete edits[name];
|
|
65
|
+
return {
|
|
66
|
+
...state,
|
|
67
|
+
edits
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (fastDeepEqual(state.edits[name], value)) return state;
|
|
71
|
+
return {
|
|
72
|
+
...state,
|
|
73
|
+
edits: {
|
|
74
|
+
...state.edits,
|
|
75
|
+
[name]: value
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
case "RESTORE_SNAPSHOT": return action.payload;
|
|
80
|
+
case "VIEWPORT_ADJUST_CROP_RECT": {
|
|
81
|
+
const nextCropper = cropperReducer(state.cropper, {
|
|
82
|
+
type: "SET_CROP_RECT",
|
|
83
|
+
payload: action.payload
|
|
84
|
+
});
|
|
85
|
+
if (nextCropper === state.cropper) return state;
|
|
86
|
+
return {
|
|
87
|
+
...state,
|
|
88
|
+
cropper: nextCropper
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
78
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Value-equality check for two composite states. Used by the history
|
|
95
|
+
* machinery to dedup snapshots when an action turned out to be a no-op.
|
|
96
|
+
*
|
|
97
|
+
* @param a First composite state.
|
|
98
|
+
* @param b Second composite state.
|
|
99
|
+
* @return Whether `a` and `b` are value-equal across all slices.
|
|
100
|
+
*/
|
|
79
101
|
function areMediaEditorStatesEqual(a, b) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
return areCropperStatesEqual(a.cropper, b.cropper) && a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue && fastDeepEqual(a.edits, b.edits);
|
|
102
|
+
if (a === b) return true;
|
|
103
|
+
return areCropperStatesEqual(a.cropper, b.cropper) && a.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue && fastDeepEqual(a.edits, b.edits);
|
|
84
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Build the composite state a session starts from: the given cropper
|
|
107
|
+
* slice, default crop options, and no edits.
|
|
108
|
+
*
|
|
109
|
+
* @param cropper The cropper slice.
|
|
110
|
+
* @return Composite initial state.
|
|
111
|
+
*/
|
|
85
112
|
function buildInitialMediaEditorState(cropper) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
113
|
+
return {
|
|
114
|
+
cropper,
|
|
115
|
+
cropOptions: { ...DEFAULT_CROP_OPTIONS },
|
|
116
|
+
edits: {}
|
|
117
|
+
};
|
|
91
118
|
}
|
|
92
|
-
export {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
mediaEditorReducer
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=composite-reducer.mjs.map
|
|
119
|
+
export { areMediaEditorStatesEqual, buildInitialMediaEditorState, mediaEditorReducer };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=composite-reducer.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/state/composite-reducer.ts"],
|
|
4
|
-
"sourcesContent": ["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport {\n\tcropperReducer,\n\tareCropperStatesEqual,\n\tcomputeInscribedRect,\n\ttype CropperState,\n} from '../image-editor';\nimport {\n\tDEFAULT_CROP_OPTIONS,\n\ttype CropOptionsSlice,\n\ttype MediaEditorAction,\n\ttype MediaEditorState,\n} from './types';\n\n/**\n * Pure composite reducer for the media editor.\n *\n * Delegates `CROPPER`-tagged actions to the framework-agnostic\n * `cropperReducer` and owns first-class transitions for the sidebar\n * `cropOptions` slice. `RESTORE_SNAPSHOT` replaces the whole composite\n * in one transaction (used by undo/redo).\n *\n * Note: this reducer carries NO history of its own. Snapshots and\n * stacks live in the `useMediaEditorState` hook that wraps it.\n *\n * @param state Current composite state.\n * @param action Action to apply.\n * @return Next composite state.\n */\nexport function mediaEditorReducer(\n\tstate: MediaEditorState,\n\taction: MediaEditorAction\n): MediaEditorState {\n\tswitch ( action.type ) {\n\t\tcase 'CROPPER': {\n\t\t\tconst nextCropper = cropperReducer( state.cropper, action.action );\n\t\t\tif ( nextCropper === state.cropper ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, cropper: nextCropper };\n\t\t}\n\t\tcase 'SET_ASPECT_RATIO_VALUE': {\n\t\t\tconst { presetKey, resolved, visualSize } = action.payload;\n\t\t\t// Atomically: update the preset key AND reshape the\n\t\t\t// cropRect (when the ratio is non-Free and we have a\n\t\t\t// visualSize). One transaction = one undo entry.\n\t\t\tconst shouldReshape =\n\t\t\t\tresolved !== undefined &&\n\t\t\t\tresolved > 0 &&\n\t\t\t\tvisualSize.width > 0 &&\n\t\t\t\tvisualSize.height > 0;\n\t\t\tconst nextCropOptions: CropOptionsSlice = {\n\t\t\t\t...state.cropOptions,\n\t\t\t\taspectRatioValue: presetKey,\n\t\t\t};\n\t\t\tif ( ! shouldReshape ) {\n\t\t\t\tif ( state.cropOptions.aspectRatioValue === presetKey ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\treturn { ...state, cropOptions: nextCropOptions };\n\t\t\t}\n\t\t\tconst newCropRect = computeInscribedRect( resolved, visualSize );\n\t\t\tconst nextCropper = cropperReducer( state.cropper, {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: newCropRect,\n\t\t\t} );\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tcropper: nextCropper,\n\t\t\t\tcropOptions: nextCropOptions,\n\t\t\t};\n\t\t}\n\t\tcase 'RESET': {\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcropperReducer( state.cropper, { type: 'RESET' } )\n\t\t\t);\n\t\t\treturn areMediaEditorStatesEqual( state, next ) ? state : next;\n\t\t}\n\t\tcase 'SET_EDIT': {\n\t\t\tconst { name, value } = action.payload;\n\t\t\tif ( value === undefined ) {\n\t\t\t\tif ( ! Object.hasOwn( state.edits, name ) ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\tconst edits = { ...state.edits };\n\t\t\t\tdelete edits[ name ];\n\t\t\t\treturn { ...state, edits };\n\t\t\t}\n\t\t\tif ( fastDeepEqual( state.edits[ name ], value ) ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, edits: { ...state.edits, [ name ]: value } };\n\t\t}\n\t\tcase 'RESTORE_SNAPSHOT':\n\t\t\treturn action.payload;\n\t\tcase 'VIEWPORT_ADJUST_CROP_RECT': {\n\t\t\tconst nextCropper = cropperReducer( state.cropper, {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: action.payload,\n\t\t\t} );\n\t\t\tif ( nextCropper === state.cropper ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, cropper: nextCropper };\n\t\t}\n\t}\n}\n\n/**\n * Value-equality check for two composite states. Used by the history\n * machinery to dedup snapshots when an action turned out to be a no-op.\n *\n * @param a First composite state.\n * @param b Second composite state.\n * @return Whether `a` and `b` are value-equal across all slices.\n */\nexport function areMediaEditorStatesEqual(\n\ta: MediaEditorState,\n\tb: MediaEditorState\n): boolean {\n\tif ( a === b ) {\n\t\treturn true;\n\t}\n\treturn (\n\t\tareCropperStatesEqual( a.cropper, b.cropper ) &&\n\t\ta.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&\n\t\tfastDeepEqual( a.edits, b.edits )\n\t);\n}\n\n/**\n * Build the composite state a session starts from: the given cropper\n * slice, default crop options, and no edits.\n *\n * @param cropper The cropper slice.\n * @return Composite initial state.\n */\nexport function buildInitialMediaEditorState(\n\tcropper: CropperState\n): MediaEditorState {\n\treturn {\n\t\tcropper,\n\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS },\n\t\tedits: {},\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,mBAAmB;AAC1B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,OAIM;AAiBA,SAAS,mBACf,OACA,QACmB;AACnB,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,WAAW;AACf,YAAM,cAAc,eAAgB,MAAM,SAAS,OAAO,MAAO;AACjE,UAAK,gBAAgB,MAAM,SAAU;AACpC,eAAO;AAAA,MACR;AACA,aAAO,EAAE,GAAG,OAAO,SAAS,YAAY;AAAA,IACzC;AAAA,IACA,KAAK,0BAA0B;AAC9B,YAAM,EAAE,WAAW,UAAU,WAAW,IAAI,OAAO;AAInD,YAAM,gBACL,aAAa,UACb,WAAW,KACX,WAAW,QAAQ,KACnB,WAAW,SAAS;AACrB,YAAM,kBAAoC;AAAA,QACzC,GAAG,MAAM;AAAA,QACT,kBAAkB;AAAA,MACnB;AACA,UAAK,CAAE,eAAgB;AACtB,YAAK,MAAM,YAAY,qBAAqB,WAAY;AACvD,iBAAO;AAAA,QACR;AACA,eAAO,EAAE,GAAG,OAAO,aAAa,gBAAgB;AAAA,MACjD;AACA,YAAM,cAAc,qBAAsB,UAAU,UAAW;AAC/D,YAAM,cAAc,eAAgB,MAAM,SAAS;AAAA,QAClD,MAAM;AAAA,QACN,SAAS;AAAA,MACV,CAAE;AACF,aAAO;AAAA,QACN,GAAG;AAAA,QACH,SAAS;AAAA,QACT,aAAa;AAAA,MACd;AAAA,IACD;AAAA,IACA,KAAK,SAAS;AACb,YAAM,OAAO;AAAA,QACZ,eAAgB,MAAM,SAAS,EAAE,MAAM,QAAQ,CAAE;AAAA,MAClD;AACA,aAAO,0BAA2B,OAAO,IAAK,IAAI,QAAQ;AAAA,IAC3D;AAAA,IACA,KAAK,YAAY;AAChB,YAAM,EAAE,MAAM,MAAM,IAAI,OAAO;AAC/B,UAAK,UAAU,QAAY;AAC1B,YAAK,CAAE,OAAO,OAAQ,MAAM,OAAO,IAAK,GAAI;AAC3C,iBAAO;AAAA,QACR;AACA,cAAM,QAAQ,EAAE,GAAG,MAAM,MAAM;AAC/B,eAAO,MAAO,IAAK;AACnB,eAAO,EAAE,GAAG,OAAO,MAAM;AAAA,MAC1B;AACA,UAAK,cAAe,MAAM,MAAO,IAAK,GAAG,KAAM,GAAI;AAClD,eAAO;AAAA,MACR;AACA,aAAO,EAAE,GAAG,OAAO,OAAO,EAAE,GAAG,MAAM,OAAO,CAAE,IAAK,GAAG,MAAM,EAAE;AAAA,IAC/D;AAAA,IACA,KAAK;AACJ,aAAO,OAAO;AAAA,IACf,KAAK,6BAA6B;AACjC,YAAM,cAAc,eAAgB,MAAM,SAAS;AAAA,QAClD,MAAM;AAAA,QACN,SAAS,OAAO;AAAA,MACjB,CAAE;AACF,UAAK,gBAAgB,MAAM,SAAU;AACpC,eAAO;AAAA,MACR;AACA,aAAO,EAAE,GAAG,OAAO,SAAS,YAAY;AAAA,IACzC;AAAA,EACD;AACD;AAUO,SAAS,0BACf,GACA,GACU;AACV,MAAK,MAAM,GAAI;AACd,WAAO;AAAA,EACR;AACA,SACC,sBAAuB,EAAE,SAAS,EAAE,OAAQ,KAC5C,EAAE,YAAY,qBAAqB,EAAE,YAAY,oBACjD,cAAe,EAAE,OAAO,EAAE,KAAM;AAElC;AASO,SAAS,6BACf,SACmB;AACnB,SAAO;AAAA,IACN;AAAA,IACA,aAAa,EAAE,GAAG,qBAAqB;AAAA,IACvC,OAAO,CAAC;AAAA,EACT;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"composite-reducer.mjs","names":[],"sources":["../../src/state/composite-reducer.ts"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport type { CropperState } from '../image-editor';\nimport {\n\tcropperReducer,\n\tareCropperStatesEqual,\n\tcomputeInscribedRect,\n} from '../image-editor/core';\nimport {\n\tDEFAULT_CROP_OPTIONS,\n\ttype CropOptionsSlice,\n\ttype MediaEditorAction,\n\ttype MediaEditorState,\n} from './types';\n\n/**\n * Pure composite reducer for the media editor.\n *\n * Delegates `CROPPER`-tagged actions to the framework-agnostic\n * `cropperReducer` and owns first-class transitions for the sidebar\n * `cropOptions` slice. `RESTORE_SNAPSHOT` replaces the whole composite\n * in one transaction (used by undo/redo).\n *\n * Note: this reducer carries NO history of its own. Snapshots and\n * stacks live in the `useMediaEditorState` hook that wraps it.\n *\n * @param state Current composite state.\n * @param action Action to apply.\n * @return Next composite state.\n */\nexport function mediaEditorReducer(\n\tstate: MediaEditorState,\n\taction: MediaEditorAction\n): MediaEditorState {\n\tswitch ( action.type ) {\n\t\tcase 'CROPPER': {\n\t\t\tconst nextCropper = cropperReducer( state.cropper, action.action );\n\t\t\tif ( nextCropper === state.cropper ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, cropper: nextCropper };\n\t\t}\n\t\tcase 'SET_ASPECT_RATIO_VALUE': {\n\t\t\tconst { presetKey, resolved, visualSize } = action.payload;\n\t\t\t// Atomically: update the preset key AND reshape the\n\t\t\t// cropRect (when the ratio is non-Free and we have a\n\t\t\t// visualSize). One transaction = one undo entry.\n\t\t\tconst shouldReshape =\n\t\t\t\tresolved !== undefined &&\n\t\t\t\tresolved > 0 &&\n\t\t\t\tvisualSize.width > 0 &&\n\t\t\t\tvisualSize.height > 0;\n\t\t\tconst nextCropOptions: CropOptionsSlice = {\n\t\t\t\t...state.cropOptions,\n\t\t\t\taspectRatioValue: presetKey,\n\t\t\t};\n\t\t\tif ( ! shouldReshape ) {\n\t\t\t\tif ( state.cropOptions.aspectRatioValue === presetKey ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\treturn { ...state, cropOptions: nextCropOptions };\n\t\t\t}\n\t\t\tconst newCropRect = computeInscribedRect( resolved, visualSize );\n\t\t\tconst nextCropper = cropperReducer( state.cropper, {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: newCropRect,\n\t\t\t} );\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tcropper: nextCropper,\n\t\t\t\tcropOptions: nextCropOptions,\n\t\t\t};\n\t\t}\n\t\tcase 'RESET': {\n\t\t\tconst next = buildInitialMediaEditorState(\n\t\t\t\tcropperReducer( state.cropper, { type: 'RESET' } )\n\t\t\t);\n\t\t\treturn areMediaEditorStatesEqual( state, next ) ? state : next;\n\t\t}\n\t\tcase 'SET_EDIT': {\n\t\t\tconst { name, value } = action.payload;\n\t\t\tif ( value === undefined ) {\n\t\t\t\tif ( ! Object.hasOwn( state.edits, name ) ) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\t\t\t\tconst edits = { ...state.edits };\n\t\t\t\tdelete edits[ name ];\n\t\t\t\treturn { ...state, edits };\n\t\t\t}\n\t\t\tif ( fastDeepEqual( state.edits[ name ], value ) ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, edits: { ...state.edits, [ name ]: value } };\n\t\t}\n\t\tcase 'RESTORE_SNAPSHOT':\n\t\t\treturn action.payload;\n\t\tcase 'VIEWPORT_ADJUST_CROP_RECT': {\n\t\t\tconst nextCropper = cropperReducer( state.cropper, {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: action.payload,\n\t\t\t} );\n\t\t\tif ( nextCropper === state.cropper ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn { ...state, cropper: nextCropper };\n\t\t}\n\t}\n}\n\n/**\n * Value-equality check for two composite states. Used by the history\n * machinery to dedup snapshots when an action turned out to be a no-op.\n *\n * @param a First composite state.\n * @param b Second composite state.\n * @return Whether `a` and `b` are value-equal across all slices.\n */\nexport function areMediaEditorStatesEqual(\n\ta: MediaEditorState,\n\tb: MediaEditorState\n): boolean {\n\tif ( a === b ) {\n\t\treturn true;\n\t}\n\treturn (\n\t\tareCropperStatesEqual( a.cropper, b.cropper ) &&\n\t\ta.cropOptions.aspectRatioValue === b.cropOptions.aspectRatioValue &&\n\t\tfastDeepEqual( a.edits, b.edits )\n\t);\n}\n\n/**\n * Build the composite state a session starts from: the given cropper\n * slice, default crop options, and no edits.\n *\n * @param cropper The cropper slice.\n * @return Composite initial state.\n */\nexport function buildInitialMediaEditorState(\n\tcropper: CropperState\n): MediaEditorState {\n\treturn {\n\t\tcropper,\n\t\tcropOptions: { ...DEFAULT_CROP_OPTIONS },\n\t\tedits: {},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,mBACf,OACA,QACmB;CACnB,QAAS,OAAO,MAAhB;EACC,KAAK,WAAW;GACf,MAAM,cAAc,eAAgB,MAAM,SAAS,OAAO,MAAO;GACjE,IAAK,gBAAgB,MAAM,SAC1B,OAAO;GAER,OAAO;IAAE,GAAG;IAAO,SAAS;GAAY;EACzC;EACA,KAAK,0BAA0B;GAC9B,MAAM,EAAE,WAAW,UAAU,eAAe,OAAO;GAInD,MAAM,gBACL,aAAa,KAAA,KACb,WAAW,KACX,WAAW,QAAQ,KACnB,WAAW,SAAS;GACrB,MAAM,kBAAoC;IACzC,GAAG,MAAM;IACT,kBAAkB;GACnB;GACA,IAAK,CAAE,eAAgB;IACtB,IAAK,MAAM,YAAY,qBAAqB,WAC3C,OAAO;IAER,OAAO;KAAE,GAAG;KAAO,aAAa;IAAgB;GACjD;GACA,MAAM,cAAc,qBAAsB,UAAU,UAAW;GAC/D,MAAM,cAAc,eAAgB,MAAM,SAAS;IAClD,MAAM;IACN,SAAS;GACV,CAAE;GACF,OAAO;IACN,GAAG;IACH,SAAS;IACT,aAAa;GACd;EACD;EACA,KAAK,SAAS;GACb,MAAM,OAAO,6BACZ,eAAgB,MAAM,SAAS,EAAE,MAAM,QAAQ,CAAE,CAClD;GACA,OAAO,0BAA2B,OAAO,IAAK,IAAI,QAAQ;EAC3D;EACA,KAAK,YAAY;GAChB,MAAM,EAAE,MAAM,UAAU,OAAO;GAC/B,IAAK,UAAU,KAAA,GAAY;IAC1B,IAAK,CAAE,OAAO,OAAQ,MAAM,OAAO,IAAK,GACvC,OAAO;IAER,MAAM,QAAQ,EAAE,GAAG,MAAM,MAAM;IAC/B,OAAO,MAAO;IACd,OAAO;KAAE,GAAG;KAAO;IAAM;GAC1B;GACA,IAAK,cAAe,MAAM,MAAO,OAAQ,KAAM,GAC9C,OAAO;GAER,OAAO;IAAE,GAAG;IAAO,OAAO;KAAE,GAAG,MAAM;MAAS,OAAQ;IAAM;GAAE;EAC/D;EACA,KAAK,oBACJ,OAAO,OAAO;EACf,KAAK,6BAA6B;GACjC,MAAM,cAAc,eAAgB,MAAM,SAAS;IAClD,MAAM;IACN,SAAS,OAAO;GACjB,CAAE;GACF,IAAK,gBAAgB,MAAM,SAC1B,OAAO;GAER,OAAO;IAAE,GAAG;IAAO,SAAS;GAAY;EACzC;CACD;AACD;;;;;;;;;AAUA,SAAgB,0BACf,GACA,GACU;CACV,IAAK,MAAM,GACV,OAAO;CAER,OACC,sBAAuB,EAAE,SAAS,EAAE,OAAQ,KAC5C,EAAE,YAAY,qBAAqB,EAAE,YAAY,oBACjD,cAAe,EAAE,OAAO,EAAE,KAAM;AAElC;;;;;;;;AASA,SAAgB,6BACf,SACmB;CACnB,OAAO;EACN;EACA,aAAa,EAAE,GAAG,qBAAqB;EACvC,OAAO,CAAC;CACT;AACD"}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
resolveAspectRatio
|
|
5
|
-
} from "./use-media-editor-state.mjs";
|
|
6
|
-
import {
|
|
7
|
-
MediaEditorStateProvider,
|
|
8
|
-
useMediaEditor
|
|
9
|
-
} from "./media-editor-state-provider.mjs";
|
|
10
|
-
import {
|
|
11
|
-
mediaEditorReducer,
|
|
12
|
-
areMediaEditorStatesEqual,
|
|
13
|
-
buildInitialMediaEditorState
|
|
14
|
-
} from "./composite-reducer.mjs";
|
|
1
|
+
import { resolveAspectRatio, useMediaEditorState } from "./use-media-editor-state.mjs";
|
|
2
|
+
import { MediaEditorStateProvider, useMediaEditor } from "./media-editor-state-provider.mjs";
|
|
3
|
+
import { areMediaEditorStatesEqual, buildInitialMediaEditorState, mediaEditorReducer } from "./composite-reducer.mjs";
|
|
15
4
|
import { DEFAULT_CROP_OPTIONS } from "./types.mjs";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
MediaEditorStateProvider,
|
|
19
|
-
areMediaEditorStatesEqual,
|
|
20
|
-
buildInitialMediaEditorState,
|
|
21
|
-
mediaEditorReducer,
|
|
22
|
-
resolveAspectRatio,
|
|
23
|
-
useMediaEditor,
|
|
24
|
-
useMediaEditorState
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=index.mjs.map
|
|
5
|
+
import { DEFAULT_ASPECT_RATIOS } from "./aspect-ratio-presets.mjs";
|
|
6
|
+
export { DEFAULT_ASPECT_RATIOS, DEFAULT_CROP_OPTIONS, MediaEditorStateProvider, areMediaEditorStatesEqual, buildInitialMediaEditorState, mediaEditorReducer, resolveAspectRatio, useMediaEditor, useMediaEditorState };
|
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
// packages/media-editor/src/state/media-editor-state-provider.tsx
|
|
2
1
|
import { createContext, useContext } from "@wordpress/element";
|
|
3
|
-
import {
|
|
4
|
-
useMediaEditorState
|
|
5
|
-
} from "./use-media-editor-state.mjs";
|
|
2
|
+
import { useMediaEditorState } from "./use-media-editor-state.mjs";
|
|
6
3
|
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
// packages/media-editor/src/state/media-editor-state-provider.tsx
|
|
5
|
+
const MediaEditorStateContext = createContext(null);
|
|
6
|
+
/**
|
|
7
|
+
* Provider that vends the media editor session via context. Wrap
|
|
8
|
+
* the media editor in this so every consumer (canvas, toolbar,
|
|
9
|
+
* sidebar) reads from the same store.
|
|
10
|
+
*
|
|
11
|
+
* @param props
|
|
12
|
+
* @param props.children
|
|
13
|
+
*/
|
|
14
|
+
function MediaEditorStateProvider({ children }) {
|
|
15
|
+
const controller = useMediaEditorState();
|
|
16
|
+
return /* @__PURE__ */ jsx(MediaEditorStateContext.Provider, {
|
|
17
|
+
value: controller,
|
|
18
|
+
children
|
|
19
|
+
});
|
|
15
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Consume the media editor session. Throws if used
|
|
23
|
+
* outside a `<MediaEditorStateProvider>`.
|
|
24
|
+
*
|
|
25
|
+
* @return The media editor session.
|
|
26
|
+
*/
|
|
16
27
|
function useMediaEditor() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"useMediaEditor must be used within a MediaEditorStateProvider."
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return context;
|
|
28
|
+
const context = useContext(MediaEditorStateContext);
|
|
29
|
+
if (!context) throw new Error("useMediaEditor must be used within a MediaEditorStateProvider.");
|
|
30
|
+
return context;
|
|
24
31
|
}
|
|
25
|
-
export {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=media-editor-state-provider.mjs.map
|
|
32
|
+
export { MediaEditorStateProvider, useMediaEditor };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=media-editor-state-provider.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/state/media-editor-state-provider.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseMediaEditorState,\n\ttype MediaEditorSession,\n} from './use-media-editor-state';\n\nconst MediaEditorStateContext = createContext< MediaEditorSession | null >(\n\tnull\n);\n\ninterface MediaEditorStateProviderProps {\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Provider that vends the media editor session via context. Wrap\n * the media editor in this so every consumer (canvas, toolbar,\n * sidebar) reads from the same store.\n *\n * @param props\n * @param props.children\n */\nexport function MediaEditorStateProvider( {\n\tchildren,\n}: MediaEditorStateProviderProps ) {\n\tconst controller = useMediaEditorState();\n\n\treturn (\n\t\t<MediaEditorStateContext.Provider value={ controller }>\n\t\t\t{ children }\n\t\t</MediaEditorStateContext.Provider>\n\t);\n}\n\n/**\n * Consume the media editor session. Throws if used\n * outside a `<MediaEditorStateProvider>`.\n *\n * @return The media editor session.\n */\nexport function useMediaEditor(): MediaEditorSession {\n\tconst context = useContext( MediaEditorStateContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditor must be used within a MediaEditorStateProvider.'\n\t\t);\n\t}\n\treturn context;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,eAAe,kBAAkB;AAC1C;AAAA,EACC;AAAA,OAEM;AAyBL;AAvBF,IAAM,0BAA0B;AAAA,EAC/B;AACD;AAeO,SAAS,yBAA0B;AAAA,EACzC;AACD,GAAmC;AAClC,QAAM,aAAa,oBAAoB;AAEvC,SACC,oBAAC,wBAAwB,UAAxB,EAAiC,OAAQ,YACvC,UACH;AAEF;AAQO,SAAS,iBAAqC;AACpD,QAAM,UAAU,WAAY,uBAAwB;AACpD,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"media-editor-state-provider.mjs","names":[],"sources":["../../src/state/media-editor-state-provider.tsx"],"sourcesContent":["import { createContext, useContext } from '@wordpress/element';\nimport {\n\tuseMediaEditorState,\n\ttype MediaEditorSession,\n} from './use-media-editor-state';\n\nconst MediaEditorStateContext = createContext< MediaEditorSession | null >(\n\tnull\n);\n\ninterface MediaEditorStateProviderProps {\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Provider that vends the media editor session via context. Wrap\n * the media editor in this so every consumer (canvas, toolbar,\n * sidebar) reads from the same store.\n *\n * @param props\n * @param props.children\n */\nexport function MediaEditorStateProvider( {\n\tchildren,\n}: MediaEditorStateProviderProps ) {\n\tconst controller = useMediaEditorState();\n\n\treturn (\n\t\t<MediaEditorStateContext.Provider value={ controller }>\n\t\t\t{ children }\n\t\t</MediaEditorStateContext.Provider>\n\t);\n}\n\n/**\n * Consume the media editor session. Throws if used\n * outside a `<MediaEditorStateProvider>`.\n *\n * @return The media editor session.\n */\nexport function useMediaEditor(): MediaEditorSession {\n\tconst context = useContext( MediaEditorStateContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'useMediaEditor must be used within a MediaEditorStateProvider.'\n\t\t);\n\t}\n\treturn context;\n}\n"],"mappings":";;;;AAMA,MAAM,0BAA0B,cAC/B,IACD;;;;;;;;;AAeA,SAAgB,yBAA0B,EACzC,YACkC;CAClC,MAAM,aAAa,oBAAoB;CAEvC,OACC,oBAAC,wBAAwB,UAAzB;EAAkC,OAAQ;EACvC;CAC+B,CAAA;AAEpC;;;;;;;AAQA,SAAgB,iBAAqC;CACpD,MAAM,UAAU,WAAY,uBAAwB;CACpD,IAAK,CAAE,SACN,MAAM,IAAI,MACT,gEACD;CAED,OAAO;AACR"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// packages/media-editor/src/state/types.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Default values for the crop-options slice. Mirrors the initial state
|
|
4
|
+
* used by the sidebar before the user has touched anything.
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_CROP_OPTIONS = { aspectRatioValue: "0" };
|
|
7
|
+
export { DEFAULT_CROP_OPTIONS };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/state/types.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n\tCropperAction,\n\tCropperState,\n\tNormalizedRect,\n\tSize,\n} from '../image-editor';\n\n/**\n * Sidebar control state for the cropper. Lives in the composite store\n * so it participates in the same undo history as cropper geometry.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * Default values for the crop-options slice. Mirrors the initial state\n * used by the sidebar before the user has touched anything.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * A value an edit can hold: plain data only, because the session\n * compares values by content to tell a real change from a no-op.\n * Anything else, such as a `Blob`, would compare equal to any other\n * and the change would be dropped — keep bytes behind a URL instead.\n *\n * Objects must satisfy the index signature, so type a value with a\n * `type` alias rather than an `interface`.\n */\nexport type EditValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| EditValue[]\n\t| { [ key: string ]: EditValue };\n\n/**\n * Named edits other than crop, keyed by edit name (for example\n * `my-plugin/vignette`). An edit that is not present means \"no edit\".\n */\nexport type EditsSlice = Record< string, EditValue >;\n\n/**\n * The full composite state for the media editor — cropper geometry,\n * the sidebar control slice, and named edits.\n *\n * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay\n * referentially equal across actions that don't touch them.\n */\nexport interface MediaEditorState {\n\tcropper: CropperState;\n\tcropOptions: CropOptionsSlice;\n\tedits: EditsSlice;\n}\n\n/**\n * Composite reducer action union.\n *\n * Cropper geometry actions are wrapped in a `CROPPER` envelope and\n * delegated to the pure `cropperReducer`. Sidebar and history\n * concerns are first-class actions on this reducer.\n */\nexport type MediaEditorAction =\n\t/**\n\t * Delegate to the underlying cropper reducer. Used for every\n\t * geometry transition (pan / zoom / rotation / flip / cropRect /\n\t * settle / etc.).\n\t */\n\t| {\n\t\t\ttype: 'CROPPER';\n\t\t\taction: CropperAction;\n\t }\n\t/**\n\t * Set the aspect-ratio preset. Atomically updates the preset key\n\t * and the cropRect (computed from the resolved ratio and the\n\t * current visualSize). One transaction = one undo entry.\n\t */\n\t| {\n\t\t\ttype: 'SET_ASPECT_RATIO_VALUE';\n\t\t\tpayload: {\n\t\t\t\t/** Preset key as it appears in the dropdown. */\n\t\t\t\tpresetKey: string;\n\t\t\t\t/**\n\t\t\t\t * Resolved width/height ratio. `undefined` = Free\n\t\t\t\t * (no lock; cropRect stays where it is).\n\t\t\t\t */\n\t\t\t\tresolved: number | undefined;\n\t\t\t\t/**\n\t\t\t\t * Rendered image size used to compute the inscribed\n\t\t\t\t * rect. Caller supplies it because the reducer is\n\t\t\t\t * framework-agnostic and has no DOM access.\n\t\t\t\t */\n\t\t\t\tvisualSize: Size;\n\t\t\t};\n\t }\n\t/**\n\t * Put every slice back to its starting state, keeping the image:\n\t * default geometry, default crop options, no edits. One action,\n\t * so one undo entry.\n\t */\n\t| { type: 'RESET' }\n\t/** Set a named edit, or remove it when `value` is `undefined`. */\n\t| {\n\t\t\ttype: 'SET_EDIT';\n\t\t\tpayload: { name: string; value: EditValue | undefined };\n\t }\n\t/**\n\t * Replace the entire composite state with `payload`. Used by\n\t * undo/redo to restore a full snapshot atomically.\n\t */\n\t| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState }\n\t/**\n\t * Adjust the cropper's cropRect in response to a viewport change\n\t * (e.g., window resize). Behaviorally identical to a `CROPPER\n\t * SET_CROP_RECT` dispatch, but tagged so the hook layer can skip\n\t * history recording — viewport reshapes aren't editor actions.\n\t */\n\t| {\n\t\t\ttype: 'VIEWPORT_ADJUST_CROP_RECT';\n\t\t\tpayload: NormalizedRect;\n\t };\n"],
|
|
5
|
-
"mappings": ";AAwBO,IAAM,uBAAyC;AAAA,EACrD,kBAAkB;AACnB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/state/types.ts"],"sourcesContent":["import type { CropperState, NormalizedRect, Size } from '../image-editor';\nimport type { CropperAction } from '../image-editor/core';\n\n/**\n * Sidebar control state for the cropper. Lives in the composite store\n * so it participates in the same undo history as cropper geometry.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * Default values for the crop-options slice. Mirrors the initial state\n * used by the sidebar before the user has touched anything.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * A value an edit can hold: plain data only, because the session\n * compares values by content to tell a real change from a no-op.\n * Anything else, such as a `Blob`, would compare equal to any other\n * and the change would be dropped — keep bytes behind a URL instead.\n *\n * Objects must satisfy the index signature, so type a value with a\n * `type` alias rather than an `interface`.\n */\nexport type EditValue =\n\t| string\n\t| number\n\t| boolean\n\t| null\n\t| EditValue[]\n\t| { [ key: string ]: EditValue };\n\n/**\n * Named edits other than crop, keyed by edit name (for example\n * `my-plugin/vignette`). An edit that is not present means \"no edit\".\n */\nexport type EditsSlice = Record< string, EditValue >;\n\n/**\n * The full composite state for the media editor — cropper geometry,\n * the sidebar control slice, and named edits.\n *\n * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay\n * referentially equal across actions that don't touch them.\n */\nexport interface MediaEditorState {\n\tcropper: CropperState;\n\tcropOptions: CropOptionsSlice;\n\tedits: EditsSlice;\n}\n\n/**\n * Composite reducer action union.\n *\n * Cropper geometry actions are wrapped in a `CROPPER` envelope and\n * delegated to the pure `cropperReducer`. Sidebar and history\n * concerns are first-class actions on this reducer.\n */\nexport type MediaEditorAction =\n\t/**\n\t * Delegate to the underlying cropper reducer. Used for every\n\t * geometry transition (pan / zoom / rotation / flip / cropRect /\n\t * settle / etc.).\n\t */\n\t| {\n\t\t\ttype: 'CROPPER';\n\t\t\taction: CropperAction;\n\t }\n\t/**\n\t * Set the aspect-ratio preset. Atomically updates the preset key\n\t * and the cropRect (computed from the resolved ratio and the\n\t * current visualSize). One transaction = one undo entry.\n\t */\n\t| {\n\t\t\ttype: 'SET_ASPECT_RATIO_VALUE';\n\t\t\tpayload: {\n\t\t\t\t/** Preset key as it appears in the dropdown. */\n\t\t\t\tpresetKey: string;\n\t\t\t\t/**\n\t\t\t\t * Resolved width/height ratio. `undefined` = Free\n\t\t\t\t * (no lock; cropRect stays where it is).\n\t\t\t\t */\n\t\t\t\tresolved: number | undefined;\n\t\t\t\t/**\n\t\t\t\t * Rendered image size used to compute the inscribed\n\t\t\t\t * rect. Caller supplies it because the reducer is\n\t\t\t\t * framework-agnostic and has no DOM access.\n\t\t\t\t */\n\t\t\t\tvisualSize: Size;\n\t\t\t};\n\t }\n\t/**\n\t * Put every slice back to its starting state, keeping the image:\n\t * default geometry, default crop options, no edits. One action,\n\t * so one undo entry.\n\t */\n\t| { type: 'RESET' }\n\t/** Set a named edit, or remove it when `value` is `undefined`. */\n\t| {\n\t\t\ttype: 'SET_EDIT';\n\t\t\tpayload: { name: string; value: EditValue | undefined };\n\t }\n\t/**\n\t * Replace the entire composite state with `payload`. Used by\n\t * undo/redo to restore a full snapshot atomically.\n\t */\n\t| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState }\n\t/**\n\t * Adjust the cropper's cropRect in response to a viewport change\n\t * (e.g., window resize). Behaviorally identical to a `CROPPER\n\t * SET_CROP_RECT` dispatch, but tagged so the hook layer can skip\n\t * history recording — viewport reshapes aren't editor actions.\n\t */\n\t| {\n\t\t\ttype: 'VIEWPORT_ADJUST_CROP_RECT';\n\t\t\tpayload: NormalizedRect;\n\t };\n"],"mappings":";;;;;AAoBA,MAAa,uBAAyC,EACrD,kBAAkB,IACnB"}
|