@wordpress/media-editor 0.7.1-next.v.202604201441.0 → 0.8.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/build/components/media-editor-canvas/index.cjs +54 -0
- package/build/components/media-editor-canvas/index.cjs.map +7 -0
- package/build/components/media-editor-crop-panel/index.cjs +116 -0
- package/build/components/media-editor-crop-panel/index.cjs.map +7 -0
- package/build/components/media-editor-modal/build-modifiers.cjs +91 -0
- package/build/components/media-editor-modal/build-modifiers.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +497 -0
- package/build/components/media-editor-modal/index.cjs.map +7 -0
- package/build/components/media-editor-toolbar/index.cjs +146 -0
- package/build/components/media-editor-toolbar/index.cjs.map +7 -0
- package/build/image-editor/core/camera.cjs +194 -0
- package/build/image-editor/core/camera.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +81 -0
- package/build/image-editor/core/constants.cjs.map +7 -0
- package/build/image-editor/core/containment.cjs +245 -0
- package/build/image-editor/core/containment.cjs.map +7 -0
- package/build/image-editor/core/export/canvas-renderer.cjs +151 -0
- package/build/image-editor/core/export/canvas-renderer.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +50 -0
- package/build/image-editor/core/index.cjs.map +7 -0
- package/build/image-editor/core/interaction-controller.cjs +608 -0
- package/build/image-editor/core/interaction-controller.cjs.map +7 -0
- package/build/image-editor/core/math/rotation.cjs +41 -0
- package/build/image-editor/core/math/rotation.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +95 -0
- package/build/image-editor/core/source-region.cjs.map +7 -0
- package/build/image-editor/core/state.cjs +269 -0
- package/build/image-editor/core/state.cjs.map +7 -0
- package/build/image-editor/core/stencil-math.cjs +197 -0
- package/build/image-editor/core/stencil-math.cjs.map +7 -0
- package/build/image-editor/core/transform-style.cjs +46 -0
- package/build/image-editor/core/transform-style.cjs.map +7 -0
- package/build/image-editor/core/transforms/pipeline.cjs +43 -0
- package/build/image-editor/core/transforms/pipeline.cjs.map +7 -0
- package/build/image-editor/core/types.cjs +19 -0
- package/build/image-editor/core/types.cjs.map +7 -0
- package/build/image-editor/index.cjs +57 -0
- package/build/image-editor/index.cjs.map +7 -0
- package/build/image-editor/react/components/cropper-provider.cjs +50 -0
- package/build/image-editor/react/components/cropper-provider.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +365 -0
- package/build/image-editor/react/components/cropper.cjs.map +7 -0
- package/build/image-editor/react/components/index.cjs +36 -0
- package/build/image-editor/react/components/index.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +58 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +91 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +351 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +31 -0
- package/build/image-editor/react/hooks/index.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +68 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs +158 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +161 -0
- package/build/image-editor/react/hooks/use-interaction.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs +38 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +7 -0
- package/build/index.cjs +5 -2
- package/build/index.cjs.map +2 -2
- package/build/lock-unlock.cjs +37 -0
- package/build/lock-unlock.cjs.map +7 -0
- package/build/private-apis.cjs +38 -0
- package/build/private-apis.cjs.map +7 -0
- package/build/store/actions.cjs +45 -0
- package/build/store/actions.cjs.map +7 -0
- package/build/store/constants.cjs +31 -0
- package/build/store/constants.cjs.map +7 -0
- package/build/store/index.cjs +51 -0
- package/build/store/index.cjs.map +7 -0
- package/build/store/reducer.cjs +51 -0
- package/build/store/reducer.cjs.map +7 -0
- package/build/store/selectors.cjs +43 -0
- package/build/store/selectors.cjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +33 -0
- package/build-module/components/media-editor-canvas/index.mjs.map +7 -0
- package/build-module/components/media-editor-crop-panel/index.mjs +100 -0
- package/build-module/components/media-editor-crop-panel/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs +66 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +483 -0
- package/build-module/components/media-editor-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-toolbar/index.mjs +130 -0
- package/build-module/components/media-editor-toolbar/index.mjs.map +7 -0
- package/build-module/image-editor/core/camera.mjs +163 -0
- package/build-module/image-editor/core/camera.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +51 -0
- package/build-module/image-editor/core/constants.mjs.map +7 -0
- package/build-module/image-editor/core/containment.mjs +218 -0
- package/build-module/image-editor/core/containment.mjs.map +7 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs +120 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +24 -0
- package/build-module/image-editor/core/index.mjs.map +7 -0
- package/build-module/image-editor/core/interaction-controller.mjs +583 -0
- package/build-module/image-editor/core/interaction-controller.mjs.map +7 -0
- package/build-module/image-editor/core/math/rotation.mjs +15 -0
- package/build-module/image-editor/core/math/rotation.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +69 -0
- package/build-module/image-editor/core/source-region.mjs.map +7 -0
- package/build-module/image-editor/core/state.mjs +242 -0
- package/build-module/image-editor/core/state.mjs.map +7 -0
- package/build-module/image-editor/core/stencil-math.mjs +169 -0
- package/build-module/image-editor/core/stencil-math.mjs.map +7 -0
- package/build-module/image-editor/core/transform-style.mjs +21 -0
- package/build-module/image-editor/core/transform-style.mjs.map +7 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs +17 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +7 -0
- package/build-module/image-editor/core/types.mjs +1 -0
- package/build-module/image-editor/core/types.mjs.map +7 -0
- package/build-module/image-editor/index.mjs +30 -0
- package/build-module/image-editor/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs +26 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +337 -0
- package/build-module/image-editor/react/components/cropper.mjs.map +7 -0
- package/build-module/image-editor/react/components/index.mjs +9 -0
- package/build-module/image-editor/react/components/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +33 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +66 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +330 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +6 -0
- package/build-module/image-editor/react/hooks/index.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +43 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +137 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +138 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +13 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +7 -0
- package/build-module/index.mjs +3 -1
- package/build-module/index.mjs.map +2 -2
- package/build-module/lock-unlock.mjs +11 -0
- package/build-module/lock-unlock.mjs.map +7 -0
- package/build-module/private-apis.mjs +13 -0
- package/build-module/private-apis.mjs.map +7 -0
- package/build-module/store/actions.mjs +19 -0
- package/build-module/store/actions.mjs.map +7 -0
- package/build-module/store/constants.mjs +6 -0
- package/build-module/store/constants.mjs.map +7 -0
- package/build-module/store/index.mjs +16 -0
- package/build-module/store/index.mjs.map +7 -0
- package/build-module/store/reducer.mjs +26 -0
- package/build-module/store/reducer.mjs.map +7 -0
- package/build-module/store/selectors.mjs +16 -0
- package/build-module/store/selectors.mjs.map +7 -0
- package/build-style/style-rtl.css +315 -0
- package/build-style/style.css +315 -0
- package/build-types/components/media-editor-canvas/index.d.ts +22 -0
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts +45 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +20 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-toolbar/index.d.ts +21 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/image-editor/core/camera.d.ts +107 -0
- package/build-types/image-editor/core/camera.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +46 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -0
- package/build-types/image-editor/core/containment.d.ts +61 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +106 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +8 -0
- package/build-types/image-editor/core/index.d.ts.map +1 -0
- package/build-types/image-editor/core/interaction-controller.d.ts +178 -0
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
- package/build-types/image-editor/core/math/rotation.d.ts +18 -0
- package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts +75 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -0
- package/build-types/image-editor/core/state.d.ts +42 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -0
- package/build-types/image-editor/core/stencil-math.d.ts +79 -0
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
- package/build-types/image-editor/core/transform-style.d.ts +23 -0
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
- package/build-types/image-editor/core/types.d.ts +211 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -0
- package/build-types/image-editor/index.d.ts +16 -0
- package/build-types/image-editor/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +37 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper.d.ts +59 -0
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
- package/build-types/image-editor/react/components/index.d.ts +4 -0
- package/build-types/image-editor/react/components/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +32 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +3 -0
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +68 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +60 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +2 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +27 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +2 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +4 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +23 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +8 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/package.json +21 -7
- package/src/components/media-editor-canvas/index.tsx +56 -0
- package/src/components/media-editor-canvas/style.scss +9 -0
- package/src/components/media-editor-crop-panel/index.tsx +143 -0
- package/src/components/media-editor-modal/build-modifiers.ts +164 -0
- package/src/components/media-editor-modal/index.tsx +639 -0
- package/src/components/media-editor-modal/style.scss +139 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +343 -0
- package/src/components/media-editor-toolbar/index.tsx +150 -0
- package/src/components/media-editor-toolbar/style.scss +21 -0
- package/src/image-editor/README.md +162 -0
- package/src/image-editor/core/camera.ts +352 -0
- package/src/image-editor/core/constants.ts +93 -0
- package/src/image-editor/core/containment.ts +435 -0
- package/src/image-editor/core/export/canvas-renderer.ts +253 -0
- package/src/image-editor/core/export/test/canvas-renderer.ts +813 -0
- package/src/image-editor/core/index.ts +35 -0
- package/src/image-editor/core/interaction-controller.ts +889 -0
- package/src/image-editor/core/math/rotation.ts +26 -0
- package/src/image-editor/core/source-region.ts +166 -0
- package/src/image-editor/core/state.ts +428 -0
- package/src/image-editor/core/stencil-math.ts +330 -0
- package/src/image-editor/core/test/camera.ts +593 -0
- package/src/image-editor/core/test/interaction-controller.ts +996 -0
- package/src/image-editor/core/test/preview-export-parity.ts +242 -0
- package/src/image-editor/core/test/render-camera-bridge.ts +348 -0
- package/src/image-editor/core/test/state.ts +762 -0
- package/src/image-editor/core/test/stencil-math.ts +321 -0
- package/src/image-editor/core/transform-style.ts +44 -0
- package/src/image-editor/core/transforms/pipeline.ts +43 -0
- package/src/image-editor/core/transforms/test/pipeline.ts +269 -0
- package/src/image-editor/core/types.ts +177 -0
- package/src/image-editor/docs/architecture.md +96 -0
- package/src/image-editor/docs/recipes.md +720 -0
- package/src/image-editor/docs/roadmap.md +66 -0
- package/src/image-editor/index.ts +43 -0
- package/src/image-editor/react/components/cropper-provider.tsx +73 -0
- package/src/image-editor/react/components/cropper.scss +195 -0
- package/src/image-editor/react/components/cropper.tsx +534 -0
- package/src/image-editor/react/components/index.ts +3 -0
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +57 -0
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +80 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +513 -0
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +265 -0
- package/src/image-editor/react/components/test/cropper.tsx +140 -0
- package/src/image-editor/react/hooks/index.ts +2 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +913 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +218 -0
- package/src/image-editor/react/hooks/test/use-transform-style.ts +146 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +64 -0
- package/src/image-editor/react/hooks/use-cropper-state.ts +238 -0
- package/src/image-editor/react/hooks/use-interaction.ts +223 -0
- package/src/image-editor/react/hooks/use-transform-style.ts +30 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +1085 -0
- package/src/image-editor/stories/style.css +94 -0
- package/src/image-editor/style.scss +1 -0
- package/src/index.ts +3 -0
- package/src/lock-unlock.ts +10 -0
- package/src/private-apis.ts +12 -0
- package/src/store/actions.ts +33 -0
- package/src/store/constants.ts +1 -0
- package/src/store/index.ts +20 -0
- package/src/store/reducer.ts +48 -0
- package/src/store/selectors.ts +16 -0
- package/src/store/test/reducer.ts +57 -0
- package/src/style.scss +4 -0
- package/tsconfig.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import { Cropper } from '../react/components/cropper';
|
|
9
|
+
import './style.css';
|
|
10
|
+
declare const meta: Meta<typeof Cropper>;
|
|
11
|
+
export default meta;
|
|
12
|
+
type Story = StoryObj<typeof Cropper>;
|
|
13
|
+
export declare const Default: Story;
|
|
14
|
+
export declare const WithControls: Story;
|
|
15
|
+
export declare const Debug: Story;
|
|
16
|
+
//# sourceMappingURL=rectangle-crop.story.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rectangle-crop.story.d.ts","sourceRoot":"","sources":["../../../src/image-editor/stories/rectangle-crop.story.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAwB5D;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAwBtD,OAAO,aAAa,CAAC;AA6ErB,QAAA,MAAM,IAAI,EAAE,IAAI,CAAE,OAAO,OAAO,CAI/B,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAE,OAAO,OAAO,CAAE,CAAC;AAsBxC,eAAO,MAAM,OAAO,EAAE,KAErB,CAAC;AAkXF,eAAO,MAAM,YAAY,EAAE,KAE1B,CAAC;AAmiBF,eAAO,MAAM,KAAK,EAAE,KAEnB,CAAC"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export type { Media, MediaEditorProviderProps, } from './components/media-editor
|
|
|
5
5
|
export type { MediaPreviewProps } from './components/media-preview';
|
|
6
6
|
export type { MediaFormProps } from './components/media-form';
|
|
7
7
|
export type { Field, Form } from '@wordpress/dataviews';
|
|
8
|
+
export { privateApis } from './private-apis';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAG/D,YAAY,EACX,KAAK,EACL,wBAAwB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAG/D,YAAY,EACX,KAAK,EACL,wBAAwB,GACxB,MAAM,oCAAoC,CAAC;AAC5C,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-unlock.d.ts","sourceRoot":"","sources":["../src/lock-unlock.ts"],"names":[],"mappings":"AAKA,eAAO,MAAQ,IAAI,mDAAE,MAAM,iCAIzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-apis.d.ts","sourceRoot":"","sources":["../src/private-apis.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW,IAAK,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape passed to `onUpdate` after a successful save. Deliberately normalized
|
|
3
|
+
* and minimal: `url` instead of REST's `source_url`, so consumers can drop
|
|
4
|
+
* it straight into block attributes (matches the legacy `ImageEditor`'s
|
|
5
|
+
* `onSaveImage` shape at
|
|
6
|
+
* `packages/block-editor/src/components/image-editor/use-save-image.js`).
|
|
7
|
+
* Keeping this decoupled from the REST field names also leaves room to reuse
|
|
8
|
+
* the modal outside a WordPress REST context (e.g. native/Electron hosts).
|
|
9
|
+
*/
|
|
10
|
+
export interface MediaEditorModalUpdate {
|
|
11
|
+
id: number;
|
|
12
|
+
url?: string;
|
|
13
|
+
}
|
|
14
|
+
interface OpenMediaEditorModalArgs {
|
|
15
|
+
id: number;
|
|
16
|
+
onUpdate?: (updated: MediaEditorModalUpdate) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare function openMediaEditorModal({ id, onUpdate, }: OpenMediaEditorModalArgs): {
|
|
19
|
+
type: "OPEN_MEDIA_EDITOR_MODAL";
|
|
20
|
+
id: number;
|
|
21
|
+
onUpdate: ((updated: MediaEditorModalUpdate) => void) | null;
|
|
22
|
+
};
|
|
23
|
+
export declare function closeMediaEditorModal(): {
|
|
24
|
+
type: "CLOSE_MEDIA_EDITOR_MODAL";
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/store/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,UAAU,wBAAwB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,CAAE,OAAO,EAAE,sBAAsB,KAAM,IAAI,CAAC;CACvD;AAED,wBAAgB,oBAAoB,CAAE,EACrC,EAAE,EACF,QAAQ,GACR,EAAE,wBAAwB;;;yBANJ,sBAAsB,KAAM,IAAI;EAYtD;AAED,wBAAgB,qBAAqB;;EAEpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/store/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as actions from './actions';
|
|
2
|
+
import * as selectors from './selectors';
|
|
3
|
+
export declare const store: import("@wordpress/data").StoreDescriptor<import("@wordpress/data").ReduxStoreConfig<unknown, typeof actions, typeof selectors>>;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAGzC,eAAO,MAAM,KAAK,kIAIf,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { MediaEditorModalUpdate } from './actions';
|
|
5
|
+
type OnUpdateCallback = (updated: MediaEditorModalUpdate) => void;
|
|
6
|
+
export interface State {
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
id: number | null;
|
|
9
|
+
onUpdate: OnUpdateCallback | null;
|
|
10
|
+
}
|
|
11
|
+
export declare const DEFAULT_STATE: State;
|
|
12
|
+
type Action = {
|
|
13
|
+
type: 'OPEN_MEDIA_EDITOR_MODAL';
|
|
14
|
+
id: number;
|
|
15
|
+
onUpdate: OnUpdateCallback | null;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'CLOSE_MEDIA_EDITOR_MODAL';
|
|
18
|
+
};
|
|
19
|
+
export default function reducer(state: State | undefined, action: Action | {
|
|
20
|
+
type: string;
|
|
21
|
+
}): State;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/store/reducer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,KAAK,gBAAgB,GAAG,CAAE,OAAO,EAAE,sBAAsB,KAAM,IAAI,CAAC;AAEpE,MAAM,WAAW,KAAK;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAClC;AAED,eAAO,MAAM,aAAa,EAAE,KAI3B,CAAC;AAEF,KAAK,MAAM,GACR;IACA,IAAI,EAAE,yBAAyB,CAAC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACjC,GACD;IAAE,IAAI,EAAE,0BAA0B,CAAA;CAAE,CAAC;AAExC,MAAM,CAAC,OAAO,UAAU,OAAO,CAC9B,KAAK,EAAE,KAAK,YAAgB,EAC5B,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B,KAAK,CAiBP"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { State } from './reducer';
|
|
5
|
+
export declare function isOpen(state: State): boolean;
|
|
6
|
+
export declare function getId(state: State): number | null;
|
|
7
|
+
export declare function getOnUpdate(state: State): ((updated: import("./actions").MediaEditorModalUpdate) => void) | null;
|
|
8
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC,wBAAgB,MAAM,CAAE,KAAK,EAAE,KAAK,GAAI,OAAO,CAE9C;AAED,wBAAgB,KAAK,CAAE,KAAK,EAAE,KAAK,GAAI,MAAM,GAAG,IAAI,CAEnD;AAED,wBAAgB,WAAW,CAAE,KAAK,EAAE,KAAK,0EAExC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/media-editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Media editor components for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -38,13 +38,27 @@
|
|
|
38
38
|
"types": "build-types",
|
|
39
39
|
"sideEffects": [
|
|
40
40
|
"build-style/**",
|
|
41
|
-
"src/**/*.scss"
|
|
41
|
+
"src/**/*.scss",
|
|
42
|
+
"src/store/index.ts",
|
|
43
|
+
"build/store/index.cjs",
|
|
44
|
+
"build-module/store/index.mjs"
|
|
42
45
|
],
|
|
43
46
|
"dependencies": {
|
|
44
|
-
"@wordpress/
|
|
45
|
-
"@wordpress/
|
|
46
|
-
"@wordpress/
|
|
47
|
-
"@wordpress/
|
|
47
|
+
"@wordpress/api-fetch": "^7.45.0",
|
|
48
|
+
"@wordpress/base-styles": "^7.0.0",
|
|
49
|
+
"@wordpress/components": "^33.0.0",
|
|
50
|
+
"@wordpress/core-data": "^7.45.0",
|
|
51
|
+
"@wordpress/data": "^10.45.0",
|
|
52
|
+
"@wordpress/dataviews": "^14.2.0",
|
|
53
|
+
"@wordpress/element": "^6.45.0",
|
|
54
|
+
"@wordpress/i18n": "^6.18.0",
|
|
55
|
+
"@wordpress/icons": "^13.0.0",
|
|
56
|
+
"@wordpress/interface": "^9.30.0",
|
|
57
|
+
"@wordpress/notices": "^5.45.0",
|
|
58
|
+
"@wordpress/private-apis": "^1.45.0",
|
|
59
|
+
"@wordpress/ui": "^0.12.0",
|
|
60
|
+
"clsx": "^2.1.1",
|
|
61
|
+
"gl-matrix": "^3.4.3"
|
|
48
62
|
},
|
|
49
63
|
"peerDependencies": {
|
|
50
64
|
"react": "^18.0.0"
|
|
@@ -52,5 +66,5 @@
|
|
|
52
66
|
"publishConfig": {
|
|
53
67
|
"access": "public"
|
|
54
68
|
},
|
|
55
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "8c229eaed0e88c9827e2da3d73a78f9ddd77714b"
|
|
56
70
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useMediaEditorContext } from '../media-editor-provider';
|
|
5
|
+
import { getMediaTypeFromMimeType } from '../../utils';
|
|
6
|
+
import { Cropper, useCropper } from '../../image-editor';
|
|
7
|
+
|
|
8
|
+
export interface MediaEditorCanvasProps {
|
|
9
|
+
/** Fixed aspect ratio (width / height). `undefined` means free. */
|
|
10
|
+
aspectRatio?: number;
|
|
11
|
+
/** Enable freeform crop mode (resize handles). */
|
|
12
|
+
freeformCrop?: boolean;
|
|
13
|
+
/** Whether external placement activity should reveal the grid. */
|
|
14
|
+
isPlacementActive?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Editing surface for image media in the media editor modal. Pulls its
|
|
19
|
+
* cropper controller from the surrounding `<CropperProvider>` so the
|
|
20
|
+
* bottom bar and Crop sidebar tab share the same state.
|
|
21
|
+
*
|
|
22
|
+
* Returns `null` for missing or non-image media so the modal's outer
|
|
23
|
+
* guards can render a spinner or fall through to `<MediaPreview>`.
|
|
24
|
+
* @param props
|
|
25
|
+
* @param props.aspectRatio
|
|
26
|
+
* @param props.freeformCrop
|
|
27
|
+
* @param props.isPlacementActive
|
|
28
|
+
*/
|
|
29
|
+
export default function MediaEditorCanvas( {
|
|
30
|
+
aspectRatio,
|
|
31
|
+
freeformCrop,
|
|
32
|
+
isPlacementActive = false,
|
|
33
|
+
}: MediaEditorCanvasProps ) {
|
|
34
|
+
const { media } = useMediaEditorContext();
|
|
35
|
+
const controller = useCropper();
|
|
36
|
+
|
|
37
|
+
const mediaUrl = media?.source_url;
|
|
38
|
+
const mediaType = getMediaTypeFromMimeType( media?.mime_type );
|
|
39
|
+
|
|
40
|
+
if ( ! mediaUrl || mediaType.type !== 'image' ) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className="media-editor-canvas">
|
|
46
|
+
<Cropper
|
|
47
|
+
src={ mediaUrl }
|
|
48
|
+
controller={ controller }
|
|
49
|
+
aspectRatio={ aspectRatio }
|
|
50
|
+
freeformCrop={ freeformCrop }
|
|
51
|
+
showGrid="interactive"
|
|
52
|
+
isPlacementActive={ isPlacementActive }
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The canvas wrapper fills the modal's canvas area so the cropper has a
|
|
2
|
+
// sized parent (the cropper uses 100% width/height of its container).
|
|
3
|
+
// `position: relative` establishes a stacking context for any future
|
|
4
|
+
// overlays rendered inside the canvas.
|
|
5
|
+
.media-editor-canvas {
|
|
6
|
+
position: relative;
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 100%;
|
|
9
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
RangeControl,
|
|
6
|
+
SelectControl,
|
|
7
|
+
ToggleControl,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
import { Stack } from '@wordpress/ui';
|
|
10
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { useCropper } from '../../image-editor';
|
|
16
|
+
import {
|
|
17
|
+
DEFAULT_ASPECT_RATIOS,
|
|
18
|
+
MAX_ZOOM,
|
|
19
|
+
MIN_ZOOM,
|
|
20
|
+
ORIGINAL_ASPECT_RATIO,
|
|
21
|
+
} from '../../image-editor/core/constants';
|
|
22
|
+
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
23
|
+
|
|
24
|
+
export interface MediaEditorCropPanelProps {
|
|
25
|
+
/**
|
|
26
|
+
* Selected aspect-ratio preset value as a string (so it round-trips
|
|
27
|
+
* through `<SelectControl>`). `'0'` = free, `'-1'` = original, any
|
|
28
|
+
* positive number = fixed ratio.
|
|
29
|
+
*/
|
|
30
|
+
aspectRatioValue: string;
|
|
31
|
+
/** Setter for the aspect-ratio preset value. */
|
|
32
|
+
onAspectRatioChange: ( value: string ) => void;
|
|
33
|
+
/** Whether the cropper is in freeform (resize-handle) mode. */
|
|
34
|
+
freeformCrop: boolean;
|
|
35
|
+
/** Setter for freeform mode. */
|
|
36
|
+
onFreeformChange: ( value: boolean ) => void;
|
|
37
|
+
/** Signal that a placement-oriented control is being adjusted. */
|
|
38
|
+
onPlacementControlInteraction?: () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Fixed aspect-ratio presets to display after Free and Original. When
|
|
41
|
+
* omitted, the media editor's default fixed-ratio presets are used.
|
|
42
|
+
*/
|
|
43
|
+
aspectRatioPresets?: AspectRatioPreset[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Resolve an aspect-ratio preset value into a number suitable for
|
|
48
|
+
* `<Cropper aspectRatio=...>`. Returns `undefined` for Free (no lock).
|
|
49
|
+
*
|
|
50
|
+
* @param value Preset value as a string.
|
|
51
|
+
* @param imageAspectRatio Image's natural width / height — used for
|
|
52
|
+
* the Original preset.
|
|
53
|
+
*/
|
|
54
|
+
export function resolveAspectRatio(
|
|
55
|
+
value: string,
|
|
56
|
+
imageAspectRatio: number | null
|
|
57
|
+
): number | undefined {
|
|
58
|
+
const num = parseFloat( value );
|
|
59
|
+
if ( num === 0 ) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
if ( num === ORIGINAL_ASPECT_RATIO && imageAspectRatio ) {
|
|
63
|
+
return imageAspectRatio;
|
|
64
|
+
}
|
|
65
|
+
if ( num > 0 ) {
|
|
66
|
+
return num;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sidebar panel for crop-shape controls — aspect-ratio presets and
|
|
73
|
+
* freeform toggle. The tactile verbs (rotate, flip) live in the
|
|
74
|
+
* bottom toolbar instead.
|
|
75
|
+
* @param props
|
|
76
|
+
* @param props.aspectRatioValue
|
|
77
|
+
* @param props.onAspectRatioChange
|
|
78
|
+
* @param props.freeformCrop
|
|
79
|
+
* @param props.onFreeformChange
|
|
80
|
+
* @param props.onPlacementControlInteraction
|
|
81
|
+
* @param props.aspectRatioPresets
|
|
82
|
+
*/
|
|
83
|
+
export default function MediaEditorCropPanel( {
|
|
84
|
+
aspectRatioValue,
|
|
85
|
+
onAspectRatioChange,
|
|
86
|
+
freeformCrop,
|
|
87
|
+
onFreeformChange,
|
|
88
|
+
onPlacementControlInteraction,
|
|
89
|
+
aspectRatioPresets,
|
|
90
|
+
}: MediaEditorCropPanelProps ) {
|
|
91
|
+
const { state, setZoom } = useCropper();
|
|
92
|
+
const aspectRatioOptions = [
|
|
93
|
+
...DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value <= 0 ),
|
|
94
|
+
...( aspectRatioPresets ??
|
|
95
|
+
DEFAULT_ASPECT_RATIOS.filter( ( preset ) => preset.value > 0 ) ),
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Stack direction="column" gap="md">
|
|
100
|
+
<RangeControl
|
|
101
|
+
__next40pxDefaultSize
|
|
102
|
+
__nextHasNoMarginBottom
|
|
103
|
+
label={ __( 'Zoom' ) }
|
|
104
|
+
min={ MIN_ZOOM }
|
|
105
|
+
max={ MAX_ZOOM }
|
|
106
|
+
step={ 0.1 }
|
|
107
|
+
value={ state.zoom }
|
|
108
|
+
onChange={ ( value ) => {
|
|
109
|
+
onPlacementControlInteraction?.();
|
|
110
|
+
setZoom( typeof value === 'number' ? value : MIN_ZOOM );
|
|
111
|
+
} }
|
|
112
|
+
renderTooltipContent={ ( value ) => {
|
|
113
|
+
const zoom = typeof value === 'number' ? value : MIN_ZOOM;
|
|
114
|
+
return sprintf(
|
|
115
|
+
/* translators: %d: zoom level as a percentage. */
|
|
116
|
+
__( '%d%%' ),
|
|
117
|
+
Math.round( zoom * 100 )
|
|
118
|
+
);
|
|
119
|
+
} }
|
|
120
|
+
/>
|
|
121
|
+
<SelectControl
|
|
122
|
+
__next40pxDefaultSize
|
|
123
|
+
__nextHasNoMarginBottom
|
|
124
|
+
label={ __( 'Aspect ratio' ) }
|
|
125
|
+
value={ aspectRatioValue }
|
|
126
|
+
onChange={ onAspectRatioChange }
|
|
127
|
+
options={ aspectRatioOptions.map( ( preset ) => ( {
|
|
128
|
+
label: preset.label,
|
|
129
|
+
value: preset.value.toString(),
|
|
130
|
+
} ) ) }
|
|
131
|
+
/>
|
|
132
|
+
<ToggleControl
|
|
133
|
+
__nextHasNoMarginBottom
|
|
134
|
+
label={ __( 'Freeform crop' ) }
|
|
135
|
+
help={ __(
|
|
136
|
+
'Drag the crop edges to resize freely. When off, the crop is fixed to the selected ratio.'
|
|
137
|
+
) }
|
|
138
|
+
checked={ freeformCrop }
|
|
139
|
+
onChange={ onFreeformChange }
|
|
140
|
+
/>
|
|
141
|
+
</Stack>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperState, Size } from '../../image-editor';
|
|
5
|
+
import { getRotatedBBox } from '../../image-editor/core/camera';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A single modifier in the Core REST `/edit` payload. Order is
|
|
9
|
+
* significant — the server applies modifiers sequentially (see
|
|
10
|
+
* `WP_REST_Attachments_Controller::edit_media_item`).
|
|
11
|
+
*
|
|
12
|
+
* Shape/units:
|
|
13
|
+
* - `flip`: booleans per axis. Applied first in this module's output.
|
|
14
|
+
* - `rotate`: `angle` in degrees, clockwise-positive (matches the
|
|
15
|
+
* cropper's own convention; Core negates it internally for
|
|
16
|
+
* `WP_Image_Editor::rotate`, which is counterclockwise-positive).
|
|
17
|
+
* - `crop`: percentages (0–100) of the image's dimensions **at the
|
|
18
|
+
* moment the crop is applied**. Because modifiers are applied in
|
|
19
|
+
* order, after a preceding `rotate` the server's
|
|
20
|
+
* `WP_Image_Editor::get_size()` reports the full post-rotate AABB,
|
|
21
|
+
* so the percentages are of that AABB. Origin is top-left.
|
|
22
|
+
*/
|
|
23
|
+
export type Modifier =
|
|
24
|
+
| {
|
|
25
|
+
type: 'flip';
|
|
26
|
+
args: { flip: { horizontal: boolean; vertical: boolean } };
|
|
27
|
+
}
|
|
28
|
+
| { type: 'rotate'; args: { angle: number } }
|
|
29
|
+
| {
|
|
30
|
+
type: 'crop';
|
|
31
|
+
args: { left: number; top: number; width: number; height: number };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Tolerance (percent) used to decide whether a crop rect is effectively
|
|
36
|
+
* full-frame. Sub-pixel / float-ulp deltas below this value are treated
|
|
37
|
+
* as no crop. Matches the historical threshold used by the legacy
|
|
38
|
+
* `use-save-image.js` (which compared against `99.9`).
|
|
39
|
+
*/
|
|
40
|
+
const CROP_TOLERANCE = 0.1;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Build a Core-compatible modifiers array from the cropper state.
|
|
44
|
+
*
|
|
45
|
+
* Emits `[flip, rotate, crop]` in that order. Identity operations are
|
|
46
|
+
* pruned — an absent flip, a rotation that normalizes to 0°, and a crop
|
|
47
|
+
* rect that covers (within tolerance) the full post-rotate AABB each
|
|
48
|
+
* produce no modifier. An identity state (fresh image, no edits) returns
|
|
49
|
+
* an empty array; callers can use that to skip the `/edit` call.
|
|
50
|
+
*
|
|
51
|
+
* Frames and math:
|
|
52
|
+
*
|
|
53
|
+
* The cropper's `cropRect` is stored as fractions of the **snap-rotation**
|
|
54
|
+
* bounding box (the stencil-reference frame — see `createCamera` /
|
|
55
|
+
* `createExportCamera`). Pan is in that frame; zoom scales the image
|
|
56
|
+
* beneath a fixed stencil. Two conversions are needed to reach the frame
|
|
57
|
+
* Core's crop modifier applies against:
|
|
58
|
+
*
|
|
59
|
+
* 1. Express the stencil rect in snap-AABB **pixels**:
|
|
60
|
+
* Image screen-normalized top-left with zoom/pan is
|
|
61
|
+
* `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the
|
|
62
|
+
* inverse of that transform applied to `cropRect`.
|
|
63
|
+
*
|
|
64
|
+
* 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs
|
|
65
|
+
* share the source-image center, so the conversion is a pure
|
|
66
|
+
* translation by `(fullCenter - snapCenter)`. Finally, express the
|
|
67
|
+
* translated rect as percentages of the full AABB.
|
|
68
|
+
*
|
|
69
|
+
* Rotation sign: the cropper composes `flip · R(θ)` on the source (see
|
|
70
|
+
* `createExportCamera` — rotate then flip). Core's `[flip, rotate]`
|
|
71
|
+
* applies the opposite order: `R(θ') · flip`. For both to land on the
|
|
72
|
+
* same pixels we invert the rotation sign when exactly one flip axis
|
|
73
|
+
* is set (`flip_h · R(θ) = R(-θ) · flip_h`). Both-or-neither flips
|
|
74
|
+
* leave the sign alone because `flip_h · flip_v = -I` commutes with
|
|
75
|
+
* rotation.
|
|
76
|
+
*
|
|
77
|
+
* @param state Current cropper state.
|
|
78
|
+
* @param imageSize Natural dimensions of the source image.
|
|
79
|
+
* @return Ordered modifier array; empty when nothing is server-relevant.
|
|
80
|
+
*/
|
|
81
|
+
export function buildModifiers(
|
|
82
|
+
state: CropperState,
|
|
83
|
+
imageSize: Size
|
|
84
|
+
): Modifier[] {
|
|
85
|
+
const modifiers: Modifier[] = [];
|
|
86
|
+
|
|
87
|
+
if ( imageSize.width === 0 || imageSize.height === 0 ) {
|
|
88
|
+
return modifiers;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const { cropRect, pan, zoom, flip } = state;
|
|
92
|
+
const hasFlipH = flip.horizontal;
|
|
93
|
+
const hasFlipV = flip.vertical;
|
|
94
|
+
|
|
95
|
+
if ( hasFlipH || hasFlipV ) {
|
|
96
|
+
modifiers.push( {
|
|
97
|
+
type: 'flip',
|
|
98
|
+
args: { flip: { horizontal: hasFlipH, vertical: hasFlipV } },
|
|
99
|
+
} );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const rawAngle = ( ( state.rotation % 360 ) + 360 ) % 360;
|
|
103
|
+
// Invert the sign for single-axis flips so Core's `flip → rotate`
|
|
104
|
+
// pipeline matches the cropper's `rotate → flip` composition.
|
|
105
|
+
const singleAxisFlip = hasFlipH !== hasFlipV;
|
|
106
|
+
const signedAngle = singleAxisFlip ? ( 360 - rawAngle ) % 360 : rawAngle;
|
|
107
|
+
if ( signedAngle !== 0 ) {
|
|
108
|
+
modifiers.push( { type: 'rotate', args: { angle: signedAngle } } );
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const snapRotation = Math.round( state.rotation / 90 ) * 90;
|
|
112
|
+
const { width: snapW, height: snapH } = getRotatedBBox(
|
|
113
|
+
imageSize.width,
|
|
114
|
+
imageSize.height,
|
|
115
|
+
snapRotation
|
|
116
|
+
);
|
|
117
|
+
const { width: fullW, height: fullH } = getRotatedBBox(
|
|
118
|
+
imageSize.width,
|
|
119
|
+
imageSize.height,
|
|
120
|
+
state.rotation
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
// Stencil rect in snap-AABB pixels. Inverts `createExportCamera`'s
|
|
124
|
+
// pan/zoom composition to recover the pixel rectangle the stencil
|
|
125
|
+
// framed in that frame.
|
|
126
|
+
const imgLeft = 0.5 + pan.x - zoom / 2;
|
|
127
|
+
const imgTop = 0.5 + pan.y - zoom / 2;
|
|
128
|
+
const snapX = ( ( cropRect.x - imgLeft ) / zoom ) * snapW;
|
|
129
|
+
const snapY = ( ( cropRect.y - imgTop ) / zoom ) * snapH;
|
|
130
|
+
const widthPx = ( cropRect.width / zoom ) * snapW;
|
|
131
|
+
const heightPx = ( cropRect.height / zoom ) * snapH;
|
|
132
|
+
|
|
133
|
+
// Translate to the full AABB (both centered on source).
|
|
134
|
+
const offsetX = ( fullW - snapW ) / 2;
|
|
135
|
+
const offsetY = ( fullH - snapH ) / 2;
|
|
136
|
+
const fullX = snapX + offsetX;
|
|
137
|
+
const fullY = snapY + offsetY;
|
|
138
|
+
|
|
139
|
+
// Percentages of the full AABB — Core's crop frame after rotate.
|
|
140
|
+
const leftPct = ( fullX / fullW ) * 100;
|
|
141
|
+
const topPct = ( fullY / fullH ) * 100;
|
|
142
|
+
const widthPct = ( widthPx / fullW ) * 100;
|
|
143
|
+
const heightPct = ( heightPx / fullH ) * 100;
|
|
144
|
+
|
|
145
|
+
const coversFullFrame =
|
|
146
|
+
leftPct <= CROP_TOLERANCE &&
|
|
147
|
+
topPct <= CROP_TOLERANCE &&
|
|
148
|
+
widthPct >= 100 - CROP_TOLERANCE &&
|
|
149
|
+
heightPct >= 100 - CROP_TOLERANCE;
|
|
150
|
+
|
|
151
|
+
if ( ! coversFullFrame ) {
|
|
152
|
+
modifiers.push( {
|
|
153
|
+
type: 'crop',
|
|
154
|
+
args: {
|
|
155
|
+
left: leftPct,
|
|
156
|
+
top: topPct,
|
|
157
|
+
width: widthPct,
|
|
158
|
+
height: heightPct,
|
|
159
|
+
},
|
|
160
|
+
} );
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return modifiers;
|
|
164
|
+
}
|