@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,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperState, Size } from '../../image-editor';
|
|
5
|
+
/**
|
|
6
|
+
* A single modifier in the Core REST `/edit` payload. Order is
|
|
7
|
+
* significant — the server applies modifiers sequentially (see
|
|
8
|
+
* `WP_REST_Attachments_Controller::edit_media_item`).
|
|
9
|
+
*
|
|
10
|
+
* Shape/units:
|
|
11
|
+
* - `flip`: booleans per axis. Applied first in this module's output.
|
|
12
|
+
* - `rotate`: `angle` in degrees, clockwise-positive (matches the
|
|
13
|
+
* cropper's own convention; Core negates it internally for
|
|
14
|
+
* `WP_Image_Editor::rotate`, which is counterclockwise-positive).
|
|
15
|
+
* - `crop`: percentages (0–100) of the image's dimensions **at the
|
|
16
|
+
* moment the crop is applied**. Because modifiers are applied in
|
|
17
|
+
* order, after a preceding `rotate` the server's
|
|
18
|
+
* `WP_Image_Editor::get_size()` reports the full post-rotate AABB,
|
|
19
|
+
* so the percentages are of that AABB. Origin is top-left.
|
|
20
|
+
*/
|
|
21
|
+
export type Modifier = {
|
|
22
|
+
type: 'flip';
|
|
23
|
+
args: {
|
|
24
|
+
flip: {
|
|
25
|
+
horizontal: boolean;
|
|
26
|
+
vertical: boolean;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
} | {
|
|
30
|
+
type: 'rotate';
|
|
31
|
+
args: {
|
|
32
|
+
angle: number;
|
|
33
|
+
};
|
|
34
|
+
} | {
|
|
35
|
+
type: 'crop';
|
|
36
|
+
args: {
|
|
37
|
+
left: number;
|
|
38
|
+
top: number;
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Build a Core-compatible modifiers array from the cropper state.
|
|
45
|
+
*
|
|
46
|
+
* Emits `[flip, rotate, crop]` in that order. Identity operations are
|
|
47
|
+
* pruned — an absent flip, a rotation that normalizes to 0°, and a crop
|
|
48
|
+
* rect that covers (within tolerance) the full post-rotate AABB each
|
|
49
|
+
* produce no modifier. An identity state (fresh image, no edits) returns
|
|
50
|
+
* an empty array; callers can use that to skip the `/edit` call.
|
|
51
|
+
*
|
|
52
|
+
* Frames and math:
|
|
53
|
+
*
|
|
54
|
+
* The cropper's `cropRect` is stored as fractions of the **snap-rotation**
|
|
55
|
+
* bounding box (the stencil-reference frame — see `createCamera` /
|
|
56
|
+
* `createExportCamera`). Pan is in that frame; zoom scales the image
|
|
57
|
+
* beneath a fixed stencil. Two conversions are needed to reach the frame
|
|
58
|
+
* Core's crop modifier applies against:
|
|
59
|
+
*
|
|
60
|
+
* 1. Express the stencil rect in snap-AABB **pixels**:
|
|
61
|
+
* Image screen-normalized top-left with zoom/pan is
|
|
62
|
+
* `(0.5 + pan - zoom/2)`; the stencil's pixel footprint is the
|
|
63
|
+
* inverse of that transform applied to `cropRect`.
|
|
64
|
+
*
|
|
65
|
+
* 2. Translate from snap-AABB coords to full-AABB coords. Both AABBs
|
|
66
|
+
* share the source-image center, so the conversion is a pure
|
|
67
|
+
* translation by `(fullCenter - snapCenter)`. Finally, express the
|
|
68
|
+
* translated rect as percentages of the full AABB.
|
|
69
|
+
*
|
|
70
|
+
* Rotation sign: the cropper composes `flip · R(θ)` on the source (see
|
|
71
|
+
* `createExportCamera` — rotate then flip). Core's `[flip, rotate]`
|
|
72
|
+
* applies the opposite order: `R(θ') · flip`. For both to land on the
|
|
73
|
+
* same pixels we invert the rotation sign when exactly one flip axis
|
|
74
|
+
* is set (`flip_h · R(θ) = R(-θ) · flip_h`). Both-or-neither flips
|
|
75
|
+
* leave the sign alone because `flip_h · flip_v = -I` commutes with
|
|
76
|
+
* rotation.
|
|
77
|
+
*
|
|
78
|
+
* @param state Current cropper state.
|
|
79
|
+
* @param imageSize Natural dimensions of the source image.
|
|
80
|
+
* @return Ordered modifier array; empty when nothing is server-relevant.
|
|
81
|
+
*/
|
|
82
|
+
export declare function buildModifiers(state: CropperState, imageSize: Size): Modifier[];
|
|
83
|
+
//# sourceMappingURL=build-modifiers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-modifiers.d.ts","sourceRoot":"","sources":["../../../src/components/media-editor-modal/build-modifiers.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,QAAQ,GACjB;IACA,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QAAE,IAAI,EAAE;YAAE,UAAU,EAAE,OAAO,CAAC;YAAC,QAAQ,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAC;CAC1D,GACD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAC3C;IACA,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE,CAAC;AAUL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,IAAI,GACb,QAAQ,EAAE,CAgFZ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Field } from '@wordpress/dataviews';
|
|
2
|
+
import type { Media } from '../media-editor-provider';
|
|
3
|
+
import type { AspectRatioPreset } from '../../image-editor/core/constants';
|
|
4
|
+
interface MediaEditorModalProps {
|
|
5
|
+
/**
|
|
6
|
+
* Attachment fields to render in the Details tab.
|
|
7
|
+
*
|
|
8
|
+
* Passed from the editor layer (which owns the `usePostFields` hook),
|
|
9
|
+
* since `@wordpress/media-editor` cannot depend on `@wordpress/editor`.
|
|
10
|
+
*/
|
|
11
|
+
fields?: Field<Media>[];
|
|
12
|
+
/**
|
|
13
|
+
* Fixed aspect-ratio presets for image cropping. Free and Original are
|
|
14
|
+
* always provided by the modal.
|
|
15
|
+
*/
|
|
16
|
+
aspectRatioPresets?: AspectRatioPreset[];
|
|
17
|
+
}
|
|
18
|
+
export declare function MediaEditorModal({ fields, aspectRatioPresets, }: MediaEditorModalProps): import("react").JSX.Element | null;
|
|
19
|
+
export default MediaEditorModal;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-editor-modal/index.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAalD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAatD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAyB3E,UAAU,qBAAqB;IAC9B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,KAAK,CAAE,KAAK,CAAE,EAAE,CAAC;IAC1B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACzC;AAqeD,wBAAgB,gBAAgB,CAAE,EACjC,MAAW,EACX,kBAAkB,GAClB,EAAE,qBAAqB,sCAyDvB;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface MediaEditorToolbarProps {
|
|
2
|
+
/**
|
|
3
|
+
* Extra work to run when the user clicks Reset — e.g. clearing
|
|
4
|
+
* aspect-ratio / freeform state that lives outside the cropper
|
|
5
|
+
* controller.
|
|
6
|
+
*/
|
|
7
|
+
onReset?: () => void;
|
|
8
|
+
/** Signal that a placement-oriented control is being adjusted. */
|
|
9
|
+
onPlacementControlInteraction?: () => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Toolbar for the media editor modal. Hosts the tactile cropper verbs —
|
|
13
|
+
* rotate, flip, fine rotation, reset — so they stay within thumb reach
|
|
14
|
+
* when the toolbar sits at the bottom of the modal. Aspect-ratio presets
|
|
15
|
+
* and freeform toggle live in the Crop sidebar tab instead.
|
|
16
|
+
* @param props
|
|
17
|
+
* @param props.onReset
|
|
18
|
+
* @param props.onPlacementControlInteraction
|
|
19
|
+
*/
|
|
20
|
+
export default function MediaEditorToolbar({ onReset, onPlacementControlInteraction, }: MediaEditorToolbarProps): import("react").JSX.Element;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-editor-toolbar/index.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,uBAAuB;IACvC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,kEAAkE;IAClE,6BAA6B,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3C;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAE,EAC3C,OAAO,EACP,6BAA6B,GAC7B,EAAE,uBAAuB,+BA2GzB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperState, NormalizedPoint, Size, Camera } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Compute the axis-aligned bounding box of a rectangle after rotation.
|
|
7
|
+
*
|
|
8
|
+
* @param width The width of the rectangle.
|
|
9
|
+
* @param height The height of the rectangle.
|
|
10
|
+
* @param rotation The rotation angle in degrees.
|
|
11
|
+
* @return The bounding box size after rotation.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getRotatedBBox(width: number, height: number, rotation: number): Size;
|
|
14
|
+
/**
|
|
15
|
+
* Compute the fitted (unrotated) image element dimensions and the visual
|
|
16
|
+
* (rotated) bounding box dimensions for a given container, image, and rotation.
|
|
17
|
+
*
|
|
18
|
+
* This is the same "contain" fit logic used by createCamera, extracted so
|
|
19
|
+
* cropper.tsx can size the <img> element and position overlays without
|
|
20
|
+
* duplicating the math.
|
|
21
|
+
*
|
|
22
|
+
* @param containerSize The container dimensions in pixels.
|
|
23
|
+
* @param imageSize The natural image dimensions in pixels.
|
|
24
|
+
* @param rotation The rotation angle in degrees.
|
|
25
|
+
* @return The fitted element size and visual bounding box size.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getImageFit(containerSize: Size, imageSize: Size, rotation: number): {
|
|
28
|
+
elementSize: Size;
|
|
29
|
+
visualSize: Size;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Compose a camera matrix from cropper state, container, and image dimensions.
|
|
33
|
+
*
|
|
34
|
+
* The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.
|
|
35
|
+
* Input (0,0) = image top-left, (1,1) = image bottom-right.
|
|
36
|
+
*
|
|
37
|
+
* Composition order (left-to-right = outermost first, applied last to point):
|
|
38
|
+
* M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels
|
|
39
|
+
*
|
|
40
|
+
* Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`
|
|
41
|
+
* are viewport-relative: the image mirrors across the viewport's vertical /
|
|
42
|
+
* horizontal axis regardless of current rotation.
|
|
43
|
+
*
|
|
44
|
+
* @param state The current cropper state (zoom, rotation, flip, crop).
|
|
45
|
+
* @param containerSize The size of the container in pixels.
|
|
46
|
+
* @param imageSize The natural size of the image in pixels.
|
|
47
|
+
* @return The composed camera matrix.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createCamera(state: CropperState, containerSize: Size, imageSize: Size): Camera;
|
|
50
|
+
/**
|
|
51
|
+
* Transform a normalized world point [0,1] to screen pixels.
|
|
52
|
+
*
|
|
53
|
+
* @param camera The camera matrix from createCamera.
|
|
54
|
+
* @param point The normalized world coordinate to transform.
|
|
55
|
+
* @return The screen pixel coordinate.
|
|
56
|
+
*/
|
|
57
|
+
export declare function worldToScreen(camera: Camera, point: NormalizedPoint): {
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Transform a screen pixel point to normalized world coordinates [0,1].
|
|
63
|
+
*
|
|
64
|
+
* @param camera The camera matrix from createCamera.
|
|
65
|
+
* @param point The screen pixel coordinate to transform.
|
|
66
|
+
* @param point.x The x component of the screen pixel coordinate.
|
|
67
|
+
* @param point.y The y component of the screen pixel coordinate.
|
|
68
|
+
* @return The normalized world coordinate.
|
|
69
|
+
*/
|
|
70
|
+
export declare function screenToWorld(camera: Camera, point: {
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
}): NormalizedPoint;
|
|
74
|
+
/**
|
|
75
|
+
* The bounding box of a transformed region in screen (pixel) space.
|
|
76
|
+
*/
|
|
77
|
+
export interface VisualBounds {
|
|
78
|
+
left: number;
|
|
79
|
+
top: number;
|
|
80
|
+
width: number;
|
|
81
|
+
height: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])
|
|
85
|
+
* after applying the camera transform.
|
|
86
|
+
*
|
|
87
|
+
* @param camera The camera matrix from createCamera.
|
|
88
|
+
* @return The screen-space bounding box of the full image.
|
|
89
|
+
*/
|
|
90
|
+
export declare function getVisibleBounds(camera: Camera): VisualBounds;
|
|
91
|
+
/**
|
|
92
|
+
* Compose a camera matrix for exporting to a canvas.
|
|
93
|
+
*
|
|
94
|
+
* The resulting matrix maps image-pixel coordinates directly to output-canvas
|
|
95
|
+
* coordinates. Apply it with `ctx.setTransform( ...camera )` then
|
|
96
|
+
* `ctx.drawImage( image, 0, 0 )`.
|
|
97
|
+
*
|
|
98
|
+
* The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:
|
|
99
|
+
* translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)
|
|
100
|
+
*
|
|
101
|
+
* @param state The current cropper state.
|
|
102
|
+
* @param imageSize The natural size of the source image in pixels.
|
|
103
|
+
* @param outputSize The desired output canvas size in pixels.
|
|
104
|
+
* @return The composed export camera matrix.
|
|
105
|
+
*/
|
|
106
|
+
export declare function createExportCamera(state: CropperState, imageSize: Size, outputSize: Size): Camera;
|
|
107
|
+
//# sourceMappingURL=camera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../../../src/image-editor/core/camera.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAQ3E;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACd,IAAI,CAQN;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAC1B,aAAa,EAAE,IAAI,EACnB,SAAS,EAAE,IAAI,EACf,QAAQ,EAAE,MAAM,GACd;IAAE,WAAW,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,IAAI,CAAA;CAAE,CAiCzC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,YAAY,EACnB,aAAa,EAAE,IAAI,EACnB,SAAS,EAAE,IAAI,GACb,MAAM,CA0ER;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,GACpB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAI1B;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7B,eAAe,CAKjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CACf;AAsCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAE,MAAM,EAAE,MAAM,GAAI,YAAY,CAO/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,IAAI,EACf,UAAU,EAAE,IAAI,GACd,MAAM,CA+CR"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperState } from './types';
|
|
5
|
+
export declare const MIN_ZOOM = 1;
|
|
6
|
+
export declare const MAX_ZOOM = 10;
|
|
7
|
+
/**
|
|
8
|
+
* Maximum free-rotation offset in degrees from the nearest 90° step.
|
|
9
|
+
* The rotation slider allows ±45° around the current cardinal angle.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAX_ROTATION_OFFSET = 45;
|
|
12
|
+
export declare const DEFAULT_STATE: CropperState;
|
|
13
|
+
/**
|
|
14
|
+
* An aspect ratio preset with a human-readable label.
|
|
15
|
+
*/
|
|
16
|
+
export interface AspectRatioPreset {
|
|
17
|
+
/** Display label (e.g., "Square (1:1)"). */
|
|
18
|
+
label: string;
|
|
19
|
+
/** The aspect ratio value (width / height). 0 = free / original. */
|
|
20
|
+
value: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Default aspect ratio presets. Consumers can use these as-is, override
|
|
24
|
+
* with their own list, or extend with additional presets.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Use defaults:
|
|
28
|
+
* <CropControls presets={ DEFAULT_ASPECT_RATIOS } />
|
|
29
|
+
*
|
|
30
|
+
* // Custom presets:
|
|
31
|
+
* const socialPresets = [
|
|
32
|
+
* { label: 'Instagram Post', value: 1 },
|
|
33
|
+
* { label: 'Instagram Story', value: 9 / 16 },
|
|
34
|
+
* { label: 'YouTube Thumbnail', value: 16 / 9 },
|
|
35
|
+
* ];
|
|
36
|
+
*
|
|
37
|
+
* // Extend defaults:
|
|
38
|
+
* const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Sentinel value for "Original" aspect ratio — resolved at runtime
|
|
42
|
+
* to the image's natural width / height.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ORIGINAL_ASPECT_RATIO = -1;
|
|
45
|
+
export declare const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[];
|
|
46
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/image-editor/core/constants.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAwB,YAAY,EAAE,MAAM,SAAS,CAAC;AAElE,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,eAAO,MAAM,QAAQ,KAAK,CAAC;AAE3B;;;GAGG;AACH,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAmBtC,eAAO,MAAM,aAAa,EAAE,YAU3B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,eAAO,MAAM,qBAAqB,EAAE,iBAAiB,EAUpD,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperState, NormalizedRect, Size } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Compute the crop handle bounds in normalized visual space by finding the
|
|
7
|
+
* axis-aligned bounding box (AABB) of the actual image footprint at the
|
|
8
|
+
* current pan/zoom/rotation, then intersecting with the container viewport.
|
|
9
|
+
*
|
|
10
|
+
* Unlike a static centerline-based calculation, this accounts for the
|
|
11
|
+
* current pan position — if the user pans right, the left bound tightens
|
|
12
|
+
* because the image's left edge has moved right.
|
|
13
|
+
*
|
|
14
|
+
* @param state The current cropper state (crop, zoom, rotation, flip).
|
|
15
|
+
* @param elementSize The fitted (unrotated) image element dimensions in pixels.
|
|
16
|
+
* @param visualSize The visual (rotated) image bounding box in pixels.
|
|
17
|
+
* @param containerSize The container dimensions in pixels.
|
|
18
|
+
* @return The min/max x and y that a crop rect edge can reach in normalized space.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getCropBounds(state: CropperState, elementSize: Size, visualSize: Size, containerSize: Size): {
|
|
21
|
+
minX: number;
|
|
22
|
+
minY: number;
|
|
23
|
+
maxX: number;
|
|
24
|
+
maxY: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.
|
|
28
|
+
* If the crop rect is too large for the current zoom and rotation, it is scaled
|
|
29
|
+
* down proportionally and re-centered.
|
|
30
|
+
*
|
|
31
|
+
* Works in pixel-proportional space where the unrotated image is a×1.
|
|
32
|
+
*
|
|
33
|
+
* @param cropRect The crop rectangle in normalized coordinates.
|
|
34
|
+
* @param zoom The current zoom factor.
|
|
35
|
+
* @param rotation The rotation angle in degrees.
|
|
36
|
+
* @param imageAspectRatio The image width / height ratio.
|
|
37
|
+
* @return The restricted crop rectangle.
|
|
38
|
+
*/
|
|
39
|
+
export declare function restrictCropRect(cropRect: NormalizedRect, zoom: number, rotation: number, imageAspectRatio: number): NormalizedRect;
|
|
40
|
+
/**
|
|
41
|
+
* Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers
|
|
42
|
+
* the crop rectangle.
|
|
43
|
+
*
|
|
44
|
+
* Uses the camera matrix to project: builds a camera from the candidate state,
|
|
45
|
+
* maps the stencil corners (axis-aligned in the visual bounding box) to world
|
|
46
|
+
* space via the inverse camera, and checks that all world points lie within
|
|
47
|
+
* [0,1]×[0,1]. If any point is outside, computes the minimal pan correction.
|
|
48
|
+
*
|
|
49
|
+
* @param state The current cropper state.
|
|
50
|
+
* @param imageSize The natural size of the image in pixels.
|
|
51
|
+
* @param cropRect The crop rectangle in normalized coordinates.
|
|
52
|
+
* @return The restricted crop pan and zoom values.
|
|
53
|
+
*/
|
|
54
|
+
export declare function restrictPanZoom(state: CropperState, imageSize: Size, cropRect: NormalizedRect): {
|
|
55
|
+
pan: {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
};
|
|
59
|
+
zoom: number;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=containment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"containment.d.ts","sourceRoot":"","sources":["../../../src/image-editor/core/containment.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AA+ElE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,YAAY,EACnB,WAAW,EAAE,IAAI,EACjB,UAAU,EAAE,IAAI,EAChB,aAAa,EAAE,IAAI,GACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA4E5D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,gBAAgB,EAAE,MAAM,GACtB,cAAc,CA4ChB;AAcD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,IAAI,EACf,QAAQ,EAAE,cAAc,GACtB;IAAE,GAAG,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA2JjD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CropperState } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Load an image from a URL with CORS support.
|
|
7
|
+
*
|
|
8
|
+
* @param src - The image URL to load.
|
|
9
|
+
* @return A promise that resolves to the loaded HTMLImageElement.
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadImage(src: string): Promise<HTMLImageElement>;
|
|
12
|
+
/**
|
|
13
|
+
* Apply rectangular crop, rotation, and flip transforms to produce a canvas.
|
|
14
|
+
*
|
|
15
|
+
* Uses createExportCamera to compose the full transform matrix, then applies
|
|
16
|
+
* it in a single ctx.setTransform call before drawing the image.
|
|
17
|
+
*
|
|
18
|
+
* @param image - The source image element.
|
|
19
|
+
* @param state - The full cropper state containing crop, rotation, and flip settings.
|
|
20
|
+
* @return A canvas element containing the transformed and cropped image.
|
|
21
|
+
*/
|
|
22
|
+
export declare function renderToCanvas(image: HTMLImageElement, state: CropperState): HTMLCanvasElement;
|
|
23
|
+
/**
|
|
24
|
+
* Convert a canvas to a Blob with configurable MIME type and quality.
|
|
25
|
+
*
|
|
26
|
+
* @param canvas - The canvas to export.
|
|
27
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
28
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
29
|
+
* @return A promise that resolves to the canvas content as a Blob.
|
|
30
|
+
*/
|
|
31
|
+
export declare function canvasToBlob(canvas: HTMLCanvasElement, mimeType?: string, quality?: number): Promise<Blob>;
|
|
32
|
+
/**
|
|
33
|
+
* Convert a canvas to a data URL string.
|
|
34
|
+
*
|
|
35
|
+
* @param canvas - The canvas to export.
|
|
36
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
37
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
38
|
+
* @return The canvas content as a data URL string.
|
|
39
|
+
*/
|
|
40
|
+
export declare function canvasToDataURL(canvas: HTMLCanvasElement, mimeType?: string, quality?: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Load an image, render with transforms, and export as a Blob.
|
|
43
|
+
*
|
|
44
|
+
* Throws on failure so callers can distinguish error cases:
|
|
45
|
+
* - Image load failures (network errors, 404s) throw the native
|
|
46
|
+
* load error from the Image element.
|
|
47
|
+
* - Cross-origin failures manifest as tainted-canvas errors from
|
|
48
|
+
* `canvas.toBlob()` — the browser rejects reading pixel data
|
|
49
|
+
* from a canvas that drew an image without valid CORS headers.
|
|
50
|
+
* Ensure the source server sets `Access-Control-Allow-Origin`.
|
|
51
|
+
* - Canvas context creation failures throw a descriptive Error.
|
|
52
|
+
*
|
|
53
|
+
* Only works in browser environments (needs DOM / HTMLCanvasElement).
|
|
54
|
+
*
|
|
55
|
+
* @param src - The image URL to load.
|
|
56
|
+
* @param state - The cropper state with all transform settings.
|
|
57
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
58
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
59
|
+
* @return A promise that resolves to the exported Blob.
|
|
60
|
+
* @throws If the image fails to load, canvas creation fails, or
|
|
61
|
+
* the resulting canvas is tainted by CORS restrictions.
|
|
62
|
+
*/
|
|
63
|
+
export declare function exportCroppedImage(src: string, state: CropperState, mimeType?: string, quality?: number): Promise<Blob>;
|
|
64
|
+
/**
|
|
65
|
+
* Apply the cropper's transform (crop, rotation, flip, zoom) to an existing
|
|
66
|
+
* canvas or image source. This is the bridge for multi-step editing pipelines
|
|
67
|
+
* where an upstream tool (e.g., brightness/color adjustment) has already
|
|
68
|
+
* processed the image and you want to apply the crop on top.
|
|
69
|
+
*
|
|
70
|
+
* Accepts any CanvasImageSource: HTMLImageElement, HTMLCanvasElement,
|
|
71
|
+
* OffscreenCanvas, ImageBitmap, HTMLVideoElement, etc.
|
|
72
|
+
*
|
|
73
|
+
* @param source - The image source to crop/transform.
|
|
74
|
+
* @param sourceSize - The dimensions of the source (natural width/height).
|
|
75
|
+
* @param sourceSize.width - The width of the source in pixels.
|
|
76
|
+
* @param sourceSize.height - The height of the source in pixels.
|
|
77
|
+
* @param state - The cropper state with all transform settings.
|
|
78
|
+
* @param outputSize - Optional output size. Defaults to the crop region's natural pixel size.
|
|
79
|
+
* @param outputSize.width - The width of the output in pixels.
|
|
80
|
+
* @param outputSize.height - The height of the output in pixels.
|
|
81
|
+
* @return A canvas with the transforms applied.
|
|
82
|
+
*/
|
|
83
|
+
export declare function applyToCanvas(source: CanvasImageSource, sourceSize: {
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
}, state: CropperState, outputSize?: {
|
|
87
|
+
width: number;
|
|
88
|
+
height: number;
|
|
89
|
+
}): HTMLCanvasElement;
|
|
90
|
+
/**
|
|
91
|
+
* Download the cropped image as a file.
|
|
92
|
+
*
|
|
93
|
+
* Loads the source image, applies all transforms, and triggers a
|
|
94
|
+
* browser download via exportCroppedImage() + object URL + anchor click.
|
|
95
|
+
*
|
|
96
|
+
* Throws on export failure (see `exportCroppedImage`).
|
|
97
|
+
*
|
|
98
|
+
* @param src - The image URL to load.
|
|
99
|
+
* @param state - The cropper state with all transform settings.
|
|
100
|
+
* @param filename - The download filename. Defaults to 'cropped-image'.
|
|
101
|
+
* @param mimeType - The output MIME type. Defaults to 'image/png'.
|
|
102
|
+
* @param quality - The quality parameter for lossy formats (0-1). Defaults to DEFAULT_QUALITY.
|
|
103
|
+
* @return A promise that resolves when the download is triggered.
|
|
104
|
+
*/
|
|
105
|
+
export declare function downloadCroppedImage(src: string, state: CropperState, filename?: string, mimeType?: string, quality?: number): Promise<void>;
|
|
106
|
+
//# sourceMappingURL=canvas-renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-renderer.d.ts","sourceRoot":"","sources":["../../../../src/image-editor/core/export/canvas-renderer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAM7C;;;;;GAKG;AACH,wBAAgB,SAAS,CAAE,GAAG,EAAE,MAAM,GAAI,OAAO,CAAE,gBAAgB,CAAE,CAQpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,YAAY,GACjB,iBAAiB,CAqCnB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC3B,MAAM,EAAE,iBAAiB,EACzB,QAAQ,GAAE,MAAoB,EAC9B,OAAO,GAAE,MAAwB,GAC/B,OAAO,CAAE,IAAI,CAAE,CAcjB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,iBAAiB,EACzB,QAAQ,GAAE,MAAoB,EAC9B,OAAO,GAAE,MAAwB,GAC/B,MAAM,CAER;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,kBAAkB,CACvC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,QAAQ,GAAE,MAAoB,EAC9B,OAAO,GAAE,MAAwB,GAC/B,OAAO,CAAE,IAAI,CAAE,CAIjB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,iBAAiB,EACzB,UAAU,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC7C,KAAK,EAAE,YAAY,EACnB,UAAU,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC5C,iBAAiB,CA0CnB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,oBAAoB,CACzC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,QAAQ,GAAE,MAAwB,EAClC,QAAQ,GAAE,MAAoB,EAC9B,OAAO,GAAE,MAAwB,GAC/B,OAAO,CAAE,IAAI,CAAE,CASjB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { CropperState, TransformOperation, NormalizedPoint, NormalizedRect, Size, Flip, StencilProps, } from './types';
|
|
2
|
+
export { DEFAULT_STATE, DEFAULT_ASPECT_RATIOS, ORIGINAL_ASPECT_RATIO, } from './constants';
|
|
3
|
+
export type { AspectRatioPreset } from './constants';
|
|
4
|
+
export { getSourceRegion, getSourceRegionPercent } from './source-region';
|
|
5
|
+
export type { SourceRegion, SourceRegionPercent } from './source-region';
|
|
6
|
+
export { applyOperationToState, stateFromPipeline, } from './transforms/pipeline';
|
|
7
|
+
export { exportCroppedImage, applyToCanvas } from './export/canvas-renderer';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/image-editor/core/index.ts"],"names":[],"mappings":"AACA,YAAY,EACX,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,IAAI,EACJ,IAAI,EACJ,YAAY,GACZ,MAAM,SAAS,CAAC;AAOjB,OAAO,EACN,aAAa,EACb,qBAAqB,EACrB,qBAAqB,GACrB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGzE,OAAO,EACN,qBAAqB,EACrB,iBAAiB,GACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
|