@wordpress/media-editor 0.7.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/components/media-preview/index.cjs +1 -1
- package/build/components/media-preview/index.cjs.map +2 -2
- 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/components/media-preview/index.mjs +1 -1
- package/build-module/components/media-preview/index.mjs.map +2 -2
- 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/components/media-preview/index.d.ts.map +1 -1
- 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 -8
- 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/components/media-preview/index.tsx +2 -1
- 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,177 @@
|
|
|
1
|
+
import type { mat2d } from 'gl-matrix';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A 2D camera represented as a 2×3 affine transformation matrix (`mat2d`).
|
|
5
|
+
*
|
|
6
|
+
* This is not a camera object with properties — it's a raw 6-element matrix
|
|
7
|
+
* `[a, b, c, d, tx, ty]` that maps normalized world coordinates [0,1] to
|
|
8
|
+
* screen pixels. It composes pan, rotation, flip, zoom, and contain-fit
|
|
9
|
+
* into a single transform.
|
|
10
|
+
*
|
|
11
|
+
* Use `createCamera()` to build one from `CropperState`, then pass it to
|
|
12
|
+
* `worldToScreen()` / `screenToWorld()` for coordinate conversion.
|
|
13
|
+
*
|
|
14
|
+
* A 3D camera would use `mat4`; this is strictly 2D (no perspective).
|
|
15
|
+
*/
|
|
16
|
+
export type Camera = mat2d;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A point with normalized coordinates (0-1 range relative to image dimensions).
|
|
20
|
+
*/
|
|
21
|
+
export interface NormalizedPoint {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A rectangle with normalized coordinates (0-1 range).
|
|
28
|
+
* Origin is the top-left corner of the image.
|
|
29
|
+
*/
|
|
30
|
+
export interface NormalizedRect {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Width and height dimensions.
|
|
39
|
+
*/
|
|
40
|
+
export interface Size {
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Flip state for horizontal and vertical axes.
|
|
47
|
+
*/
|
|
48
|
+
export interface Flip {
|
|
49
|
+
horizontal: boolean;
|
|
50
|
+
vertical: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A JSON-serializable transform operation for the non-destructive pipeline.
|
|
55
|
+
*/
|
|
56
|
+
export type TransformOperation =
|
|
57
|
+
| { type: 'crop'; rect: NormalizedRect }
|
|
58
|
+
| { type: 'rotate'; degrees: number }
|
|
59
|
+
| { type: 'flip'; direction: 'horizontal' | 'vertical' }
|
|
60
|
+
| { type: 'zoom'; factor: number };
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Full cropper state.
|
|
64
|
+
*/
|
|
65
|
+
export interface CropperState {
|
|
66
|
+
/** The source image information. Null until an image is loaded. */
|
|
67
|
+
image: {
|
|
68
|
+
src: string;
|
|
69
|
+
naturalWidth: number;
|
|
70
|
+
naturalHeight: number;
|
|
71
|
+
} | null;
|
|
72
|
+
/**
|
|
73
|
+
* Image pan offset in normalized coordinates. Not the crop
|
|
74
|
+
* rectangle — that's `cropRect` below.
|
|
75
|
+
*/
|
|
76
|
+
pan: NormalizedPoint;
|
|
77
|
+
/** Zoom level. 1 = no zoom. */
|
|
78
|
+
zoom: number;
|
|
79
|
+
/** Rotation in degrees, normalized to 0-360. */
|
|
80
|
+
rotation: number;
|
|
81
|
+
/**
|
|
82
|
+
* Base pan/zoom/rotation — the pose the user last explicitly set.
|
|
83
|
+
*
|
|
84
|
+
* During continuous fine rotation (SET_ROTATION), every tick
|
|
85
|
+
* re-derives the transient `pan`/`zoom` from these base values
|
|
86
|
+
* rather than compounding on the previous tick. This prevents
|
|
87
|
+
* drift from accumulated containment clamping near image edges:
|
|
88
|
+
* rotating 0°→30°→0° returns to the exact starting pan, not a
|
|
89
|
+
* slightly-nudged version of it.
|
|
90
|
+
*
|
|
91
|
+
* These are updated by every action except SET_ROTATION itself —
|
|
92
|
+
* explicit zoom, pan, crop-rect, flip, and 90° snap all commit
|
|
93
|
+
* the post-containment state into base. SET_ROTATION reads from
|
|
94
|
+
* `basePan` and `baseRotation` to compute the new pan, and reads
|
|
95
|
+
* `baseZoom` as the zoom floor (enforceContainment may bump it up
|
|
96
|
+
* to cover the rotated crop, but never leaves it above baseZoom).
|
|
97
|
+
*/
|
|
98
|
+
basePan: NormalizedPoint;
|
|
99
|
+
baseZoom: number;
|
|
100
|
+
baseRotation: number;
|
|
101
|
+
/** Flip state. */
|
|
102
|
+
flip: Flip;
|
|
103
|
+
/** The crop rectangle in normalized coordinates. */
|
|
104
|
+
cropRect: NormalizedRect;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Internal reducer action union.
|
|
109
|
+
*
|
|
110
|
+
* This type is intentionally not exported from the image-editor public barrel.
|
|
111
|
+
* Consumers should drive state through the controller returned by
|
|
112
|
+
* `useCropperState()` or through serializable `TransformOperation` values.
|
|
113
|
+
*/
|
|
114
|
+
export type CropperAction =
|
|
115
|
+
/** Sets the loaded image metadata (natural size, src). */
|
|
116
|
+
| { type: 'SET_IMAGE'; payload: CropperState[ 'image' ] }
|
|
117
|
+
/** Sets the image pan offset. (Crop rectangle is SET_CROP_RECT.) */
|
|
118
|
+
| { type: 'SET_PAN'; payload: NormalizedPoint }
|
|
119
|
+
/** Sets the zoom level, clamped to [1, MAX_ZOOM]. */
|
|
120
|
+
| { type: 'SET_ZOOM'; payload: number }
|
|
121
|
+
/**
|
|
122
|
+
* Sets zoom and pan together atomically. Used by focal-point
|
|
123
|
+
* zoom (wheel, pinch) to keep a target point stationary while
|
|
124
|
+
* zoom changes.
|
|
125
|
+
*/
|
|
126
|
+
| {
|
|
127
|
+
type: 'SET_ZOOM_AT_POINT';
|
|
128
|
+
payload: { zoom: number; pan: NormalizedPoint };
|
|
129
|
+
}
|
|
130
|
+
/** Sets the absolute rotation angle in degrees. */
|
|
131
|
+
| { type: 'SET_ROTATION'; payload: number }
|
|
132
|
+
/** Rotates by +/-90 degrees (snap). */
|
|
133
|
+
| { type: 'SNAP_ROTATE_90'; payload: { direction: 1 | -1 } }
|
|
134
|
+
/** Sets the flip state. */
|
|
135
|
+
| { type: 'SET_FLIP'; payload: Flip }
|
|
136
|
+
/** Sets the crop rectangle. */
|
|
137
|
+
| { type: 'SET_CROP_RECT'; payload: NormalizedRect }
|
|
138
|
+
/** Settle animation after resize drag, recentering the crop rect. */
|
|
139
|
+
| { type: 'SETTLE_CROP' }
|
|
140
|
+
/** Applies a single pipeline transform via the reducer. */
|
|
141
|
+
| { type: 'APPLY_OPERATION'; payload: TransformOperation }
|
|
142
|
+
/** Resets to DEFAULT_STATE, optionally merging a partial override. */
|
|
143
|
+
| { type: 'RESET'; payload?: Partial< CropperState > };
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The contract for a pluggable stencil component.
|
|
147
|
+
* Stencils render the crop area overlay and handle resize interactions.
|
|
148
|
+
*/
|
|
149
|
+
export interface StencilProps {
|
|
150
|
+
/** The current crop rectangle in normalized coordinates. */
|
|
151
|
+
cropRect: NormalizedRect;
|
|
152
|
+
/** The container element dimensions in pixels. */
|
|
153
|
+
containerSize: Size;
|
|
154
|
+
/** The rendered image dimensions in pixels within the container. */
|
|
155
|
+
imageSize: Size;
|
|
156
|
+
/** Callback when the crop rectangle changes (during drag). */
|
|
157
|
+
onCropChange: ( rect: NormalizedRect ) => void;
|
|
158
|
+
/** Callback when a resize drag starts (pointerdown on handle). */
|
|
159
|
+
onResizeStart?: () => void;
|
|
160
|
+
/** Callback when a resize drag ends (mouseup after handle drag). */
|
|
161
|
+
onResizeEnd?: () => void;
|
|
162
|
+
/** Optional fixed aspect ratio (width / height) in pixel space. */
|
|
163
|
+
aspectRatio?: number;
|
|
164
|
+
/** Whether the crop handles are shown for freeform resizing. */
|
|
165
|
+
freeformCrop?: boolean;
|
|
166
|
+
/** CSS transition string for settle animation. */
|
|
167
|
+
stencilTransition?: string;
|
|
168
|
+
/** Maximum crop rect bounds based on current zoom/rotation. */
|
|
169
|
+
cropBounds?: {
|
|
170
|
+
minX: number;
|
|
171
|
+
minY: number;
|
|
172
|
+
maxX: number;
|
|
173
|
+
maxY: number;
|
|
174
|
+
};
|
|
175
|
+
/** Called when Escape is pressed on a resize handle. */
|
|
176
|
+
onEscape?: () => void;
|
|
177
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Image Editor — Architecture
|
|
2
|
+
|
|
3
|
+
## Coordinate Spaces
|
|
4
|
+
|
|
5
|
+
| Space | What lives here | Coordinates |
|
|
6
|
+
|-------|----------------|-------------|
|
|
7
|
+
| **World** | Image, crop rect | Normalized 0–1, origin top-left of image |
|
|
8
|
+
| **Camera** | View transform (zoom, pan, rotation, flip) | A `mat2d` mapping world → screen |
|
|
9
|
+
| **Screen** | DOM container, mouse events, CSS | Pixels relative to container |
|
|
10
|
+
|
|
11
|
+
## Data Flow
|
|
12
|
+
|
|
13
|
+
The camera is the source of truth for restriction (ensuring the image covers the crop). The render path uses lightweight manual math for CSS transforms and stencil positioning — these are simple, correct, and deliberately not routed through the camera to avoid prop-threading complexity.
|
|
14
|
+
|
|
15
|
+
```mermaid
|
|
16
|
+
graph TD
|
|
17
|
+
subgraph State["CropperState"]
|
|
18
|
+
pan["pan.x, pan.y"]
|
|
19
|
+
zoom["zoom"]
|
|
20
|
+
rotation["rotation"]
|
|
21
|
+
flip["flip"]
|
|
22
|
+
cropRect["cropRect"]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
subgraph Camera["camera.ts — coordinate primitives"]
|
|
26
|
+
createCamera["createCamera()"]
|
|
27
|
+
getImageFit["getImageFit()"]
|
|
28
|
+
createExportCamera["createExportCamera()"]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
subgraph Containment["containment.ts — restriction source of truth"]
|
|
32
|
+
restrictPanZoom["restrictPanZoom()\nbuilds camera → inverse → clamp"]
|
|
33
|
+
restrictCropRect["restrictCropRect()"]
|
|
34
|
+
getMinZoomForCover["getMinZoomForCover()"]
|
|
35
|
+
getCropBounds["getCropBounds()"]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
subgraph Rendering["Render Path"]
|
|
39
|
+
useTransformStyle["use-transform-style.ts\ncos/sin → CSS matrix()"]
|
|
40
|
+
stencil["rectangle-stencil.tsx\noffset + cropRect * visualSize"]
|
|
41
|
+
dimming["dimming-overlay.tsx\noffset + cropRect * visualSize"]
|
|
42
|
+
grid["grid-overlay.tsx\noffset + cropRect * visualSize"]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
subgraph Interaction["Interaction Path"]
|
|
46
|
+
useInteraction["use-interaction.ts\ndelta / visualSize → restrictPanZoom"]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
subgraph Export["Export Path"]
|
|
50
|
+
canvasRenderer["canvas-renderer.ts"]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
State --> restrictPanZoom
|
|
54
|
+
State --> restrictCropRect
|
|
55
|
+
restrictPanZoom --> |"corrected crop/zoom"| State
|
|
56
|
+
restrictCropRect --> |"corrected cropRect"| State
|
|
57
|
+
|
|
58
|
+
State --> getImageFit
|
|
59
|
+
getImageFit --> |"elementSize"| imgStyle["img element style"]
|
|
60
|
+
getImageFit --> |"visualSize"| stencil
|
|
61
|
+
getImageFit --> |"visualSize"| dimming
|
|
62
|
+
getImageFit --> |"visualSize"| grid
|
|
63
|
+
getImageFit --> |"visualSize"| useInteraction
|
|
64
|
+
getImageFit --> |"visualSize"| useTransformStyle
|
|
65
|
+
|
|
66
|
+
useInteraction --> |"named controller actions"| State
|
|
67
|
+
|
|
68
|
+
State --> createExportCamera --> canvasRenderer
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Design decisions
|
|
72
|
+
|
|
73
|
+
**Why restriction uses the camera but rendering doesn't:**
|
|
74
|
+
- `restrictPanZoom` builds a camera internally and projects crop corners through its inverse. This guarantees the restriction and rendering agree on geometry — the camera IS the screen transform.
|
|
75
|
+
- The render path (`use-transform-style`, stencils, overlays) uses simple manual math because the CSS transform operates in a different coordinate system (element-center origin vs container-center). Deriving CSS matrix from the camera mat2d would be more complex, not less.
|
|
76
|
+
|
|
77
|
+
**Why `getImageFit` exists:**
|
|
78
|
+
- `createCamera` needs to know the fitted image dimensions to build its matrix. `cropper.tsx` also needs them to size the `<img>` element and compute `visualSize` for overlays. `getImageFit` is the shared contain-fit calculation used by both — no duplication.
|
|
79
|
+
|
|
80
|
+
**UX invariant:**
|
|
81
|
+
> After `restrictPanZoom`, transforming the 4 crop corners through `screenToWorld(camera, corner)` must produce world points inside [0,1]×[0,1].
|
|
82
|
+
|
|
83
|
+
This is both the restriction algorithm AND the test. If the camera says it's covered, it's covered on screen — because the camera IS the screen transform.
|
|
84
|
+
|
|
85
|
+
## Extension points
|
|
86
|
+
|
|
87
|
+
See [recipes.md](recipes.md) for the full developer guide. Summary:
|
|
88
|
+
|
|
89
|
+
| Extension | Mechanism |
|
|
90
|
+
|-----------|-----------|
|
|
91
|
+
| Custom crop area UI | `stencil` prop — any component implementing `StencilProps` |
|
|
92
|
+
| AI agent control | `TransformOperation[]` pipeline — JSON-serializable, replayable |
|
|
93
|
+
| Custom export | `exportCroppedImage()` or `applyToCanvas()` for multi-step pipelines |
|
|
94
|
+
| Theming | BEM CSS classes (`.wp-media-editor-image-editor__*`) |
|
|
95
|
+
| State observation | `onStateChange` (every frame), `onGestureStart`/`onGestureEnd` (gesture boundaries) |
|
|
96
|
+
| Undo/redo | Snapshot state at gesture boundaries, `reset()` to restore — see recipes.md |
|