@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,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/image-editor/core/stencil-math.ts
|
|
21
|
+
var stencil_math_exports = {};
|
|
22
|
+
__export(stencil_math_exports, {
|
|
23
|
+
MIN_CROP_SIZE: () => MIN_CROP_SIZE,
|
|
24
|
+
computeFreeResizeRect: () => computeFreeResizeRect,
|
|
25
|
+
computeLockedResizeRect: () => computeLockedResizeRect,
|
|
26
|
+
computeShiftLockedResizeRect: () => computeShiftLockedResizeRect
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(stencil_math_exports);
|
|
29
|
+
var MIN_CROP_SIZE = 0.05;
|
|
30
|
+
function computeFreeResizeRect(drag, clientX, clientY, imageSize, bounds) {
|
|
31
|
+
const dx = imageSize.width > 0 ? (clientX - drag.startX) / imageSize.width : 0;
|
|
32
|
+
const dy = imageSize.height > 0 ? (clientY - drag.startY) / imageSize.height : 0;
|
|
33
|
+
const s = drag.startRect;
|
|
34
|
+
const handle = drag.handle;
|
|
35
|
+
let edgeTop = s.y;
|
|
36
|
+
let edgeBottom = s.y + s.height;
|
|
37
|
+
let edgeLeft = s.x;
|
|
38
|
+
let edgeRight = s.x + s.width;
|
|
39
|
+
if (handle === "n" || handle === "nw" || handle === "ne") {
|
|
40
|
+
edgeTop = Math.max(
|
|
41
|
+
bounds.minY,
|
|
42
|
+
Math.min(s.y + dy, edgeBottom - MIN_CROP_SIZE)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (handle === "s" || handle === "sw" || handle === "se") {
|
|
46
|
+
edgeBottom = Math.max(
|
|
47
|
+
edgeTop + MIN_CROP_SIZE,
|
|
48
|
+
Math.min(s.y + s.height + dy, bounds.maxY)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (handle === "w" || handle === "nw" || handle === "sw") {
|
|
52
|
+
edgeLeft = Math.max(
|
|
53
|
+
bounds.minX,
|
|
54
|
+
Math.min(s.x + dx, edgeRight - MIN_CROP_SIZE)
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (handle === "e" || handle === "ne" || handle === "se") {
|
|
58
|
+
edgeRight = Math.max(
|
|
59
|
+
edgeLeft + MIN_CROP_SIZE,
|
|
60
|
+
Math.min(s.x + s.width + dx, bounds.maxX)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
x: edgeLeft,
|
|
65
|
+
y: edgeTop,
|
|
66
|
+
width: edgeRight - edgeLeft,
|
|
67
|
+
height: edgeBottom - edgeTop
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function computeLockedResizeRect(drag, clientX, clientY, imageSize, bounds, normalizedRatio) {
|
|
71
|
+
if (normalizedRatio <= 0 || imageSize.width <= 0 || imageSize.height <= 0) {
|
|
72
|
+
return { ...drag.startRect };
|
|
73
|
+
}
|
|
74
|
+
const dx = (clientX - drag.startX) / imageSize.width;
|
|
75
|
+
const dy = (clientY - drag.startY) / imageSize.height;
|
|
76
|
+
const s = drag.startRect;
|
|
77
|
+
const handle = drag.handle;
|
|
78
|
+
const anchorX = handle === "nw" || handle === "sw" ? s.x + s.width : s.x;
|
|
79
|
+
const anchorY = handle === "nw" || handle === "ne" ? s.y + s.height : s.y;
|
|
80
|
+
const dirX = handle === "nw" || handle === "sw" ? -1 : 1;
|
|
81
|
+
const dirY = handle === "nw" || handle === "ne" ? -1 : 1;
|
|
82
|
+
const draggedX = (handle === "nw" || handle === "sw" ? s.x : s.x + s.width) + dx;
|
|
83
|
+
const draggedY = (handle === "nw" || handle === "ne" ? s.y : s.y + s.height) + dy;
|
|
84
|
+
let distW = (draggedX - anchorX) * dirX;
|
|
85
|
+
let distH = (draggedY - anchorY) * dirY;
|
|
86
|
+
distW = Math.max(distW, MIN_CROP_SIZE);
|
|
87
|
+
distH = Math.max(distH, MIN_CROP_SIZE);
|
|
88
|
+
const pixelDistW = distW * imageSize.width;
|
|
89
|
+
const pixelDistH = distH * imageSize.height;
|
|
90
|
+
const pixelRatio = normalizedRatio * imageSize.width / imageSize.height;
|
|
91
|
+
if (pixelDistW / pixelDistH > pixelRatio) {
|
|
92
|
+
distH = distW / normalizedRatio;
|
|
93
|
+
} else {
|
|
94
|
+
distW = distH * normalizedRatio;
|
|
95
|
+
}
|
|
96
|
+
const maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;
|
|
97
|
+
const maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;
|
|
98
|
+
if (distW > maxW) {
|
|
99
|
+
distW = maxW;
|
|
100
|
+
distH = distW / normalizedRatio;
|
|
101
|
+
}
|
|
102
|
+
if (distH > maxH) {
|
|
103
|
+
distH = maxH;
|
|
104
|
+
distW = distH * normalizedRatio;
|
|
105
|
+
}
|
|
106
|
+
distW = Math.max(distW, MIN_CROP_SIZE);
|
|
107
|
+
distH = Math.max(distH, MIN_CROP_SIZE);
|
|
108
|
+
const newX = dirX > 0 ? anchorX : anchorX - distW;
|
|
109
|
+
const newY = dirY > 0 ? anchorY : anchorY - distH;
|
|
110
|
+
return { x: newX, y: newY, width: distW, height: distH };
|
|
111
|
+
}
|
|
112
|
+
function computeShiftLockedResizeRect(drag, clientX, clientY, imageSize, bounds) {
|
|
113
|
+
const s = drag.startRect;
|
|
114
|
+
const pixelW = s.width * imageSize.width;
|
|
115
|
+
const pixelH = s.height * imageSize.height;
|
|
116
|
+
if (pixelH <= 0 || pixelW <= 0) {
|
|
117
|
+
return computeFreeResizeRect(
|
|
118
|
+
drag,
|
|
119
|
+
clientX,
|
|
120
|
+
clientY,
|
|
121
|
+
imageSize,
|
|
122
|
+
bounds
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
const normalizedRatio = s.width / s.height;
|
|
126
|
+
const handle = drag.handle;
|
|
127
|
+
if (handle === "nw" || handle === "ne" || handle === "sw" || handle === "se") {
|
|
128
|
+
return computeLockedResizeRect(
|
|
129
|
+
drag,
|
|
130
|
+
clientX,
|
|
131
|
+
clientY,
|
|
132
|
+
imageSize,
|
|
133
|
+
bounds,
|
|
134
|
+
normalizedRatio
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const free = computeFreeResizeRect(
|
|
138
|
+
drag,
|
|
139
|
+
clientX,
|
|
140
|
+
clientY,
|
|
141
|
+
imageSize,
|
|
142
|
+
bounds
|
|
143
|
+
);
|
|
144
|
+
if (handle === "n" || handle === "s") {
|
|
145
|
+
let newHeight2 = free.height;
|
|
146
|
+
let newWidth2 = newHeight2 * normalizedRatio;
|
|
147
|
+
const centerX = s.x + s.width / 2;
|
|
148
|
+
const maxWidth = Math.min(centerX - bounds.minX, bounds.maxX - centerX) * 2;
|
|
149
|
+
if (newWidth2 > maxWidth) {
|
|
150
|
+
newWidth2 = maxWidth;
|
|
151
|
+
newHeight2 = newWidth2 / normalizedRatio;
|
|
152
|
+
}
|
|
153
|
+
const minHeight = Math.max(
|
|
154
|
+
MIN_CROP_SIZE,
|
|
155
|
+
MIN_CROP_SIZE / normalizedRatio
|
|
156
|
+
);
|
|
157
|
+
if (newHeight2 < minHeight) {
|
|
158
|
+
newHeight2 = minHeight;
|
|
159
|
+
newWidth2 = newHeight2 * normalizedRatio;
|
|
160
|
+
}
|
|
161
|
+
const newY = handle === "n" ? s.y + s.height - newHeight2 : s.y;
|
|
162
|
+
return {
|
|
163
|
+
x: centerX - newWidth2 / 2,
|
|
164
|
+
y: newY,
|
|
165
|
+
width: newWidth2,
|
|
166
|
+
height: newHeight2
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
let newWidth = free.width;
|
|
170
|
+
let newHeight = newWidth / normalizedRatio;
|
|
171
|
+
const centerY = s.y + s.height / 2;
|
|
172
|
+
const maxHeight = Math.min(centerY - bounds.minY, bounds.maxY - centerY) * 2;
|
|
173
|
+
if (newHeight > maxHeight) {
|
|
174
|
+
newHeight = maxHeight;
|
|
175
|
+
newWidth = newHeight * normalizedRatio;
|
|
176
|
+
}
|
|
177
|
+
const minWidth = Math.max(MIN_CROP_SIZE, MIN_CROP_SIZE * normalizedRatio);
|
|
178
|
+
if (newWidth < minWidth) {
|
|
179
|
+
newWidth = minWidth;
|
|
180
|
+
newHeight = newWidth / normalizedRatio;
|
|
181
|
+
}
|
|
182
|
+
const newX = handle === "w" ? s.x + s.width - newWidth : s.x;
|
|
183
|
+
return {
|
|
184
|
+
x: newX,
|
|
185
|
+
y: centerY - newHeight / 2,
|
|
186
|
+
width: newWidth,
|
|
187
|
+
height: newHeight
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
191
|
+
0 && (module.exports = {
|
|
192
|
+
MIN_CROP_SIZE,
|
|
193
|
+
computeFreeResizeRect,
|
|
194
|
+
computeLockedResizeRect,
|
|
195
|
+
computeShiftLockedResizeRect
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=stencil-math.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/image-editor/core/stencil-math.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Size } from './types';\n\n/** Minimum crop rect dimension in normalized space (5% of visual area). */\nexport const MIN_CROP_SIZE = 0.05;\n\n/**\n * Handle position identifiers for the 8 resize handles.\n */\nexport type HandlePosition = 'n' | 's' | 'e' | 'w' | 'nw' | 'ne' | 'sw' | 'se';\n\n/**\n * Bounds within which the crop rect must stay.\n */\nexport interface CropBounds {\n\tminX: number;\n\tminY: number;\n\tmaxX: number;\n\tmaxY: number;\n}\n\n/**\n * Drag state for tracking a resize interaction.\n */\nexport interface ResizeDragState {\n\t/** Which handle is being dragged. */\n\thandle: HandlePosition;\n\t/** The mouse position (pixels) when the drag started. */\n\tstartX: number;\n\tstartY: number;\n\t/** The crop rect (normalized) when the drag started. */\n\tstartRect: NormalizedRect;\n}\n\n/**\n * Compute the new crop rect for a free (no aspect ratio) resize.\n *\n * Each edge moves independently based on the handle being dragged.\n * Edges are clamped to the provided bounds and maintain a minimum size.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeFreeResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds\n): NormalizedRect {\n\tconst dx =\n\t\timageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;\n\tconst dy =\n\t\timageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\tlet edgeTop = s.y;\n\tlet edgeBottom = s.y + s.height;\n\tlet edgeLeft = s.x;\n\tlet edgeRight = s.x + s.width;\n\n\tif ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {\n\t\tedgeTop = Math.max(\n\t\t\tbounds.minY,\n\t\t\tMath.min( s.y + dy, edgeBottom - MIN_CROP_SIZE )\n\t\t);\n\t}\n\tif ( handle === 's' || handle === 'sw' || handle === 'se' ) {\n\t\tedgeBottom = Math.max(\n\t\t\tedgeTop + MIN_CROP_SIZE,\n\t\t\tMath.min( s.y + s.height + dy, bounds.maxY )\n\t\t);\n\t}\n\tif ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {\n\t\tedgeLeft = Math.max(\n\t\t\tbounds.minX,\n\t\t\tMath.min( s.x + dx, edgeRight - MIN_CROP_SIZE )\n\t\t);\n\t}\n\tif ( handle === 'e' || handle === 'ne' || handle === 'se' ) {\n\t\tedgeRight = Math.max(\n\t\t\tedgeLeft + MIN_CROP_SIZE,\n\t\t\tMath.min( s.x + s.width + dx, bounds.maxX )\n\t\t);\n\t}\n\n\treturn {\n\t\tx: edgeLeft,\n\t\ty: edgeTop,\n\t\twidth: edgeRight - edgeLeft,\n\t\theight: edgeBottom - edgeTop,\n\t};\n}\n\n/**\n * Compute the new crop rect for a locked-aspect-ratio corner resize.\n *\n * The opposite corner is the anchor. The dragged corner moves freely\n * but the result is clamped to maintain the aspect ratio and stay\n * within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @param normalizedRatio The locked aspect ratio (width / height in normalized space).\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds,\n\tnormalizedRatio: number\n): NormalizedRect {\n\t// The math below divides by `normalizedRatio` and `imageSize`, so\n\t// bail out with the start rect when any of them is zero. This can\n\t// happen if a resize is triggered (e.g. via keyboard arrows on a\n\t// focused handle) before the image has loaded.\n\tif (\n\t\tnormalizedRatio <= 0 ||\n\t\timageSize.width <= 0 ||\n\t\timageSize.height <= 0\n\t) {\n\t\treturn { ...drag.startRect };\n\t}\n\n\tconst dx = ( clientX - drag.startX ) / imageSize.width;\n\tconst dy = ( clientY - drag.startY ) / imageSize.height;\n\n\tconst s = drag.startRect;\n\tconst handle = drag.handle;\n\n\t// Determine the anchor corner (opposite to the dragged corner).\n\tconst anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;\n\tconst anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;\n\n\t// Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).\n\tconst dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;\n\tconst dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;\n\n\t// Desired new position of the dragged corner.\n\tconst draggedX =\n\t\t( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;\n\tconst draggedY =\n\t\t( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;\n\n\t// Raw distances from anchor to dragged corner.\n\tlet distW = ( draggedX - anchorX ) * dirX;\n\tlet distH = ( draggedY - anchorY ) * dirY;\n\n\t// Enforce minimum size.\n\tdistW = Math.max( distW, MIN_CROP_SIZE );\n\tdistH = Math.max( distH, MIN_CROP_SIZE );\n\n\t// Determine which axis \"drives\" \u2014 whichever the user moved more\n\t// (in pixel space) determines the size, the other follows. The\n\t// `normalizedRatio` is w/h in normalized space; the equivalent\n\t// pixel-space ratio is `normalizedRatio * imageW / imageH`. We\n\t// compare the pixel motion ratio against that pixel-space ratio\n\t// so the units line up (was a unit mismatch on non-square images).\n\tconst pixelDistW = distW * imageSize.width;\n\tconst pixelDistH = distH * imageSize.height;\n\tconst pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;\n\tif ( pixelDistW / pixelDistH > pixelRatio ) {\n\t\t// Width is the driver \u2014 compute height from ratio.\n\t\tdistH = distW / normalizedRatio;\n\t} else {\n\t\t// Height is the driver \u2014 compute width from ratio.\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Clamp to image coverage bounds. If the rect would exceed,\n\t// shrink it (maintaining ratio) to fit.\n\tconst maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;\n\tconst maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;\n\n\tif ( distW > maxW ) {\n\t\tdistW = maxW;\n\t\tdistH = distW / normalizedRatio;\n\t}\n\tif ( distH > maxH ) {\n\t\tdistH = maxH;\n\t\tdistW = distH * normalizedRatio;\n\t}\n\n\t// Enforce minimum after clamping.\n\tdistW = Math.max( distW, MIN_CROP_SIZE );\n\tdistH = Math.max( distH, MIN_CROP_SIZE );\n\n\t// Compute the final rect position from the anchor.\n\tconst newX = dirX > 0 ? anchorX : anchorX - distW;\n\tconst newY = dirY > 0 ? anchorY : anchorY - distH;\n\n\treturn { x: newX, y: newY, width: distW, height: distH };\n}\n\n/**\n * Compute the new crop rect for a resize that temporarily locks the\n * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).\n *\n * Corner handles delegate to {@link computeLockedResizeRect}. Edge\n * handles size the dragged axis freely, then expand the perpendicular\n * axis symmetrically around the rect's center to preserve the ratio,\n * clamping symmetrically so the rect stays within bounds.\n *\n * @param drag The current drag state.\n * @param clientX Current mouse/touch X position in pixels.\n * @param clientY Current mouse/touch Y position in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param bounds The allowed crop area bounds.\n * @return The new crop rect in normalized coordinates.\n */\nexport function computeShiftLockedResizeRect(\n\tdrag: ResizeDragState,\n\tclientX: number,\n\tclientY: number,\n\timageSize: Size,\n\tbounds: CropBounds\n): NormalizedRect {\n\tconst s = drag.startRect;\n\tconst pixelW = s.width * imageSize.width;\n\tconst pixelH = s.height * imageSize.height;\n\tif ( pixelH <= 0 || pixelW <= 0 ) {\n\t\treturn computeFreeResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds\n\t\t);\n\t}\n\tconst normalizedRatio = s.width / s.height;\n\n\tconst handle = drag.handle;\n\tif (\n\t\thandle === 'nw' ||\n\t\thandle === 'ne' ||\n\t\thandle === 'sw' ||\n\t\thandle === 'se'\n\t) {\n\t\treturn computeLockedResizeRect(\n\t\t\tdrag,\n\t\t\tclientX,\n\t\t\tclientY,\n\t\t\timageSize,\n\t\t\tbounds,\n\t\t\tnormalizedRatio\n\t\t);\n\t}\n\n\t// Edge handle: size the dragged axis with free-resize logic, then\n\t// expand the perpendicular axis symmetrically around the rect's center.\n\tconst free = computeFreeResizeRect(\n\t\tdrag,\n\t\tclientX,\n\t\tclientY,\n\t\timageSize,\n\t\tbounds\n\t);\n\n\tif ( handle === 'n' || handle === 's' ) {\n\t\t// Height is the driver; derive width from ratio.\n\t\tlet newHeight = free.height;\n\t\tlet newWidth = newHeight * normalizedRatio;\n\t\tconst centerX = s.x + s.width / 2;\n\t\t// Symmetric clamp: limit by the smaller of the two side gaps so\n\t\t// the rect stays centered around centerX.\n\t\tconst maxWidth =\n\t\t\tMath.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;\n\t\tif ( newWidth > maxWidth ) {\n\t\t\tnewWidth = maxWidth;\n\t\t\tnewHeight = newWidth / normalizedRatio;\n\t\t}\n\t\t// Enforce the minimum on the driving axis, then derive the\n\t\t// other axis from the ratio so it stays consistent. The\n\t\t// effective minimum height has to satisfy MIN_CROP_SIZE on\n\t\t// both axes simultaneously.\n\t\tconst minHeight = Math.max(\n\t\t\tMIN_CROP_SIZE,\n\t\t\tMIN_CROP_SIZE / normalizedRatio\n\t\t);\n\t\tif ( newHeight < minHeight ) {\n\t\t\tnewHeight = minHeight;\n\t\t\tnewWidth = newHeight * normalizedRatio;\n\t\t}\n\t\t// Re-anchor the dragged axis to the opposite edge so the\n\t\t// height adjustment after clamping keeps that edge fixed.\n\t\tconst newY = handle === 'n' ? s.y + s.height - newHeight : s.y;\n\t\treturn {\n\t\t\tx: centerX - newWidth / 2,\n\t\t\ty: newY,\n\t\t\twidth: newWidth,\n\t\t\theight: newHeight,\n\t\t};\n\t}\n\n\t// 'e' or 'w': width is the driver; derive height from ratio.\n\tlet newWidth = free.width;\n\tlet newHeight = newWidth / normalizedRatio;\n\tconst centerY = s.y + s.height / 2;\n\tconst maxHeight =\n\t\tMath.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;\n\tif ( newHeight > maxHeight ) {\n\t\tnewHeight = maxHeight;\n\t\tnewWidth = newHeight * normalizedRatio;\n\t}\n\tconst minWidth = Math.max( MIN_CROP_SIZE, MIN_CROP_SIZE * normalizedRatio );\n\tif ( newWidth < minWidth ) {\n\t\tnewWidth = minWidth;\n\t\tnewHeight = newWidth / normalizedRatio;\n\t}\n\tconst newX = handle === 'w' ? s.x + s.width - newWidth : s.x;\n\treturn {\n\t\tx: newX,\n\t\ty: centerY - newHeight / 2,\n\t\twidth: newWidth,\n\t\theight: newHeight,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["newHeight", "newWidth"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/image-editor/core/transform-style.ts
|
|
21
|
+
var transform_style_exports = {};
|
|
22
|
+
__export(transform_style_exports, {
|
|
23
|
+
computeTransformStyle: () => computeTransformStyle
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(transform_style_exports);
|
|
26
|
+
var import_rotation = require("./math/rotation.cjs");
|
|
27
|
+
function computeTransformStyle(state, imageSize) {
|
|
28
|
+
const translateX = state.pan.x * imageSize.width;
|
|
29
|
+
const translateY = state.pan.y * imageSize.height;
|
|
30
|
+
const rad = (0, import_rotation.degreesToRadians)(state.rotation);
|
|
31
|
+
const cos = Math.cos(rad);
|
|
32
|
+
const sin = Math.sin(rad);
|
|
33
|
+
const sx = state.flip.horizontal ? -1 : 1;
|
|
34
|
+
const sy = state.flip.vertical ? -1 : 1;
|
|
35
|
+
const z = state.zoom;
|
|
36
|
+
const a = sx * cos * z;
|
|
37
|
+
const b = sy * sin * z;
|
|
38
|
+
const c = -sx * sin * z;
|
|
39
|
+
const d = sy * cos * z;
|
|
40
|
+
return `matrix(${a}, ${b}, ${c}, ${d}, ${translateX}, ${translateY})`;
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
computeTransformStyle
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=transform-style.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/image-editor/core/transform-style.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\n\n/**\n * Computes a CSS matrix() transform string from the cropper state.\n *\n * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)\n * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).\n *\n * Flip is composed outside rotation so it is viewport-relative \u2014 horizontal\n * flip mirrors across the viewport's vertical axis regardless of rotation.\n * Must match the matrix order in `createCamera` / `getCropBounds`.\n *\n * This is a pure function with no framework dependencies. The React hook\n * `useTransformStyle` wraps this in `useMemo` for memoization.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function computeTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\tconst translateX = state.pan.x * imageSize.width;\n\tconst translateY = state.pan.y * imageSize.height;\n\tconst rad = degreesToRadians( state.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = state.flip.horizontal ? -1 : 1;\n\tconst sy = state.flip.vertical ? -1 : 1;\n\tconst z = state.zoom;\n\n\t// Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)\n\tconst a = sx * cos * z;\n\tconst b = sy * sin * z;\n\tconst c = -sx * sin * z;\n\tconst d = sy * cos * z;\n\n\treturn `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAiC;AAmB1B,SAAS,sBACf,OACA,WACS;AACT,QAAM,aAAa,MAAM,IAAI,IAAI,UAAU;AAC3C,QAAM,aAAa,MAAM,IAAI,IAAI,UAAU;AAC3C,QAAM,UAAM,kCAAkB,MAAM,QAAS;AAC7C,QAAM,MAAM,KAAK,IAAK,GAAI;AAC1B,QAAM,MAAM,KAAK,IAAK,GAAI;AAC1B,QAAM,KAAK,MAAM,KAAK,aAAa,KAAK;AACxC,QAAM,KAAK,MAAM,KAAK,WAAW,KAAK;AACtC,QAAM,IAAI,MAAM;AAGhB,QAAM,IAAI,KAAK,MAAM;AACrB,QAAM,IAAI,KAAK,MAAM;AACrB,QAAM,IAAI,CAAC,KAAK,MAAM;AACtB,QAAM,IAAI,KAAK,MAAM;AAErB,SAAO,UAAW,CAAE,KAAM,CAAE,KAAM,CAAE,KAAM,CAAE,KAAM,UAAW,KAAM,UAAW;AAC/E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/image-editor/core/transforms/pipeline.ts
|
|
21
|
+
var pipeline_exports = {};
|
|
22
|
+
__export(pipeline_exports, {
|
|
23
|
+
applyOperationToState: () => applyOperationToState,
|
|
24
|
+
stateFromPipeline: () => stateFromPipeline
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(pipeline_exports);
|
|
27
|
+
var import_constants = require("../constants.cjs");
|
|
28
|
+
var import_state = require("../state.cjs");
|
|
29
|
+
function applyOperationToState(state, op) {
|
|
30
|
+
return (0, import_state.cropperReducer)(state, { type: "APPLY_OPERATION", payload: op });
|
|
31
|
+
}
|
|
32
|
+
function stateFromPipeline(pipeline, initialState = { ...import_constants.DEFAULT_STATE }) {
|
|
33
|
+
return pipeline.reduce(
|
|
34
|
+
(state, op) => applyOperationToState(state, op),
|
|
35
|
+
initialState
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
applyOperationToState,
|
|
41
|
+
stateFromPipeline
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=pipeline.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/image-editor/core/transforms/pipeline.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { TransformOperation, CropperState } from '../types';\nimport { DEFAULT_STATE } from '../constants';\nimport { cropperReducer } from '../state';\n\n/**\n * Apply a single transform operation to a cropper state, returning\n * a new state with the containment invariant enforced.\n *\n * Delegates to the reducer via APPLY_OPERATION so pipeline replay\n * produces identical bounded state to UI interaction or setter\n * calls. The same logical operation yields the same result\n * regardless of entrypoint.\n *\n * @param state The current cropper state.\n * @param op The operation to apply.\n * @return A new cropper state with the operation applied.\n */\nexport function applyOperationToState(\n\tstate: CropperState,\n\top: TransformOperation\n): CropperState {\n\treturn cropperReducer( state, { type: 'APPLY_OPERATION', payload: op } );\n}\n\n/**\n * Replay all operations from an initial state to produce the final state.\n *\n * @param pipeline The array of transform operations to replay.\n * @param initialState The starting state. Defaults to DEFAULT_STATE.\n * @return The resulting cropper state after all operations are applied.\n */\nexport function stateFromPipeline(\n\tpipeline: TransformOperation[],\n\tinitialState: CropperState = { ...DEFAULT_STATE }\n): CropperState {\n\treturn pipeline.reduce(\n\t\t( state, op ) => applyOperationToState( state, op ),\n\t\tinitialState\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAA8B;AAC9B,mBAA+B;AAexB,SAAS,sBACf,OACA,IACe;AACf,aAAO,6BAAgB,OAAO,EAAE,MAAM,mBAAmB,SAAS,GAAG,CAAE;AACxE;AASO,SAAS,kBACf,UACA,eAA6B,EAAE,GAAG,+BAAc,GACjC;AACf,SAAO,SAAS;AAAA,IACf,CAAE,OAAO,OAAQ,sBAAuB,OAAO,EAAG;AAAA,IAClD;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/media-editor/src/image-editor/core/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/image-editor/core/types.ts"],
|
|
4
|
+
"sourcesContent": ["import type { mat2d } from 'gl-matrix';\n\n/**\n * A 2D camera represented as a 2\u00D73 affine transformation matrix (`mat2d`).\n *\n * This is not a camera object with properties \u2014 it's a raw 6-element matrix\n * `[a, b, c, d, tx, ty]` that maps normalized world coordinates [0,1] to\n * screen pixels. It composes pan, rotation, flip, zoom, and contain-fit\n * into a single transform.\n *\n * Use `createCamera()` to build one from `CropperState`, then pass it to\n * `worldToScreen()` / `screenToWorld()` for coordinate conversion.\n *\n * A 3D camera would use `mat4`; this is strictly 2D (no perspective).\n */\nexport type Camera = mat2d;\n\n/**\n * A point with normalized coordinates (0-1 range relative to image dimensions).\n */\nexport interface NormalizedPoint {\n\tx: number;\n\ty: number;\n}\n\n/**\n * A rectangle with normalized coordinates (0-1 range).\n * Origin is the top-left corner of the image.\n */\nexport interface NormalizedRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Width and height dimensions.\n */\nexport interface Size {\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Flip state for horizontal and vertical axes.\n */\nexport interface Flip {\n\thorizontal: boolean;\n\tvertical: boolean;\n}\n\n/**\n * A JSON-serializable transform operation for the non-destructive pipeline.\n */\nexport type TransformOperation =\n\t| { type: 'crop'; rect: NormalizedRect }\n\t| { type: 'rotate'; degrees: number }\n\t| { type: 'flip'; direction: 'horizontal' | 'vertical' }\n\t| { type: 'zoom'; factor: number };\n\n/**\n * Full cropper state.\n */\nexport interface CropperState {\n\t/** The source image information. Null until an image is loaded. */\n\timage: {\n\t\tsrc: string;\n\t\tnaturalWidth: number;\n\t\tnaturalHeight: number;\n\t} | null;\n\t/**\n\t * Image pan offset in normalized coordinates. Not the crop\n\t * rectangle \u2014 that's `cropRect` below.\n\t */\n\tpan: NormalizedPoint;\n\t/** Zoom level. 1 = no zoom. */\n\tzoom: number;\n\t/** Rotation in degrees, normalized to 0-360. */\n\trotation: number;\n\t/**\n\t * Base pan/zoom/rotation \u2014 the pose the user last explicitly set.\n\t *\n\t * During continuous fine rotation (SET_ROTATION), every tick\n\t * re-derives the transient `pan`/`zoom` from these base values\n\t * rather than compounding on the previous tick. This prevents\n\t * drift from accumulated containment clamping near image edges:\n\t * rotating 0\u00B0\u219230\u00B0\u21920\u00B0 returns to the exact starting pan, not a\n\t * slightly-nudged version of it.\n\t *\n\t * These are updated by every action except SET_ROTATION itself \u2014\n\t * explicit zoom, pan, crop-rect, flip, and 90\u00B0 snap all commit\n\t * the post-containment state into base. SET_ROTATION reads from\n\t * `basePan` and `baseRotation` to compute the new pan, and reads\n\t * `baseZoom` as the zoom floor (enforceContainment may bump it up\n\t * to cover the rotated crop, but never leaves it above baseZoom).\n\t */\n\tbasePan: NormalizedPoint;\n\tbaseZoom: number;\n\tbaseRotation: number;\n\t/** Flip state. */\n\tflip: Flip;\n\t/** The crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n}\n\n/**\n * Internal reducer action union.\n *\n * This type is intentionally not exported from the image-editor public barrel.\n * Consumers should drive state through the controller returned by\n * `useCropperState()` or through serializable `TransformOperation` values.\n */\nexport type CropperAction =\n\t/** Sets the loaded image metadata (natural size, src). */\n\t| { type: 'SET_IMAGE'; payload: CropperState[ 'image' ] }\n\t/** Sets the image pan offset. (Crop rectangle is SET_CROP_RECT.) */\n\t| { type: 'SET_PAN'; payload: NormalizedPoint }\n\t/** Sets the zoom level, clamped to [1, MAX_ZOOM]. */\n\t| { type: 'SET_ZOOM'; payload: number }\n\t/**\n\t * Sets zoom and pan together atomically. Used by focal-point\n\t * zoom (wheel, pinch) to keep a target point stationary while\n\t * zoom changes.\n\t */\n\t| {\n\t\t\ttype: 'SET_ZOOM_AT_POINT';\n\t\t\tpayload: { zoom: number; pan: NormalizedPoint };\n\t }\n\t/** Sets the absolute rotation angle in degrees. */\n\t| { type: 'SET_ROTATION'; payload: number }\n\t/** Rotates by +/-90 degrees (snap). */\n\t| { type: 'SNAP_ROTATE_90'; payload: { direction: 1 | -1 } }\n\t/** Sets the flip state. */\n\t| { type: 'SET_FLIP'; payload: Flip }\n\t/** Sets the crop rectangle. */\n\t| { type: 'SET_CROP_RECT'; payload: NormalizedRect }\n\t/** Settle animation after resize drag, recentering the crop rect. */\n\t| { type: 'SETTLE_CROP' }\n\t/** Applies a single pipeline transform via the reducer. */\n\t| { type: 'APPLY_OPERATION'; payload: TransformOperation }\n\t/** Resets to DEFAULT_STATE, optionally merging a partial override. */\n\t| { type: 'RESET'; payload?: Partial< CropperState > };\n\n/**\n * The contract for a pluggable stencil component.\n * Stencils render the crop area overlay and handle resize interactions.\n */\nexport interface StencilProps {\n\t/** The current crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** The container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** The rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n\t/** Callback when the crop rectangle changes (during drag). */\n\tonCropChange: ( rect: NormalizedRect ) => void;\n\t/** Callback when a resize drag starts (pointerdown on handle). */\n\tonResizeStart?: () => void;\n\t/** Callback when a resize drag ends (mouseup after handle drag). */\n\tonResizeEnd?: () => void;\n\t/** Optional fixed aspect ratio (width / height) in pixel space. */\n\taspectRatio?: number;\n\t/** Whether the crop handles are shown for freeform resizing. */\n\tfreeformCrop?: boolean;\n\t/** CSS transition string for settle animation. */\n\tstencilTransition?: string;\n\t/** Maximum crop rect bounds based on current zoom/rotation. */\n\tcropBounds?: {\n\t\tminX: number;\n\t\tminY: number;\n\t\tmaxX: number;\n\t\tmaxY: number;\n\t};\n\t/** Called when Escape is pressed on a resize handle. */\n\tonEscape?: () => void;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/image-editor/index.ts
|
|
21
|
+
var image_editor_exports = {};
|
|
22
|
+
__export(image_editor_exports, {
|
|
23
|
+
Cropper: () => import_components.Cropper,
|
|
24
|
+
CropperProvider: () => import_components.CropperProvider,
|
|
25
|
+
DEFAULT_ASPECT_RATIOS: () => import_core.DEFAULT_ASPECT_RATIOS,
|
|
26
|
+
DEFAULT_STATE: () => import_core.DEFAULT_STATE,
|
|
27
|
+
ORIGINAL_ASPECT_RATIO: () => import_core.ORIGINAL_ASPECT_RATIO,
|
|
28
|
+
applyOperationToState: () => import_core.applyOperationToState,
|
|
29
|
+
applyToCanvas: () => import_core.applyToCanvas,
|
|
30
|
+
exportCroppedImage: () => import_core.exportCroppedImage,
|
|
31
|
+
getSourceRegion: () => import_core.getSourceRegion,
|
|
32
|
+
getSourceRegionPercent: () => import_core.getSourceRegionPercent,
|
|
33
|
+
stateFromPipeline: () => import_core.stateFromPipeline,
|
|
34
|
+
useCropper: () => import_components.useCropper,
|
|
35
|
+
useCropperState: () => import_hooks.useCropperState
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(image_editor_exports);
|
|
38
|
+
var import_hooks = require("./react/hooks/index.cjs");
|
|
39
|
+
var import_components = require("./react/components/index.cjs");
|
|
40
|
+
var import_core = require("./core/index.cjs");
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
Cropper,
|
|
44
|
+
CropperProvider,
|
|
45
|
+
DEFAULT_ASPECT_RATIOS,
|
|
46
|
+
DEFAULT_STATE,
|
|
47
|
+
ORIGINAL_ASPECT_RATIO,
|
|
48
|
+
applyOperationToState,
|
|
49
|
+
applyToCanvas,
|
|
50
|
+
exportCroppedImage,
|
|
51
|
+
getSourceRegion,
|
|
52
|
+
getSourceRegionPercent,
|
|
53
|
+
stateFromPipeline,
|
|
54
|
+
useCropper,
|
|
55
|
+
useCropperState
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/image-editor/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Public image editor contract.\n *\n * Keep this barrel explicit so implementation details from `core/`,\n * `react/hooks/`, or `react/components/` do not become supported API by\n * accident. Internal modules may export additional helpers for local tests or\n * React wiring; consumers should import through this file.\n */\n\n// React surface.\nexport { useCropperState } from './react/hooks';\nexport { Cropper, CropperProvider, useCropper } from './react/components';\nexport type { UseCropperStateReturn } from './react/hooks';\nexport type { CropperProps } from './react/components';\n\n// State and extension types.\nexport type {\n\tCropperState,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tSize,\n\tFlip,\n\tStencilProps,\n} from './core';\n\n// Deterministic cropper helpers.\nexport {\n\tDEFAULT_STATE,\n\tDEFAULT_ASPECT_RATIOS,\n\tORIGINAL_ASPECT_RATIO,\n\tgetSourceRegion,\n\tgetSourceRegionPercent,\n\tapplyOperationToState,\n\tstateFromPipeline,\n\texportCroppedImage,\n\tapplyToCanvas,\n} from './core';\nexport type {\n\tAspectRatioPreset,\n\tSourceRegion,\n\tSourceRegionPercent,\n} from './core';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,mBAAgC;AAChC,wBAAqD;AAgBrD,kBAUO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/image-editor/react/components/cropper-provider.tsx
|
|
21
|
+
var cropper_provider_exports = {};
|
|
22
|
+
__export(cropper_provider_exports, {
|
|
23
|
+
CropperProvider: () => CropperProvider,
|
|
24
|
+
useCropper: () => useCropper
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(cropper_provider_exports);
|
|
27
|
+
var import_element = require("@wordpress/element");
|
|
28
|
+
var import_use_cropper_state = require("../hooks/use-cropper-state.cjs");
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
var CropperContext = (0, import_element.createContext)(null);
|
|
31
|
+
function CropperProvider({
|
|
32
|
+
initialState,
|
|
33
|
+
children
|
|
34
|
+
}) {
|
|
35
|
+
const cropperReturn = (0, import_use_cropper_state.useCropperState)(initialState);
|
|
36
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CropperContext.Provider, { value: cropperReturn, children });
|
|
37
|
+
}
|
|
38
|
+
function useCropper() {
|
|
39
|
+
const context = (0, import_element.useContext)(CropperContext);
|
|
40
|
+
if (!context) {
|
|
41
|
+
throw new Error("useCropper must be used within a CropperProvider.");
|
|
42
|
+
}
|
|
43
|
+
return context;
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
CropperProvider,
|
|
48
|
+
useCropper
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=cropper-provider.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/image-editor/react/components/cropper-provider.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tuseCropperState,\n\ttype UseCropperStateReturn,\n} from '../hooks/use-cropper-state';\nimport type { CropperState } from '../../core/types';\n\n/**\n * The context value type for the CropperProvider.\n * Contains the full return value of useCropperState.\n */\ntype CropperContextValue = UseCropperStateReturn | null;\n\nconst CropperContext = createContext< CropperContextValue >( null );\n\n/**\n * Props for the CropperProvider component.\n */\ninterface CropperProviderProps {\n\t/** Optional partial initial state to merge with defaults. */\n\tinitialState?: Partial< CropperState >;\n\t/** Child components. */\n\tchildren: React.ReactNode;\n}\n\n/**\n * Convenience context provider that wraps useCropperState.\n *\n * Provides the full cropper state and action creators to all\n * descendant components via React context.\n *\n * @param props Provider props.\n * @param props.initialState\n * @param props.children\n * @return The provider element wrapping children.\n */\nexport function CropperProvider( {\n\tinitialState,\n\tchildren,\n}: CropperProviderProps ) {\n\tconst cropperReturn = useCropperState( initialState );\n\n\treturn (\n\t\t<CropperContext.Provider value={ cropperReturn }>\n\t\t\t{ children }\n\t\t</CropperContext.Provider>\n\t);\n}\n\n/**\n * Hook to consume the CropperProvider context.\n *\n * Must be used within a CropperProvider. Throws if used outside\n * of the provider tree.\n *\n * @return The cropper state and action creators.\n */\nexport function useCropper(): UseCropperStateReturn {\n\tconst context = useContext( CropperContext );\n\n\tif ( ! context ) {\n\t\tthrow new Error( 'useCropper must be used within a CropperProvider.' );\n\t}\n\n\treturn context;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0C;AAK1C,+BAGO;AAuCL;AA9BF,IAAM,qBAAiB,8BAAsC,IAAK;AAuB3D,SAAS,gBAAiB;AAAA,EAChC;AAAA,EACA;AACD,GAA0B;AACzB,QAAM,oBAAgB,0CAAiB,YAAa;AAEpD,SACC,4CAAC,eAAe,UAAf,EAAwB,OAAQ,eAC9B,UACH;AAEF;AAUO,SAAS,aAAoC;AACnD,QAAM,cAAU,2BAAY,cAAe;AAE3C,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI,MAAO,mDAAoD;AAAA,EACtE;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|