@wordpress/media-editor 0.21.0 → 0.23.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 +30 -0
- package/build/components/media-editor/index.cjs +586 -686
- package/build/components/media-editor/index.cjs.map +1 -7
- package/build/components/media-editor/use-crop-options.cjs +42 -57
- package/build/components/media-editor/use-crop-options.cjs.map +1 -7
- package/build/components/media-editor/use-save-media-editor.cjs +131 -185
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
- package/build/components/media-editor-canvas/index.cjs +117 -124
- package/build/components/media-editor-canvas/index.cjs.map +1 -7
- package/build/components/media-editor-crop-panel/index.cjs +81 -72
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
- package/build/components/media-editor-fine-rotation/index.cjs +61 -72
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
- package/build/components/media-editor-image-controls/index.cjs +181 -257
- package/build/components/media-editor-image-controls/index.cjs.map +1 -7
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
- package/build/components/media-editor-keyboard-shortcuts-modal/index.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 +82 -77
- package/build/components/media-form/index.cjs.map +1 -7
- package/build/components/media-preview/index.cjs +113 -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/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 +59 -0
- package/build/state/aspect-ratio-presets.cjs.map +1 -0
- package/build/state/composite-reducer.cjs +100 -113
- package/build/state/composite-reducer.cjs.map +1 -7
- package/build/state/index.cjs +22 -45
- 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 +11 -31
- package/build/state/types.cjs.map +1 -7
- package/build/state/use-media-editor-state.cjs +227 -296
- 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 +545 -675
- package/build-module/components/media-editor/index.mjs.map +1 -7
- package/build-module/components/media-editor/use-crop-options.mjs +37 -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 +109 -157
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
- package/build-module/components/media-editor-canvas/index.mjs +95 -98
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
- package/build-module/components/media-editor-crop-panel/index.mjs +59 -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 -46
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
- package/build-module/components/media-editor-image-controls/index.mjs +171 -238
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.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 +74 -56
- package/build-module/components/media-form/index.mjs.map +1 -7
- package/build-module/components/media-preview/index.mjs +105 -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/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 +53 -0
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
- package/build-module/state/composite-reducer.mjs +80 -91
- package/build-module/state/composite-reducer.mjs.map +1 -7
- package/build-module/state/index.mjs +3 -26
- 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 +7 -7
- package/build-module/state/types.mjs.map +1 -7
- package/build-module/state/use-media-editor-state.mjs +223 -288
- 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 +145 -61
- package/build-style/style.css +144 -61
- package/build-types/components/media-editor/index.d.ts +20 -2
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- 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 +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- 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/state/aspect-ratio-presets.d.ts +24 -0
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -4
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -63
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +33 -52
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/package.json +22 -23
- package/src/components/media-editor/index.tsx +355 -167
- package/src/components/media-editor/style.scss +19 -0
- package/src/components/media-editor/use-crop-options.ts +9 -10
- package/src/components/media-editor/use-save-media-editor.ts +48 -10
- package/src/components/media-editor-canvas/index.tsx +30 -51
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +15 -11
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +1 -1
- package/src/components/media-editor-modal/style.scss +1 -1
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +65 -23
- package/src/components/media-preview/style.scss +16 -2
- package/src/components/rotation-ruler/style.scss +9 -5
- package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
- package/src/state/README.md +32 -0
- package/src/state/aspect-ratio-presets.ts +37 -0
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -17
- package/src/state/types.ts +18 -72
- package/src/state/use-media-editor-state.ts +155 -238
- package/src/style.scss +2 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
- package/build/image-editor/core/camera.cjs +0 -225
- package/build/image-editor/core/camera.cjs.map +0 -7
- package/build/image-editor/core/constants.cjs +0 -108
- package/build/image-editor/core/constants.cjs.map +0 -7
- package/build/image-editor/core/containment.cjs +0 -276
- package/build/image-editor/core/containment.cjs.map +0 -7
- package/build/image-editor/core/crop-rect.cjs +0 -48
- package/build/image-editor/core/crop-rect.cjs.map +0 -7
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
- package/build/image-editor/core/index.cjs +0 -62
- package/build/image-editor/core/index.cjs.map +0 -7
- package/build/image-editor/core/interaction-controller.cjs +0 -654
- package/build/image-editor/core/interaction-controller.cjs.map +0 -7
- package/build/image-editor/core/math/rotation.cjs +0 -41
- package/build/image-editor/core/math/rotation.cjs.map +0 -7
- package/build/image-editor/core/math/sanitize.cjs +0 -92
- package/build/image-editor/core/math/sanitize.cjs.map +0 -7
- package/build/image-editor/core/setter-helpers.cjs +0 -64
- package/build/image-editor/core/setter-helpers.cjs.map +0 -7
- package/build/image-editor/core/source-region.cjs +0 -206
- package/build/image-editor/core/source-region.cjs.map +0 -7
- package/build/image-editor/core/state.cjs +0 -283
- package/build/image-editor/core/state.cjs.map +0 -7
- package/build/image-editor/core/stencil-math.cjs +0 -216
- package/build/image-editor/core/stencil-math.cjs.map +0 -7
- package/build/image-editor/core/transform-style.cjs +0 -52
- package/build/image-editor/core/transform-style.cjs.map +0 -7
- package/build/image-editor/core/transforms/pipeline.cjs +0 -43
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
- package/build/image-editor/core/types.cjs +0 -19
- package/build/image-editor/core/types.cjs.map +0 -7
- package/build/image-editor/core/viewport-state.cjs +0 -50
- package/build/image-editor/core/viewport-state.cjs.map +0 -7
- package/build/image-editor/index.cjs +0 -67
- package/build/image-editor/index.cjs.map +0 -7
- package/build/image-editor/react/components/cropper-provider.cjs +0 -50
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
- package/build/image-editor/react/components/cropper.cjs +0 -722
- package/build/image-editor/react/components/cropper.cjs.map +0 -7
- package/build/image-editor/react/components/index.cjs +0 -36
- package/build/image-editor/react/components/index.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
- package/build/image-editor/react/components/viewport-provider.cjs +0 -51
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
- package/build/image-editor/react/hooks/index.cjs +0 -34
- package/build/image-editor/react/hooks/index.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
- package/build/image-editor/react/hooks/use-aria-announcer.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/image-editor/react/hooks/use-interaction.cjs +0 -213
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
- package/build/image-editor/react/visually-hidden-style.cjs +0 -41
- package/build/image-editor/react/visually-hidden-style.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/components/media-editor-modal/build-modifiers.mjs +0 -66
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
- package/build-module/image-editor/core/camera.mjs +0 -198
- package/build-module/image-editor/core/camera.mjs.map +0 -7
- package/build-module/image-editor/core/constants.mjs +0 -69
- package/build-module/image-editor/core/constants.mjs.map +0 -7
- package/build-module/image-editor/core/containment.mjs +0 -253
- package/build-module/image-editor/core/containment.mjs.map +0 -7
- package/build-module/image-editor/core/crop-rect.mjs +0 -23
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
- package/build-module/image-editor/core/index.mjs +0 -36
- package/build-module/image-editor/core/index.mjs.map +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -635
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
- package/build-module/image-editor/core/math/rotation.mjs +0 -15
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
- package/build-module/image-editor/core/math/sanitize.mjs +0 -63
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
- package/build-module/image-editor/core/setter-helpers.mjs +0 -39
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
- package/build-module/image-editor/core/source-region.mjs +0 -178
- package/build-module/image-editor/core/source-region.mjs.map +0 -7
- package/build-module/image-editor/core/state.mjs +0 -260
- package/build-module/image-editor/core/state.mjs.map +0 -7
- package/build-module/image-editor/core/stencil-math.mjs +0 -187
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
- package/build-module/image-editor/core/transform-style.mjs +0 -27
- package/build-module/image-editor/core/transform-style.mjs.map +0 -7
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
- package/build-module/image-editor/core/types.mjs +0 -1
- package/build-module/image-editor/core/types.mjs.map +0 -7
- package/build-module/image-editor/core/viewport-state.mjs +0 -24
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
- package/build-module/image-editor/index.mjs +0 -39
- package/build-module/image-editor/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
- package/build-module/image-editor/react/components/cropper.mjs +0 -704
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
- package/build-module/image-editor/react/components/index.mjs +0 -9
- package/build-module/image-editor/react/components/index.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/index.mjs +0 -8
- package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
- package/build-module/image-editor/react/hooks/use-aria-announcer.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/image-editor/react/hooks/use-interaction.mjs +0 -190
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
- package/build-module/image-editor/react/visually-hidden-style.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/components/media-editor-modal/build-modifiers.d.ts +0 -80
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -99
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -16
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -63
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -161
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -150
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -47
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -52
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1116
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/media-editor/src/components/media-editor-modal/build-modifiers.ts
|
|
21
|
-
var build_modifiers_exports = {};
|
|
22
|
-
__export(build_modifiers_exports, {
|
|
23
|
-
buildModifiers: () => buildModifiers
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(build_modifiers_exports);
|
|
26
|
-
var import_camera = require("../../image-editor/core/camera.cjs");
|
|
27
|
-
var CROP_TOLERANCE = 0.1;
|
|
28
|
-
function buildModifiers(state, imageSize) {
|
|
29
|
-
const modifiers = [];
|
|
30
|
-
if (imageSize.width === 0 || imageSize.height === 0) {
|
|
31
|
-
return modifiers;
|
|
32
|
-
}
|
|
33
|
-
const { cropRect, pan, zoom, flip } = state;
|
|
34
|
-
const hasFlipH = flip.horizontal;
|
|
35
|
-
const hasFlipV = flip.vertical;
|
|
36
|
-
if (hasFlipH || hasFlipV) {
|
|
37
|
-
modifiers.push({
|
|
38
|
-
type: "flip",
|
|
39
|
-
args: { flip: { horizontal: hasFlipH, vertical: hasFlipV } }
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const rawAngle = (state.rotation % 360 + 360) % 360;
|
|
43
|
-
const singleAxisFlip = hasFlipH !== hasFlipV;
|
|
44
|
-
const signedAngle = singleAxisFlip ? (360 - rawAngle) % 360 : rawAngle;
|
|
45
|
-
if (signedAngle !== 0) {
|
|
46
|
-
modifiers.push({ type: "rotate", args: { angle: signedAngle } });
|
|
47
|
-
}
|
|
48
|
-
const snapRotation = Math.round(state.rotation / 90) * 90;
|
|
49
|
-
const { width: snapW, height: snapH } = (0, import_camera.getRotatedBBox)(
|
|
50
|
-
imageSize.width,
|
|
51
|
-
imageSize.height,
|
|
52
|
-
snapRotation
|
|
53
|
-
);
|
|
54
|
-
const { width: fullW, height: fullH } = (0, import_camera.getRotatedBBox)(
|
|
55
|
-
imageSize.width,
|
|
56
|
-
imageSize.height,
|
|
57
|
-
state.rotation
|
|
58
|
-
);
|
|
59
|
-
const imgLeft = 0.5 + pan.x - zoom / 2;
|
|
60
|
-
const imgTop = 0.5 + pan.y - zoom / 2;
|
|
61
|
-
const snapX = (cropRect.x - imgLeft) / zoom * snapW;
|
|
62
|
-
const snapY = (cropRect.y - imgTop) / zoom * snapH;
|
|
63
|
-
const widthPx = cropRect.width / zoom * snapW;
|
|
64
|
-
const heightPx = cropRect.height / zoom * snapH;
|
|
65
|
-
const offsetX = (fullW - snapW) / 2;
|
|
66
|
-
const offsetY = (fullH - snapH) / 2;
|
|
67
|
-
const fullX = snapX + offsetX;
|
|
68
|
-
const fullY = snapY + offsetY;
|
|
69
|
-
const leftPct = fullX / fullW * 100;
|
|
70
|
-
const topPct = fullY / fullH * 100;
|
|
71
|
-
const widthPct = widthPx / fullW * 100;
|
|
72
|
-
const heightPct = heightPx / fullH * 100;
|
|
73
|
-
const coversFullFrame = leftPct <= CROP_TOLERANCE && topPct <= CROP_TOLERANCE && widthPct >= 100 - CROP_TOLERANCE && heightPct >= 100 - CROP_TOLERANCE;
|
|
74
|
-
if (!coversFullFrame) {
|
|
75
|
-
modifiers.push({
|
|
76
|
-
type: "crop",
|
|
77
|
-
args: {
|
|
78
|
-
left: leftPct,
|
|
79
|
-
top: topPct,
|
|
80
|
-
width: widthPct,
|
|
81
|
-
height: heightPct
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return modifiers;
|
|
86
|
-
}
|
|
87
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
-
0 && (module.exports = {
|
|
89
|
-
buildModifiers
|
|
90
|
-
});
|
|
91
|
-
//# sourceMappingURL=build-modifiers.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-editor-modal/build-modifiers.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CropperState, Size } from '../../image-editor';\nimport { getRotatedBBox } from '../../image-editor/core/camera';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant — the server applies modifiers sequentially (see\n * `WP_REST_Attachments_Controller::edit_media_item`).\n *\n * Shape/units:\n * - `flip`: booleans per axis. Applied first in this module's output.\n * - `rotate`: `angle` in degrees, clockwise-positive (matches the\n * cropper's own convention; Core negates it internally for\n * `WP_Image_Editor::rotate`, which is counterclockwise-positive).\n * - `crop`: percentages (0–100) of the image's dimensions **at the\n * moment the crop is applied**. Because modifiers are applied in\n * order, after a preceding `rotate` the server's\n * `WP_Image_Editor::get_size()` reports the full post-rotate AABB,\n * so the percentages are of that AABB. Origin is top-left.\n */\nexport type Modifier =\n\t| {\n\t\t\ttype: 'flip';\n\t\t\targs: { flip: { horizontal: boolean; vertical: boolean } };\n\t }\n\t| { type: 'rotate'; args: { angle: number } }\n\t| {\n\t\t\ttype: 'crop';\n\t\t\targs: { left: number; top: number; width: number; height: number };\n\t };\n\n/**\n * Tolerance (percent) used to decide whether a crop rect is effectively\n * full-frame. Sub-pixel / float-ulp deltas below this value are treated\n * as no crop. Matches the historical threshold used by the legacy\n * `use-save-image.js` (which compared against `99.9`).\n */\nconst CROP_TOLERANCE = 0.1;\n\n/**\n * Build a Core-compatible modifiers array from the cropper state.\n *\n * Emits `[flip, rotate, crop]` in that order. Identity operations are\n * pruned — an absent flip, a rotation that normalizes to 0°, and a crop\n * rect that covers (within tolerance) the full post-rotate AABB each\n * produce no modifier. An identity state (fresh image, no edits) returns\n * an empty array; callers can use that to skip the `/edit` call.\n *\n * Frames and math:\n *\n * The cropper's `cropRect` is stored as fractions of the **snap-rotation**\n * bounding box (the stencil-reference frame — see `createCamera` /\n * `createExportCamera`). Pan is in that frame; zoom scales the image\n * beneath a fixed stencil. Two conversions are needed to reach the frame\n * Core's crop modifier applies against:\n *\n * 1. Express the stencil rect in snap-AABB **pixels**:\n * Image screen-normalized top-left with zoom/pan is\n * `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the\n * inverse of that transform applied to `cropRect`.\n *\n * 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs\n * share the source-image center, so the conversion is a pure\n * translation by `(fullCenter - snapCenter)`. Finally, express the\n * translated rect as percentages of the full AABB.\n *\n * Rotation sign: the cropper composes `flip · R(θ)` on the source (see\n * `createExportCamera` — rotate then flip). Core's `[flip, rotate]`\n * applies the opposite order: `R(θ') · flip`. For both to land on the\n * same pixels we invert the rotation sign when exactly one flip axis\n * is set (`flip_h · R(θ) = R(-θ) · flip_h`). Both-or-neither flips\n * leave the sign alone because `flip_h · flip_v = -I` commutes with\n * rotation.\n *\n * @param state Current cropper state.\n * @param imageSize Natural dimensions of the source image.\n * @return Ordered modifier array; empty when nothing is server-relevant.\n */\nexport function buildModifiers(\n\tstate: CropperState,\n\timageSize: Size\n): Modifier[] {\n\tconst modifiers: Modifier[] = [];\n\n\tif ( imageSize.width === 0 || imageSize.height === 0 ) {\n\t\treturn modifiers;\n\t}\n\n\tconst { cropRect, pan, zoom, flip } = state;\n\tconst hasFlipH = flip.horizontal;\n\tconst hasFlipV = flip.vertical;\n\n\tif ( hasFlipH || hasFlipV ) {\n\t\tmodifiers.push( {\n\t\t\ttype: 'flip',\n\t\t\targs: { flip: { horizontal: hasFlipH, vertical: hasFlipV } },\n\t\t} );\n\t}\n\n\tconst rawAngle = ( ( state.rotation % 360 ) + 360 ) % 360;\n\t// Invert the sign for single-axis flips so Core's `flip → rotate`\n\t// pipeline matches the cropper's `rotate → flip` composition.\n\tconst singleAxisFlip = hasFlipH !== hasFlipV;\n\tconst signedAngle = singleAxisFlip ? ( 360 - rawAngle ) % 360 : rawAngle;\n\tif ( signedAngle !== 0 ) {\n\t\tmodifiers.push( { type: 'rotate', args: { angle: signedAngle } } );\n\t}\n\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst { width: snapW, height: snapH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\tconst { width: fullW, height: fullH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tstate.rotation\n\t);\n\n\t// Stencil rect in snap-AABB pixels. Inverts `createExportCamera`'s\n\t// pan/zoom composition to recover the pixel rectangle the stencil\n\t// framed in that frame.\n\tconst imgLeft = 0.5 + pan.x - zoom / 2;\n\tconst imgTop = 0.5 + pan.y - zoom / 2;\n\tconst snapX = ( ( cropRect.x - imgLeft ) / zoom ) * snapW;\n\tconst snapY = ( ( cropRect.y - imgTop ) / zoom ) * snapH;\n\tconst widthPx = ( cropRect.width / zoom ) * snapW;\n\tconst heightPx = ( cropRect.height / zoom ) * snapH;\n\n\t// Translate to the full AABB (both centered on source).\n\tconst offsetX = ( fullW - snapW ) / 2;\n\tconst offsetY = ( fullH - snapH ) / 2;\n\tconst fullX = snapX + offsetX;\n\tconst fullY = snapY + offsetY;\n\n\t// Percentages of the full AABB — Core's crop frame after rotate.\n\tconst leftPct = ( fullX / fullW ) * 100;\n\tconst topPct = ( fullY / fullH ) * 100;\n\tconst widthPct = ( widthPx / fullW ) * 100;\n\tconst heightPct = ( heightPx / fullH ) * 100;\n\n\tconst coversFullFrame =\n\t\tleftPct <= CROP_TOLERANCE &&\n\t\ttopPct <= CROP_TOLERANCE &&\n\t\twidthPct >= 100 - CROP_TOLERANCE &&\n\t\theightPct >= 100 - CROP_TOLERANCE;\n\n\tif ( ! coversFullFrame ) {\n\t\tmodifiers.push( {\n\t\t\ttype: 'crop',\n\t\t\targs: {\n\t\t\t\tleft: leftPct,\n\t\t\t\ttop: topPct,\n\t\t\t\twidth: widthPct,\n\t\t\t\theight: heightPct,\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn modifiers;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAA+B;AAmC/B,IAAM,iBAAiB;AAyChB,SAAS,eACf,OACA,WACa;AACb,QAAM,YAAwB,CAAC;AAE/B,MAAK,UAAU,UAAU,KAAK,UAAU,WAAW,GAAI;AACtD,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,UAAU,KAAK,MAAM,KAAK,IAAI;AACtC,QAAM,WAAW,KAAK;AACtB,QAAM,WAAW,KAAK;AAEtB,MAAK,YAAY,UAAW;AAC3B,cAAU,KAAM;AAAA,MACf,MAAM;AAAA,MACN,MAAM,EAAE,MAAM,EAAE,YAAY,UAAU,UAAU,SAAS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P,QAAQ;AAAA,MACT;AAAA,IACD,CAAE;AAAA,EACH;AAEA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/media-editor/src/image-editor/core/camera.ts
|
|
21
|
-
var camera_exports = {};
|
|
22
|
-
__export(camera_exports, {
|
|
23
|
-
createCamera: () => createCamera,
|
|
24
|
-
createExportCamera: () => createExportCamera,
|
|
25
|
-
getImageFit: () => getImageFit,
|
|
26
|
-
getRotatedBBox: () => getRotatedBBox,
|
|
27
|
-
getViewScale: () => getViewScale,
|
|
28
|
-
getVisibleBounds: () => getVisibleBounds,
|
|
29
|
-
screenToWorld: () => screenToWorld,
|
|
30
|
-
worldToScreen: () => worldToScreen
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(camera_exports);
|
|
33
|
-
var import_gl_matrix = require("gl-matrix");
|
|
34
|
-
var import_rotation = require("./math/rotation.cjs");
|
|
35
|
-
var import_sanitize = require("./math/sanitize.cjs");
|
|
36
|
-
var _scratchMat = import_gl_matrix.mat2d.create();
|
|
37
|
-
var _scratchVec = import_gl_matrix.vec2.create();
|
|
38
|
-
function getRotatedBBox(width, height, rotation) {
|
|
39
|
-
if (!(0, import_sanitize.isSafeNumber)(width) || !(0, import_sanitize.isSafeNumber)(height) || !(0, import_sanitize.isSafeNumber)(rotation) || width <= 0 || height <= 0) {
|
|
40
|
-
return { width: 0, height: 0 };
|
|
41
|
-
}
|
|
42
|
-
const rad = (0, import_rotation.degreesToRadians)(rotation);
|
|
43
|
-
const cosR = Math.abs(Math.cos(rad));
|
|
44
|
-
const sinR = Math.abs(Math.sin(rad));
|
|
45
|
-
return {
|
|
46
|
-
width: cosR * width + sinR * height,
|
|
47
|
-
height: sinR * width + cosR * height
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function getImageFit(containerSize, imageSize, rotation) {
|
|
51
|
-
if (!(0, import_sanitize.isValidSize)(containerSize) || !(0, import_sanitize.isValidSize)(imageSize)) {
|
|
52
|
-
return {
|
|
53
|
-
elementSize: { width: 0, height: 0 },
|
|
54
|
-
visualSize: { width: 0, height: 0 }
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const safeRotation = (0, import_sanitize.safeBoundedNumber)(rotation, 0);
|
|
58
|
-
const snapRotation = Math.round(safeRotation / 90) * 90;
|
|
59
|
-
const naturalBBox = getRotatedBBox(
|
|
60
|
-
imageSize.width,
|
|
61
|
-
imageSize.height,
|
|
62
|
-
snapRotation
|
|
63
|
-
);
|
|
64
|
-
if (naturalBBox.width === 0 || naturalBBox.height === 0) {
|
|
65
|
-
return {
|
|
66
|
-
elementSize: { width: 0, height: 0 },
|
|
67
|
-
visualSize: { width: 0, height: 0 }
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
const fitScale = Math.min(
|
|
71
|
-
containerSize.width / naturalBBox.width,
|
|
72
|
-
containerSize.height / naturalBBox.height
|
|
73
|
-
);
|
|
74
|
-
const renderedW = imageSize.width * fitScale;
|
|
75
|
-
const renderedH = imageSize.height * fitScale;
|
|
76
|
-
const visualSize = getRotatedBBox(renderedW, renderedH, snapRotation);
|
|
77
|
-
return {
|
|
78
|
-
elementSize: { width: renderedW, height: renderedH },
|
|
79
|
-
visualSize
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function getViewScale(cropRect, canvasSize, visualSize, targetFill, maxScale) {
|
|
83
|
-
const cropScreenW = cropRect.width * visualSize.width;
|
|
84
|
-
const cropScreenH = cropRect.height * visualSize.height;
|
|
85
|
-
if (!(0, import_sanitize.isValidSize)(canvasSize) || !(0, import_sanitize.isValidSize)(visualSize) || !(cropScreenW > 0) || !(cropScreenH > 0) || !Number.isFinite(targetFill) || !Number.isFinite(maxScale) || !(targetFill > 0) || !(maxScale >= 1)) {
|
|
86
|
-
return 1;
|
|
87
|
-
}
|
|
88
|
-
const kW = targetFill * canvasSize.width / cropScreenW;
|
|
89
|
-
const kH = targetFill * canvasSize.height / cropScreenH;
|
|
90
|
-
const k = Math.min(kW, kH);
|
|
91
|
-
return Math.min(maxScale, Math.max(1, k));
|
|
92
|
-
}
|
|
93
|
-
function createCamera(state, containerSize, imageSize) {
|
|
94
|
-
const m = import_gl_matrix.mat2d.create();
|
|
95
|
-
if (!(0, import_sanitize.isValidSize)(containerSize) || !(0, import_sanitize.isValidSize)(imageSize)) {
|
|
96
|
-
return m;
|
|
97
|
-
}
|
|
98
|
-
const safeState = (0, import_sanitize.sanitizeCropperState)(state);
|
|
99
|
-
const snapRotation = Math.round(safeState.rotation / 90) * 90;
|
|
100
|
-
const naturalBBox = getRotatedBBox(
|
|
101
|
-
imageSize.width,
|
|
102
|
-
imageSize.height,
|
|
103
|
-
snapRotation
|
|
104
|
-
);
|
|
105
|
-
if (naturalBBox.width === 0 || naturalBBox.height === 0) {
|
|
106
|
-
return m;
|
|
107
|
-
}
|
|
108
|
-
const fitScale = Math.min(
|
|
109
|
-
containerSize.width / naturalBBox.width,
|
|
110
|
-
containerSize.height / naturalBBox.height
|
|
111
|
-
);
|
|
112
|
-
const renderedW = imageSize.width * fitScale;
|
|
113
|
-
const renderedH = imageSize.height * fitScale;
|
|
114
|
-
const { width: visualW, height: visualH } = getRotatedBBox(
|
|
115
|
-
renderedW,
|
|
116
|
-
renderedH,
|
|
117
|
-
snapRotation
|
|
118
|
-
);
|
|
119
|
-
import_gl_matrix.mat2d.translate(m, m, [
|
|
120
|
-
containerSize.width / 2,
|
|
121
|
-
containerSize.height / 2
|
|
122
|
-
]);
|
|
123
|
-
import_gl_matrix.mat2d.translate(m, m, [
|
|
124
|
-
safeState.pan.x * visualW,
|
|
125
|
-
safeState.pan.y * visualH
|
|
126
|
-
]);
|
|
127
|
-
import_gl_matrix.mat2d.scale(m, m, [
|
|
128
|
-
safeState.flip.horizontal ? -1 : 1,
|
|
129
|
-
safeState.flip.vertical ? -1 : 1
|
|
130
|
-
]);
|
|
131
|
-
import_gl_matrix.mat2d.rotate(m, m, (0, import_rotation.degreesToRadians)(safeState.rotation));
|
|
132
|
-
import_gl_matrix.mat2d.scale(m, m, [safeState.zoom, safeState.zoom]);
|
|
133
|
-
import_gl_matrix.mat2d.translate(m, m, [-renderedW / 2, -renderedH / 2]);
|
|
134
|
-
import_gl_matrix.mat2d.scale(m, m, [renderedW, renderedH]);
|
|
135
|
-
return m;
|
|
136
|
-
}
|
|
137
|
-
function worldToScreen(camera, point) {
|
|
138
|
-
const out = import_gl_matrix.vec2.create();
|
|
139
|
-
import_gl_matrix.vec2.transformMat2d(out, [point.x, point.y], camera);
|
|
140
|
-
return { x: out[0], y: out[1] };
|
|
141
|
-
}
|
|
142
|
-
function screenToWorld(camera, point) {
|
|
143
|
-
import_gl_matrix.mat2d.invert(_scratchMat, camera);
|
|
144
|
-
const out = _scratchVec;
|
|
145
|
-
import_gl_matrix.vec2.transformMat2d(out, [point.x, point.y], _scratchMat);
|
|
146
|
-
return { x: out[0], y: out[1] };
|
|
147
|
-
}
|
|
148
|
-
function aabb(camera, corners) {
|
|
149
|
-
const screenCorners = corners.map((c) => {
|
|
150
|
-
const out = import_gl_matrix.vec2.create();
|
|
151
|
-
import_gl_matrix.vec2.transformMat2d(out, c, camera);
|
|
152
|
-
return out;
|
|
153
|
-
});
|
|
154
|
-
let minX = screenCorners[0][0];
|
|
155
|
-
let maxX = screenCorners[0][0];
|
|
156
|
-
let minY = screenCorners[0][1];
|
|
157
|
-
let maxY = screenCorners[0][1];
|
|
158
|
-
for (let i = 1; i < screenCorners.length; i++) {
|
|
159
|
-
const s = screenCorners[i];
|
|
160
|
-
if (s[0] < minX) {
|
|
161
|
-
minX = s[0];
|
|
162
|
-
}
|
|
163
|
-
if (s[0] > maxX) {
|
|
164
|
-
maxX = s[0];
|
|
165
|
-
}
|
|
166
|
-
if (s[1] < minY) {
|
|
167
|
-
minY = s[1];
|
|
168
|
-
}
|
|
169
|
-
if (s[1] > maxY) {
|
|
170
|
-
maxY = s[1];
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return { left: minX, top: minY, width: maxX - minX, height: maxY - minY };
|
|
174
|
-
}
|
|
175
|
-
function getVisibleBounds(camera) {
|
|
176
|
-
return aabb(camera, [
|
|
177
|
-
[0, 0],
|
|
178
|
-
[1, 0],
|
|
179
|
-
[1, 1],
|
|
180
|
-
[0, 1]
|
|
181
|
-
]);
|
|
182
|
-
}
|
|
183
|
-
function createExportCamera(state, imageSize, outputSize) {
|
|
184
|
-
const m = import_gl_matrix.mat2d.create();
|
|
185
|
-
if (!(0, import_sanitize.isValidSize)(imageSize) || !(0, import_sanitize.isValidSize)(outputSize)) {
|
|
186
|
-
return m;
|
|
187
|
-
}
|
|
188
|
-
const { rotation, flip, cropRect, zoom, pan } = (0, import_sanitize.sanitizeCropperState)(state);
|
|
189
|
-
const snapRotation = Math.round(rotation / 90) * 90;
|
|
190
|
-
const { width: rotW, height: rotH } = getRotatedBBox(
|
|
191
|
-
imageSize.width,
|
|
192
|
-
imageSize.height,
|
|
193
|
-
snapRotation
|
|
194
|
-
);
|
|
195
|
-
const naturalCropW = cropRect.width * rotW;
|
|
196
|
-
const naturalCropH = cropRect.height * rotH;
|
|
197
|
-
const outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;
|
|
198
|
-
const outputScaleY = naturalCropH > 0 ? outputSize.height / naturalCropH : 1;
|
|
199
|
-
const cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;
|
|
200
|
-
const cropOffsetY = cropRect.y * rotH + outputSize.height / 2 / outputScaleY;
|
|
201
|
-
const visualCenterX = rotW / 2 + pan.x * rotW;
|
|
202
|
-
const visualCenterY = rotH / 2 + pan.y * rotH;
|
|
203
|
-
import_gl_matrix.mat2d.scale(m, m, [outputScaleX, outputScaleY]);
|
|
204
|
-
import_gl_matrix.mat2d.translate(m, m, [
|
|
205
|
-
visualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,
|
|
206
|
-
visualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY
|
|
207
|
-
]);
|
|
208
|
-
import_gl_matrix.mat2d.scale(m, m, [flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1]);
|
|
209
|
-
import_gl_matrix.mat2d.rotate(m, m, (0, import_rotation.degreesToRadians)(rotation));
|
|
210
|
-
import_gl_matrix.mat2d.scale(m, m, [zoom, zoom]);
|
|
211
|
-
import_gl_matrix.mat2d.translate(m, m, [-imageSize.width / 2, -imageSize.height / 2]);
|
|
212
|
-
return m;
|
|
213
|
-
}
|
|
214
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
215
|
-
0 && (module.exports = {
|
|
216
|
-
createCamera,
|
|
217
|
-
createExportCamera,
|
|
218
|
-
getImageFit,
|
|
219
|
-
getRotatedBBox,
|
|
220
|
-
getViewScale,
|
|
221
|
-
getVisibleBounds,
|
|
222
|
-
screenToWorld,
|
|
223
|
-
worldToScreen
|
|
224
|
-
});
|
|
225
|
-
//# sourceMappingURL=camera.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/image-editor/core/camera.ts"],
|
|
4
|
-
"sourcesContent": ["import { mat2d, vec2 } from 'gl-matrix';\nimport type {\n\tCropperState,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tCamera,\n} from './types';\nimport { degreesToRadians } from './math/rotation';\nimport {\n\tisSafeNumber,\n\tisValidSize,\n\tsafeBoundedNumber,\n\tsanitizeCropperState,\n} from './math/sanitize';\n\n// Pre-allocated scratch buffers for `screenToWorld`, which is called per\n// pointermove. Module-level singletons — safe because usage is synchronous.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Compute the axis-aligned bounding box of a rectangle after rotation.\n *\n * @param width The width of the rectangle.\n * @param height The height of the rectangle.\n * @param rotation The rotation angle in degrees.\n * @return The bounding box size after rotation.\n */\nexport function getRotatedBBox(\n\twidth: number,\n\theight: number,\n\trotation: number\n): Size {\n\t// Short-circuit on any unsafe input. `isSafeNumber` is stricter than\n\t// `Number.isFinite`: very large but technically-finite rotations (e.g.\n\t// `Number.MAX_VALUE`) overflow inside `degreesToRadians` and then\n\t// `Math.cos`/`Math.sin` return `NaN`, so the magnitude bound matters.\n\tif (\n\t\t! isSafeNumber( width ) ||\n\t\t! isSafeNumber( height ) ||\n\t\t! isSafeNumber( rotation ) ||\n\t\twidth <= 0 ||\n\t\theight <= 0\n\t) {\n\t\treturn { width: 0, height: 0 };\n\t}\n\tconst rad = degreesToRadians( rotation );\n\tconst cosR = Math.abs( Math.cos( rad ) );\n\tconst sinR = Math.abs( Math.sin( rad ) );\n\treturn {\n\t\twidth: cosR * width + sinR * height,\n\t\theight: sinR * width + cosR * height,\n\t};\n}\n\n/**\n * Compute the fitted (unrotated) image element dimensions and the visual\n * (rotated) bounding box dimensions for a given container, image, and rotation.\n *\n * This is the same \"contain\" fit logic used by createCamera, extracted so\n * cropper.tsx can size the <img> element and position overlays without\n * duplicating the math.\n *\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The natural image dimensions in pixels.\n * @param rotation The rotation angle in degrees.\n * @return The fitted element size and visual bounding box size.\n */\nexport function getImageFit(\n\tcontainerSize: Size,\n\timageSize: Size,\n\trotation: number\n): { elementSize: Size; visualSize: Size } {\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst safeRotation = safeBoundedNumber( rotation, 0 );\n\t// Snap rotation to the nearest 90° multiple for layout sizing.\n\t// This keeps the stencil a stable size through fine ±45° rotation\n\t// (no inflation at 15°/30° etc.) while still swapping aspect at\n\t// 90°/180°/270° so the snap rotate preserves the framed content.\n\tconst snapRotation = Math.round( safeRotation / 90 ) * 90;\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\t// Defensive: getRotatedBBox returns zero dims for hostile inputs, which\n\t// would make fitScale infinite. Mirror the zero-container short-circuit.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn {\n\t\t\telementSize: { width: 0, height: 0 },\n\t\t\tvisualSize: { width: 0, height: 0 },\n\t\t};\n\t}\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\tconst visualSize = getRotatedBBox( renderedW, renderedH, snapRotation );\n\treturn {\n\t\telementSize: { width: renderedW, height: renderedH },\n\t\tvisualSize,\n\t};\n}\n\n/**\n * Resolve the presentational view magnification that makes the crop fill the\n * canvas.\n *\n * The crop overlay is laid out as `cropRect * visualSize` (the contain-fit\n * footprint, with no zoom), so its on-screen size is capped by that footprint.\n * When a crop's aspect differs from the image's, it can be much smaller than\n * the canvas could show (e.g. a square crop in a tall image is bound by the\n * footprint's narrow axis). Scaling `elementSize` and `visualSize` together by\n * the returned factor uniformly magnifies the whole scene — image, crop\n * overlay, and overlays — so the crop reaches `targetFill` of its constraining\n * canvas axis, with the image bleeding past the canvas (clipped by the host).\n *\n * Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,\n * so the framed source region — and therefore the export — is unchanged.\n *\n * @param cropRect The crop rectangle, normalized to the footprint.\n * @param canvasSize The canvas size in pixels.\n * @param visualSize The contain-fit (rotated) image footprint in pixels.\n * @param targetFill Fraction of the constraining canvas axis to fill (0–1].\n * @param maxScale Upper bound on the magnification.\n * @return A magnification factor in [1, maxScale]; 1 when none is needed.\n */\nexport function getViewScale(\n\tcropRect: NormalizedRect,\n\tcanvasSize: Size,\n\tvisualSize: Size,\n\ttargetFill: number,\n\tmaxScale: number\n): number {\n\tconst cropScreenW = cropRect.width * visualSize.width;\n\tconst cropScreenH = cropRect.height * visualSize.height;\n\t// `> 0` comparisons (rather than `<= 0`) reject NaN as well as zero and\n\t// negatives, so a non-finite rect/dimension/scale can't propagate to a\n\t// `scale(NaN)`. `isValidSize` already guards finiteness of the sizes.\n\tif (\n\t\t! isValidSize( canvasSize ) ||\n\t\t! isValidSize( visualSize ) ||\n\t\t! ( cropScreenW > 0 ) ||\n\t\t! ( cropScreenH > 0 ) ||\n\t\t! Number.isFinite( targetFill ) ||\n\t\t! Number.isFinite( maxScale ) ||\n\t\t! ( targetFill > 0 ) ||\n\t\t! ( maxScale >= 1 )\n\t) {\n\t\treturn 1;\n\t}\n\tconst kW = ( targetFill * canvasSize.width ) / cropScreenW;\n\tconst kH = ( targetFill * canvasSize.height ) / cropScreenH;\n\tconst k = Math.min( kW, kH );\n\treturn Math.min( maxScale, Math.max( 1, k ) );\n}\n\n/**\n * Compose a camera matrix from cropper state, container, and image dimensions.\n *\n * The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.\n * Input (0,0) = image top-left, (1,1) = image bottom-right.\n *\n * Composition order (left-to-right = outermost first, applied last to point):\n * M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels\n *\n * Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`\n * are viewport-relative: the image mirrors across the viewport's vertical /\n * horizontal axis regardless of current rotation.\n *\n * @param state The current cropper state (zoom, rotation, flip, crop).\n * @param containerSize The size of the container in pixels.\n * @param imageSize The natural size of the image in pixels.\n * @return The composed camera matrix.\n */\nexport function createCamera(\n\tstate: CropperState,\n\tcontainerSize: Size,\n\timageSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\n\tif ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {\n\t\treturn m;\n\t}\n\n\tconst safeState = sanitizeCropperState( state );\n\n\t// Use the nearest 90° multiple for layout sizing so the stencil\n\t// and visual bounds are stable through fine rotation. The actual\n\t// `state.rotation` is still used for the rotation component of\n\t// the matrix below.\n\tconst snapRotation = Math.round( safeState.rotation / 90 ) * 90;\n\n\t// Rotated bounding box of the natural image (at snap angle).\n\tconst naturalBBox = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Defensive: getRotatedBBox returns zero dims for unsafe inputs. Mirror\n\t// the zero-size short-circuit so `fitScale` doesn't become Infinity.\n\tif ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {\n\t\treturn m;\n\t}\n\n\t// \"Contain\" fit: scale rotated bounding box to fit within container.\n\tconst fitScale = Math.min(\n\t\tcontainerSize.width / naturalBBox.width,\n\t\tcontainerSize.height / naturalBBox.height\n\t);\n\n\t// The rendered (unrotated) image dimensions at this fit scale.\n\tconst renderedW = imageSize.width * fitScale;\n\tconst renderedH = imageSize.height * fitScale;\n\n\t// Visual (rotated) image footprint in pixels (at snap angle).\n\tconst { width: visualW, height: visualH } = getRotatedBBox(\n\t\trenderedW,\n\t\trenderedH,\n\t\tsnapRotation\n\t);\n\n\t// Build matrix left-to-right (outermost first).\n\t// Innermost operations (last in code) are applied first to input point.\n\n\t// Outermost: translate to container center.\n\tmat2d.translate( m, m, [\n\t\tcontainerSize.width / 2,\n\t\tcontainerSize.height / 2,\n\t] );\n\n\t// Pan offset in visual-space pixels.\n\tmat2d.translate( m, m, [\n\t\tsafeState.pan.x * visualW,\n\t\tsafeState.pan.y * visualH,\n\t] );\n\n\t// Flip (viewport-relative — composed outside rotation so horizontal\n\t// flip always mirrors across the viewport's vertical axis).\n\tmat2d.scale( m, m, [\n\t\tsafeState.flip.horizontal ? -1 : 1,\n\t\tsafeState.flip.vertical ? -1 : 1,\n\t] );\n\n\t// Rotate.\n\tmat2d.rotate( m, m, degreesToRadians( safeState.rotation ) );\n\n\t// Zoom.\n\tmat2d.scale( m, m, [ safeState.zoom, safeState.zoom ] );\n\n\t// Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).\n\tmat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );\n\n\t// Innermost: scale from normalized [0,1] to rendered pixels.\n\tmat2d.scale( m, m, [ renderedW, renderedH ] );\n\n\treturn m;\n}\n\n/**\n * Transform a normalized world point [0,1] to screen pixels.\n *\n * @param camera The camera matrix from createCamera.\n * @param point The normalized world coordinate to transform.\n * @return The screen pixel coordinate.\n */\nexport function worldToScreen(\n\tcamera: Camera,\n\tpoint: NormalizedPoint\n): { x: number; y: number } {\n\tconst out = vec2.create();\n\tvec2.transformMat2d( out, [ point.x, point.y ], camera );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * Transform a screen pixel point to normalized world coordinates [0,1].\n *\n * @param camera The camera matrix from createCamera.\n * @param point The screen pixel coordinate to transform.\n * @param point.x The x component of the screen pixel coordinate.\n * @param point.y The y component of the screen pixel coordinate.\n * @return The normalized world coordinate.\n */\nexport function screenToWorld(\n\tcamera: Camera,\n\tpoint: { x: number; y: number }\n): NormalizedPoint {\n\tmat2d.invert( _scratchMat, camera );\n\tconst out = _scratchVec;\n\tvec2.transformMat2d( out, [ point.x, point.y ], _scratchMat );\n\treturn { x: out[ 0 ], y: out[ 1 ] };\n}\n\n/**\n * The bounding box of a transformed region in screen (pixel) space.\n */\nexport interface VisualBounds {\n\tleft: number;\n\ttop: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Compute the axis-aligned bounding box of a set of corners after\n * transforming them through a camera matrix.\n *\n * @param camera The camera matrix from createCamera.\n * @param corners The corners to transform (each as [x, y]).\n * @return The screen-space bounding box.\n */\nfunction aabb( camera: Camera, corners: [ number, number ][] ): VisualBounds {\n\tconst screenCorners = corners.map( ( c ) => {\n\t\tconst out = vec2.create();\n\t\tvec2.transformMat2d( out, c, camera );\n\t\treturn out;\n\t} );\n\tlet minX = screenCorners[ 0 ][ 0 ];\n\tlet maxX = screenCorners[ 0 ][ 0 ];\n\tlet minY = screenCorners[ 0 ][ 1 ];\n\tlet maxY = screenCorners[ 0 ][ 1 ];\n\tfor ( let i = 1; i < screenCorners.length; i++ ) {\n\t\tconst s = screenCorners[ i ];\n\t\tif ( s[ 0 ] < minX ) {\n\t\t\tminX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 0 ] > maxX ) {\n\t\t\tmaxX = s[ 0 ];\n\t\t}\n\t\tif ( s[ 1 ] < minY ) {\n\t\t\tminY = s[ 1 ];\n\t\t}\n\t\tif ( s[ 1 ] > maxY ) {\n\t\t\tmaxY = s[ 1 ];\n\t\t}\n\t}\n\treturn { left: minX, top: minY, width: maxX - minX, height: maxY - minY };\n}\n\n/**\n * Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])\n * after applying the camera transform.\n *\n * @param camera The camera matrix from createCamera.\n * @return The screen-space bounding box of the full image.\n */\nexport function getVisibleBounds( camera: Camera ): VisualBounds {\n\treturn aabb( camera, [\n\t\t[ 0, 0 ],\n\t\t[ 1, 0 ],\n\t\t[ 1, 1 ],\n\t\t[ 0, 1 ],\n\t] );\n}\n\n/**\n * Compose a camera matrix for exporting to a canvas.\n *\n * The resulting matrix maps image-pixel coordinates directly to output-canvas\n * coordinates. Apply it with `ctx.setTransform( ...camera )` then\n * `ctx.drawImage( image, 0, 0 )`.\n *\n * The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:\n * translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the source image in pixels.\n * @param outputSize The desired output canvas size in pixels.\n * @return The composed export camera matrix.\n */\nexport function createExportCamera(\n\tstate: CropperState,\n\timageSize: Size,\n\toutputSize: Size\n): Camera {\n\tconst m = mat2d.create();\n\tif ( ! isValidSize( imageSize ) || ! isValidSize( outputSize ) ) {\n\t\treturn m;\n\t}\n\tconst { rotation, flip, cropRect, zoom, pan } =\n\t\tsanitizeCropperState( state );\n\t// Reference frame for cropRect/pan is the snap-rotation bbox — that's\n\t// what the stencil and CSS matrix use in the preview (see createCamera\n\t// and getImageFit). Using the true rotation here would position the\n\t// crop window at a different offset than the stencil framed, and show\n\t// a shifted region after any fine rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { width: rotW, height: rotH } = getRotatedBBox(\n\t\timageSize.width,\n\t\timageSize.height,\n\t\tsnapRotation\n\t);\n\n\t// Scale factor to map the natural crop region to the output canvas size.\n\tconst naturalCropW = cropRect.width * rotW;\n\tconst naturalCropH = cropRect.height * rotH;\n\tconst outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;\n\tconst outputScaleY =\n\t\tnaturalCropH > 0 ? outputSize.height / naturalCropH : 1;\n\n\tconst cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;\n\tconst cropOffsetY =\n\t\tcropRect.y * rotH + outputSize.height / 2 / outputScaleY;\n\tconst visualCenterX = rotW / 2 + pan.x * rotW;\n\tconst visualCenterY = rotH / 2 + pan.y * rotH;\n\tmat2d.scale( m, m, [ outputScaleX, outputScaleY ] );\n\tmat2d.translate( m, m, [\n\t\tvisualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,\n\t\tvisualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY,\n\t] );\n\t// Flip is composed outside rotation so it acts in viewport/output space —\n\t// must match createCamera's order for preview and export to agree.\n\tmat2d.scale( m, m, [ flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1 ] );\n\tmat2d.rotate( m, m, degreesToRadians( rotation ) );\n\tmat2d.scale( m, m, [ zoom, zoom ] );\n\tmat2d.translate( m, m, [ -imageSize.width / 2, -imageSize.height / 2 ] );\n\treturn m;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA4B;AAQ5B,sBAAiC;AACjC,sBAKO;AAIP,IAAM,cAAc,uBAAM,OAAO;AACjC,IAAM,cAAc,sBAAK,OAAO;AAUzB,SAAS,eACf,OACA,QACA,UACO;AAKP,MACC,KAAE,8BAAc,KAAM,KACtB,KAAE,8BAAc,MAAO,KACvB,KAAE,8BAAc,QAAS,KACzB,SAAS,KACT,UAAU,GACT;AACD,WAAO,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,EAC9B;AACA,QAAM,UAAM,kCAAkB,QAAS;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,SAAO;AAAA,IACN,OAAO,OAAO,QAAQ,OAAO;AAAA,IAC7B,QAAQ,OAAO,QAAQ,OAAO;AAAA,EAC/B;AACD;AAeO,SAAS,YACf,eACA,WACA,UAC0C;AAC1C,MAAK,KAAE,6BAAa,aAAc,KAAK,KAAE,6BAAa,SAAU,GAAI;AACnE,WAAO;AAAA,MACN,aAAa,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,MACnC,YAAY,EAAE,OAAO,GAAG,QAAQ,EAAE;AAAA,IACnC;AAAA,EACD;AACA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M,IAAK,CAAE;AAClC,yBAAM,UAAW,GAAG,GAAG,CAAE,CAAC,UAAU,QAAQ,GAAG,CAAC,UAAU,SAAS,CAAE,CAAE;AACvE,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/media-editor/src/image-editor/core/constants.ts
|
|
21
|
-
var constants_exports = {};
|
|
22
|
-
__export(constants_exports, {
|
|
23
|
-
ABSOLUTE_MIN_ZOOM: () => ABSOLUTE_MIN_ZOOM,
|
|
24
|
-
DEFAULT_ASPECT_RATIOS: () => DEFAULT_ASPECT_RATIOS,
|
|
25
|
-
DEFAULT_KEYBOARD_STEP: () => DEFAULT_KEYBOARD_STEP,
|
|
26
|
-
DEFAULT_STATE: () => DEFAULT_STATE,
|
|
27
|
-
DEFAULT_WHEEL_ZOOM_SPEED: () => DEFAULT_WHEEL_ZOOM_SPEED,
|
|
28
|
-
KEYBOARD_SHIFT_STEP_MULTIPLIER: () => KEYBOARD_SHIFT_STEP_MULTIPLIER,
|
|
29
|
-
MAX_ROTATION_OFFSET: () => MAX_ROTATION_OFFSET,
|
|
30
|
-
MAX_VIEW_SCALE: () => MAX_VIEW_SCALE,
|
|
31
|
-
MAX_ZOOM: () => MAX_ZOOM,
|
|
32
|
-
MIN_CROP_PIXELS: () => MIN_CROP_PIXELS,
|
|
33
|
-
MIN_CROP_SCREEN_PX: () => MIN_CROP_SCREEN_PX,
|
|
34
|
-
MIN_ZOOM: () => MIN_ZOOM,
|
|
35
|
-
ORIGINAL_ASPECT_RATIO: () => ORIGINAL_ASPECT_RATIO,
|
|
36
|
-
PIXEL_SNAP_DISPLAY_SCALE: () => PIXEL_SNAP_DISPLAY_SCALE,
|
|
37
|
-
SETTLE_TARGET_CANVAS_FILL: () => SETTLE_TARGET_CANVAS_FILL
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(constants_exports);
|
|
40
|
-
var import_i18n = require("@wordpress/i18n");
|
|
41
|
-
var MIN_ZOOM = 1;
|
|
42
|
-
var ABSOLUTE_MIN_ZOOM = 0.1;
|
|
43
|
-
var MAX_ZOOM = 10;
|
|
44
|
-
var MIN_CROP_PIXELS = 16;
|
|
45
|
-
var MIN_CROP_SCREEN_PX = 44;
|
|
46
|
-
var SETTLE_TARGET_CANVAS_FILL = 0.8;
|
|
47
|
-
var MAX_VIEW_SCALE = 8;
|
|
48
|
-
var PIXEL_SNAP_DISPLAY_SCALE = 1;
|
|
49
|
-
var DEFAULT_WHEEL_ZOOM_SPEED = 25e-4;
|
|
50
|
-
var DEFAULT_KEYBOARD_STEP = 0.01;
|
|
51
|
-
var KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;
|
|
52
|
-
var MAX_ROTATION_OFFSET = 45;
|
|
53
|
-
var DEFAULT_CROP_RECT = {
|
|
54
|
-
x: 0,
|
|
55
|
-
y: 0,
|
|
56
|
-
width: 1,
|
|
57
|
-
height: 1
|
|
58
|
-
};
|
|
59
|
-
var DEFAULT_FLIP = {
|
|
60
|
-
horizontal: false,
|
|
61
|
-
vertical: false
|
|
62
|
-
};
|
|
63
|
-
var DEFAULT_PAN = {
|
|
64
|
-
x: 0,
|
|
65
|
-
y: 0
|
|
66
|
-
};
|
|
67
|
-
var DEFAULT_STATE = {
|
|
68
|
-
image: null,
|
|
69
|
-
pan: { ...DEFAULT_PAN },
|
|
70
|
-
zoom: MIN_ZOOM,
|
|
71
|
-
rotation: 0,
|
|
72
|
-
basePan: { ...DEFAULT_PAN },
|
|
73
|
-
baseZoom: MIN_ZOOM,
|
|
74
|
-
baseRotation: 0,
|
|
75
|
-
flip: { ...DEFAULT_FLIP },
|
|
76
|
-
cropRect: { ...DEFAULT_CROP_RECT }
|
|
77
|
-
};
|
|
78
|
-
var ORIGINAL_ASPECT_RATIO = -1;
|
|
79
|
-
var DEFAULT_ASPECT_RATIOS = [
|
|
80
|
-
{ label: (0, import_i18n.__)("Free"), value: 0 },
|
|
81
|
-
{ label: (0, import_i18n.__)("Original"), value: ORIGINAL_ASPECT_RATIO },
|
|
82
|
-
{ label: (0, import_i18n.__)("Square (1:1)"), value: 1 },
|
|
83
|
-
{ label: (0, import_i18n.__)("Landscape (16:9)"), value: 16 / 9 },
|
|
84
|
-
{ label: (0, import_i18n.__)("Portrait (9:16)"), value: 9 / 16 },
|
|
85
|
-
{ label: (0, import_i18n.__)("Classic (4:3)"), value: 4 / 3 },
|
|
86
|
-
{ label: (0, import_i18n.__)("Classic portrait (3:4)"), value: 3 / 4 },
|
|
87
|
-
{ label: (0, import_i18n.__)("Photo (3:2)"), value: 3 / 2 },
|
|
88
|
-
{ label: (0, import_i18n.__)("Photo portrait (2:3)"), value: 2 / 3 }
|
|
89
|
-
];
|
|
90
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
-
0 && (module.exports = {
|
|
92
|
-
ABSOLUTE_MIN_ZOOM,
|
|
93
|
-
DEFAULT_ASPECT_RATIOS,
|
|
94
|
-
DEFAULT_KEYBOARD_STEP,
|
|
95
|
-
DEFAULT_STATE,
|
|
96
|
-
DEFAULT_WHEEL_ZOOM_SPEED,
|
|
97
|
-
KEYBOARD_SHIFT_STEP_MULTIPLIER,
|
|
98
|
-
MAX_ROTATION_OFFSET,
|
|
99
|
-
MAX_VIEW_SCALE,
|
|
100
|
-
MAX_ZOOM,
|
|
101
|
-
MIN_CROP_PIXELS,
|
|
102
|
-
MIN_CROP_SCREEN_PX,
|
|
103
|
-
MIN_ZOOM,
|
|
104
|
-
ORIGINAL_ASPECT_RATIO,
|
|
105
|
-
PIXEL_SNAP_DISPLAY_SCALE,
|
|
106
|
-
SETTLE_TARGET_CANVAS_FILL
|
|
107
|
-
});
|
|
108
|
-
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/image-editor/core/constants.ts"],
|
|
4
|
-
"sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport type { NormalizedRect, Flip, CropperState } from './types';\n\n/**\n * Default/resting zoom. A full, unrotated crop needs at least 1x to cover the\n * crop area, but smaller/fine-rotated crops can be valid below 1x — the true\n * floor for those comes from `getMinZoom`.\n */\nexport const MIN_ZOOM = 1;\n/**\n * Safety floor for coverage-aware zoom. Degenerate crops can have a geometric\n * coverage minimum of 0, but camera and inverse-matrix math need a stable,\n * positive scale.\n */\nexport const ABSOLUTE_MIN_ZOOM = 0.1;\nexport const MAX_ZOOM = 10;\n\n/**\n * Minimum crop rect dimension in source-image pixels, enforced per axis\n * during resize. Prevents accidental sub-pixel crops while staying small\n * enough to allow tight crops (favicons, icons). Adjust here to tune the\n * floor globally.\n */\nexport const MIN_CROP_PIXELS = 16;\n\n/**\n * Minimum on-screen crop rect dimension in CSS pixels. The source-pixel\n * floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large\n * image fit into a small canvas it can render only a few CSS pixels wide —\n * too small to grab the resize handles. This floor keeps the crop operable\n * regardless of display scale; it binds when zoomed out and yields to the\n * source-pixel floor once the image is shown large enough. Sized to one\n * handle touch target (`$handle-touch-target-size` in `cropper.scss`).\n */\nexport const MIN_CROP_SCREEN_PX = 44;\n\n/**\n * Fraction of the constraining canvas axis the settled crop should occupy on\n * screen. When a crop is shown smaller than this (e.g. a square crop in a tall\n * image, capped by the contain-fit footprint's narrow axis), the view magnifies\n * to fill the canvas. `1` = always fill the canvas; lower = rescue only the\n * under-filled cases. See `getViewScale`.\n */\nexport const SETTLE_TARGET_CANVAS_FILL = 0.8;\n\n/**\n * Upper bound on the presentational view magnification (`getViewScale`).\n * Prevents a near-degenerate crop from magnifying the scene without limit.\n */\nexport const MAX_VIEW_SCALE = 8;\n\n/**\n * CSS pixels per source pixel required before resize handles snap the selected\n * source region to whole-pixel edges. Below 1:1, a source pixel is sub-pixel on\n * screen, so snapping would feel notchy without a visible pixel boundary.\n */\nexport const PIXEL_SNAP_DISPLAY_SCALE = 1;\n\n/**\n * Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.\n * This could be made configurable as a prop to the Cropper component.\n */\nexport const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;\n\n/** Fine step for keyboard-driven cropper movement, in normalized coordinates. */\nexport const DEFAULT_KEYBOARD_STEP = 0.01;\n\n/** Coarse keyboard movement multiplier when Shift is held. */\nexport const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;\n\n/**\n * Maximum free-rotation offset in degrees from the nearest 90° step.\n * The rotation slider allows ±45° around the current cardinal angle.\n */\nexport const MAX_ROTATION_OFFSET = 45;\n\nconst DEFAULT_CROP_RECT: NormalizedRect = {\n\tx: 0,\n\ty: 0,\n\twidth: 1,\n\theight: 1,\n};\n\nconst DEFAULT_FLIP: Flip = {\n\thorizontal: false,\n\tvertical: false,\n};\n\nconst DEFAULT_PAN: { x: number; y: number } = {\n\tx: 0,\n\ty: 0,\n};\n\nexport const DEFAULT_STATE: CropperState = {\n\timage: null,\n\tpan: { ...DEFAULT_PAN },\n\tzoom: MIN_ZOOM,\n\trotation: 0,\n\tbasePan: { ...DEFAULT_PAN },\n\tbaseZoom: MIN_ZOOM,\n\tbaseRotation: 0,\n\tflip: { ...DEFAULT_FLIP },\n\tcropRect: { ...DEFAULT_CROP_RECT },\n};\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/** The aspect ratio value (width / height). 0 = free / original. */\n\tvalue: number;\n}\n\n/**\n * Default aspect ratio presets. Consumers can use these as-is, override\n * with their own list, or extend with additional presets.\n *\n * @example\n * // Use defaults:\n * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />\n *\n * // Custom presets:\n * const socialPresets = [\n * { label: 'Instagram Post', value: 1 },\n * { label: 'Instagram Story', value: 9 / 16 },\n * { label: 'YouTube Thumbnail', value: 16 / 9 },\n * ];\n *\n * // Extend defaults:\n * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];\n */\n/**\n * Sentinel value for \"Original\" aspect ratio — resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA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