@wordpress/image-cropper 1.0.1-next.6deb34194.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE.md +788 -0
  3. package/README.md +196 -0
  4. package/build/components/image-cropper/index.js +97 -0
  5. package/build/components/image-cropper/index.js.map +7 -0
  6. package/build/constants.js +37 -0
  7. package/build/constants.js.map +7 -0
  8. package/build/index.js +52 -0
  9. package/build/index.js.map +7 -0
  10. package/build/provider/index.js +86 -0
  11. package/build/provider/index.js.map +7 -0
  12. package/build/provider/use-image-cropper.js +189 -0
  13. package/build/provider/use-image-cropper.js.map +7 -0
  14. package/build/types.js +19 -0
  15. package/build/types.js.map +7 -0
  16. package/build/utils.js +107 -0
  17. package/build/utils.js.map +7 -0
  18. package/build-module/components/image-cropper/index.js +66 -0
  19. package/build-module/components/image-cropper/index.js.map +7 -0
  20. package/build-module/constants.js +10 -0
  21. package/build-module/constants.js.map +7 -0
  22. package/build-module/index.js +12 -0
  23. package/build-module/index.js.map +7 -0
  24. package/build-module/provider/index.js +50 -0
  25. package/build-module/provider/index.js.map +7 -0
  26. package/build-module/provider/use-image-cropper.js +167 -0
  27. package/build-module/provider/use-image-cropper.js.map +7 -0
  28. package/build-module/types.js +1 -0
  29. package/build-module/types.js.map +7 -0
  30. package/build-module/utils.js +78 -0
  31. package/build-module/utils.js.map +7 -0
  32. package/build-types/components/image-cropper/index.d.ts +3 -0
  33. package/build-types/components/image-cropper/index.d.ts.map +1 -0
  34. package/build-types/constants.d.ts +4 -0
  35. package/build-types/constants.d.ts.map +1 -0
  36. package/build-types/index.d.ts +5 -0
  37. package/build-types/index.d.ts.map +1 -0
  38. package/build-types/provider/index.d.ts +7 -0
  39. package/build-types/provider/index.d.ts.map +1 -0
  40. package/build-types/provider/use-image-cropper.d.ts +15 -0
  41. package/build-types/provider/use-image-cropper.d.ts.map +1 -0
  42. package/build-types/stories/index.story.d.ts +28 -0
  43. package/build-types/stories/index.story.d.ts.map +1 -0
  44. package/build-types/types.d.ts +42 -0
  45. package/build-types/types.d.ts.map +1 -0
  46. package/build-types/utils.d.ts +60 -0
  47. package/build-types/utils.d.ts.map +1 -0
  48. package/package.json +49 -0
  49. package/src/components/image-cropper/index.tsx +84 -0
  50. package/src/constants.ts +3 -0
  51. package/src/index.ts +4 -0
  52. package/src/provider/index.tsx +57 -0
  53. package/src/provider/use-image-cropper.ts +220 -0
  54. package/src/stories/index.story.tsx +351 -0
  55. package/src/stories/style.css +17 -0
  56. package/src/types.ts +54 -0
  57. package/src/utils.ts +146 -0
  58. package/tsconfig.json +8 -0
  59. package/tsconfig.tsbuildinfo +1 -0
package/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # Image Cropper
2
+
3
+ An implementation of [react-easy-crop](https://www.npmjs.com/package/react-easy-crop).
4
+
5
+ ## Current features
6
+
7
+ - **Image Cropping**: Interactive aspect ratio-based crop area with drag and resize functionality
8
+ - **Rotation**: Rotate images in 90-degree increments
9
+ - **Zoom Control**: Zoom in/out with configurable min/max limits
10
+ - **Aspect Ratio**: Set and maintain specific aspect ratios
11
+ - **Flip Controls**: Horizontal and vertical image flipping
12
+ - **State Management**: Centralized state management with React Context
13
+ - **Custom Reset State**: Configure custom initial states for reset operations
14
+
15
+ ## Future features
16
+
17
+ - [ ] Freeform cropping
18
+
19
+ ## Installation
20
+
21
+ Install the module
22
+
23
+ ```bash
24
+ npm install @wordpress/image-cropper --save
25
+ ```
26
+
27
+ ## API
28
+
29
+ ### Components
30
+
31
+ - `ImageCropper` - The main cropping component that provides the cropping canvas.
32
+
33
+ ```tsx
34
+ interface ImageCropperProps {
35
+ src: string; // Image source URL
36
+ onLoad?: ( mediaSize: MediaSize ) => void; // Callback when image loads with media dimensions
37
+ minZoom?: number; // Minimum zoom level (default: 1)
38
+ maxZoom?: number; // Maximum zoom level (default: 5)
39
+ }
40
+ ```
41
+
42
+ - `ImageCropperProvider` - Context provider for state management. This component implements the React Context pattern to share cropper state across your application. It manages all internal cropper state including crop position, zoom levels, rotation, flip transformations, aspect ratios, and media dimensions. Any component that needs to read or modify cropper state must be a descendant of this provider. The provider also handles state persistence and provides methods for resetting to custom initial states.
43
+
44
+ ### Hooks
45
+
46
+ - `useImageCropper` - Provides access to all cropper state and methods.
47
+
48
+ ```tsx
49
+ import { useImageCropper } from '@wordpress/image-cropper';
50
+
51
+ const {
52
+ // Unified state object
53
+ cropperState, // Complete cropper state { crop, croppedArea, croppedAreaPixels, zoom, rotation, aspectRatio, flip, mediaSize }
54
+ setCropperState, // Set multiple state properties at once
55
+
56
+ // Actions
57
+ reset, // Reset all changes (uses resetState if set)
58
+ setResetState, // Set custom reset state
59
+ getCroppedImage, // Get cropped image as data URL
60
+
61
+ // Reset state
62
+ resetState, // Current reset state configuration
63
+ isDirty, // Whether the state is dirty based on resetState or default settings
64
+ } = useImageCropper();
65
+ ```
66
+
67
+ ### Types
68
+
69
+ - `ImageCropperState` - State interface for cropper data
70
+ - `ImageCropperProps` - Props interface for ImageCropper component
71
+ - `ImageCropperContextValue` - Context value interface
72
+ - `Flip` - Flip state interface
73
+ - `Point`, `Area`, `MediaSize` - Re-exported from react-easy-crop
74
+
75
+ ### Utilities
76
+
77
+ - `normalizeRotation` - Utility function to normalize rotation values to 0-360 degrees
78
+
79
+ ```tsx
80
+ import { normalizeRotation } from '@wordpress/image-cropper';
81
+
82
+ const normalized = normalizeRotation( -90 ); // Returns 270
83
+ const normalized2 = normalizeRotation( 450 ); // Returns 90
84
+ ```
85
+
86
+ ## Usage
87
+
88
+ ### Basic Implementation
89
+
90
+ The image cropper provides the core cropping functionality without any built-in UI controls. You must implement your own tools using the `useImageCropper` hook.
91
+
92
+ ```tsx
93
+ import {
94
+ ImageCropper,
95
+ ImageCropperProvider,
96
+ useImageCropper,
97
+ } from '@wordpress/image-cropper';
98
+
99
+ function ImageEditor() {
100
+ return (
101
+ <ImageCropperProvider>
102
+ <div className="image-editor">
103
+ <ImageCropper
104
+ src="https://example.com/image.jpg"
105
+ className="image-cropper"
106
+ onLoad={ ( mediaSize ) =>
107
+ console.log( 'Image loaded', mediaSize )
108
+ }
109
+ />
110
+ <ImageEditorTools />
111
+ </div>
112
+ </ImageCropperProvider>
113
+ );
114
+ }
115
+
116
+ function ImageEditorTools() {
117
+ const { cropperState, setCropperState, reset, setResetState } =
118
+ useImageCropper();
119
+
120
+ const { zoom, rotation, aspectRatio, flip, mediaSize, croppedArea } =
121
+ cropperState;
122
+
123
+ const handleSave = () => {
124
+ console.log( 'Cropper state:', {
125
+ crop: croppedArea,
126
+ zoom,
127
+ rotation,
128
+ aspectRatio,
129
+ flip,
130
+ } );
131
+ // Apply the crop state to your image
132
+ };
133
+
134
+ return (
135
+ <div className="image-editor-tools">
136
+ <button
137
+ onClick={ () => setCropperState( { rotation: rotation + 90 } ) }
138
+ >
139
+ Rotate Right
140
+ </button>
141
+ <button
142
+ onClick={ () => setCropperState( { rotation: rotation - 90 } ) }
143
+ >
144
+ Rotate Left
145
+ </button>
146
+ <button
147
+ onClick={ () =>
148
+ setCropperState( {
149
+ flip: { ...flip, horizontal: ! flip.horizontal },
150
+ } )
151
+ }
152
+ >
153
+ Flip Horizontal
154
+ </button>
155
+ <button
156
+ onClick={ () =>
157
+ setCropperState( {
158
+ flip: { ...flip, vertical: ! flip.vertical },
159
+ } )
160
+ }
161
+ >
162
+ Flip Vertical
163
+ </button>
164
+ <button onClick={ handleSave }>Apply Changes</button>
165
+ <button onClick={ reset }>Reset</button>
166
+ </div>
167
+ );
168
+ }
169
+ ```
170
+
171
+ ### Advanced Usage with Custom Reset State
172
+
173
+ You can configure a custom initial state that will be used when the reset function is called:
174
+
175
+ ```tsx
176
+ function ImageEditorWithCustomReset() {
177
+ const { setResetState, reset } = useImageCropper();
178
+
179
+ // Set custom reset state
180
+ useEffect( () => {
181
+ setResetState( {
182
+ rotation: 90,
183
+ zoom: 1.5,
184
+ aspectRatio: 16 / 9,
185
+ flip: { horizontal: false, vertical: false },
186
+ } );
187
+ }, [ setResetState ] );
188
+
189
+ return (
190
+ <div>
191
+ { /* Your cropper components */ }
192
+ <button onClick={ reset }>Reset to Custom State</button>
193
+ </div>
194
+ );
195
+ }
196
+ ```
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/image-cropper/src/components/image-cropper/index.tsx
31
+ var image_cropper_exports = {};
32
+ __export(image_cropper_exports, {
33
+ default: () => ImageCropper
34
+ });
35
+ module.exports = __toCommonJS(image_cropper_exports);
36
+ var import_react_easy_crop = __toESM(require("react-easy-crop"));
37
+ var import_element = require("@wordpress/element");
38
+ var import_provider = require("../../provider");
39
+ var import_constants = require("../../constants");
40
+ var import_jsx_runtime = require("react/jsx-runtime");
41
+ function ImageCropper({
42
+ src,
43
+ onLoad,
44
+ minZoom = import_constants.MIN_ZOOM,
45
+ maxZoom = import_constants.MAX_ZOOM,
46
+ ...props
47
+ }) {
48
+ const { cropperState, setCropperState } = (0, import_provider.useImageCropper)();
49
+ const { crop, zoom, rotation, aspectRatio, flip } = cropperState;
50
+ const setCrop = (newCrop) => setCropperState({ crop: newCrop });
51
+ const setZoom = (newZoom) => setCropperState({ zoom: newZoom });
52
+ const setRotation = (newRotation) => setCropperState({ rotation: newRotation });
53
+ const setMediaSize = (newMediaSize) => setCropperState({ mediaSize: newMediaSize });
54
+ const onCropComplete = (0, import_element.useCallback)(
55
+ (areaPercentage, areaPixels) => {
56
+ setCropperState({
57
+ croppedArea: areaPercentage,
58
+ croppedAreaPixels: areaPixels
59
+ });
60
+ },
61
+ [setCropperState]
62
+ );
63
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
64
+ import_react_easy_crop.default,
65
+ {
66
+ classes: {
67
+ containerClassName: "image-cropper__container",
68
+ cropAreaClassName: "image-cropper__crop-area",
69
+ mediaClassName: "image-cropper__image"
70
+ },
71
+ minZoom,
72
+ maxZoom,
73
+ rotation,
74
+ image: src,
75
+ setMediaSize,
76
+ crop,
77
+ zoom,
78
+ aspect: aspectRatio,
79
+ onCropChange: setCrop,
80
+ onZoomChange: setZoom,
81
+ onCropComplete,
82
+ onMediaLoaded: (loadedMediaSize) => {
83
+ onLoad?.(loadedMediaSize);
84
+ },
85
+ onRotationChange: setRotation,
86
+ transform: [
87
+ `translate(${crop.x}px, ${crop.y}px)`,
88
+ `rotateZ(${rotation}deg)`,
89
+ `rotateY(${flip.horizontal ? 180 : 0}deg)`,
90
+ `rotateX(${flip.vertical ? 180 : 0}deg)`,
91
+ `scale(${zoom})`
92
+ ].join(" "),
93
+ ...props
94
+ }
95
+ );
96
+ }
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/image-cropper/index.tsx"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport Cropper from 'react-easy-crop';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useImageCropper } from '../../provider';\nimport type { Area, ImageCropperProps, MediaSize, Point } from '../../types';\nimport { MIN_ZOOM, MAX_ZOOM } from '../../constants';\n\nexport default function ImageCropper( {\n\tsrc,\n\tonLoad,\n\tminZoom = MIN_ZOOM,\n\tmaxZoom = MAX_ZOOM,\n\t...props\n}: ImageCropperProps ) {\n\tconst { cropperState, setCropperState } = useImageCropper();\n\tconst { crop, zoom, rotation, aspectRatio, flip } = cropperState;\n\n\tconst setCrop = ( newCrop: Point ) => setCropperState( { crop: newCrop } );\n\tconst setZoom = ( newZoom: number ) => setCropperState( { zoom: newZoom } );\n\tconst setRotation = ( newRotation: number ) =>\n\t\tsetCropperState( { rotation: newRotation } );\n\tconst setMediaSize = ( newMediaSize: MediaSize ) =>\n\t\tsetCropperState( { mediaSize: newMediaSize } );\n\n\t/**\n\t * Handles the crop complete event, when a user stops interacting with the cropper.\n\t * Updates the cropped area in percentages and pixels.\n\t *\n\t * @param {Area} areaPercentage - The area percentage.\n\t * @param {Area} areaPixels - The area pixels.\n\t */\n\tconst onCropComplete = useCallback(\n\t\t( areaPercentage: Area, areaPixels: Area ) => {\n\t\t\tsetCropperState( {\n\t\t\t\tcroppedArea: areaPercentage,\n\t\t\t\tcroppedAreaPixels: areaPixels,\n\t\t\t} );\n\t\t},\n\t\t[ setCropperState ]\n\t);\n\n\treturn (\n\t\t<Cropper\n\t\t\tclasses={ {\n\t\t\t\tcontainerClassName: 'image-cropper__container',\n\t\t\t\tcropAreaClassName: 'image-cropper__crop-area',\n\t\t\t\tmediaClassName: 'image-cropper__image',\n\t\t\t} }\n\t\t\tminZoom={ minZoom }\n\t\t\tmaxZoom={ maxZoom }\n\t\t\trotation={ rotation }\n\t\t\timage={ src }\n\t\t\tsetMediaSize={ setMediaSize }\n\t\t\tcrop={ crop }\n\t\t\tzoom={ zoom }\n\t\t\taspect={ aspectRatio }\n\t\t\tonCropChange={ setCrop }\n\t\t\tonZoomChange={ setZoom }\n\t\t\tonCropComplete={ onCropComplete }\n\t\t\tonMediaLoaded={ ( loadedMediaSize: MediaSize ) => {\n\t\t\t\tonLoad?.( loadedMediaSize );\n\t\t\t} }\n\t\t\tonRotationChange={ setRotation }\n\t\t\ttransform={ [\n\t\t\t\t`translate(${ crop.x }px, ${ crop.y }px)`,\n\t\t\t\t`rotateZ(${ rotation }deg)`,\n\t\t\t\t`rotateY(${ flip.horizontal ? 180 : 0 }deg)`,\n\t\t\t\t`rotateX(${ flip.vertical ? 180 : 0 }deg)`,\n\t\t\t\t`scale(${ zoom })`,\n\t\t\t].join( ' ' ) }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,6BAAoB;AAKpB,qBAA4B;AAK5B,sBAAgC;AAEhC,uBAAmC;AAqCjC;AAnCa,SAAR,aAA+B;AAAA,EACrC;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,UAAU;AAAA,EACV,GAAG;AACJ,GAAuB;AACtB,QAAM,EAAE,cAAc,gBAAgB,QAAI,iCAAgB;AAC1D,QAAM,EAAE,MAAM,MAAM,UAAU,aAAa,KAAK,IAAI;AAEpD,QAAM,UAAU,CAAE,YAAoB,gBAAiB,EAAE,MAAM,QAAQ,CAAE;AACzE,QAAM,UAAU,CAAE,YAAqB,gBAAiB,EAAE,MAAM,QAAQ,CAAE;AAC1E,QAAM,cAAc,CAAE,gBACrB,gBAAiB,EAAE,UAAU,YAAY,CAAE;AAC5C,QAAM,eAAe,CAAE,iBACtB,gBAAiB,EAAE,WAAW,aAAa,CAAE;AAS9C,QAAM,qBAAiB;AAAA,IACtB,CAAE,gBAAsB,eAAsB;AAC7C,sBAAiB;AAAA,QAChB,aAAa;AAAA,QACb,mBAAmB;AAAA,MACpB,CAAE;AAAA,IACH;AAAA,IACA,CAAE,eAAgB;AAAA,EACnB;AAEA,SACC;AAAA,IAAC,uBAAAA;AAAA,IAAA;AAAA,MACA,SAAU;AAAA,QACT,oBAAoB;AAAA,QACpB,mBAAmB;AAAA,QACnB,gBAAgB;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAS;AAAA,MACT,cAAe;AAAA,MACf,cAAe;AAAA,MACf;AAAA,MACA,eAAgB,CAAE,oBAAgC;AACjD,iBAAU,eAAgB;AAAA,MAC3B;AAAA,MACA,kBAAmB;AAAA,MACnB,WAAY;AAAA,QACX,aAAc,KAAK,CAAE,OAAQ,KAAK,CAAE;AAAA,QACpC,WAAY,QAAS;AAAA,QACrB,WAAY,KAAK,aAAa,MAAM,CAAE;AAAA,QACtC,WAAY,KAAK,WAAW,MAAM,CAAE;AAAA,QACpC,SAAU,IAAK;AAAA,MAChB,EAAE,KAAM,GAAI;AAAA,MACV,GAAG;AAAA;AAAA,EACN;AAEF;",
6
+ "names": ["Cropper"]
7
+ }
@@ -0,0 +1,37 @@
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/image-cropper/src/constants.ts
21
+ var constants_exports = {};
22
+ __export(constants_exports, {
23
+ DEFAULT_ASPECT_RATIO_SLUG: () => DEFAULT_ASPECT_RATIO_SLUG,
24
+ MAX_ZOOM: () => MAX_ZOOM,
25
+ MIN_ZOOM: () => MIN_ZOOM
26
+ });
27
+ module.exports = __toCommonJS(constants_exports);
28
+ var MIN_ZOOM = 1;
29
+ var MAX_ZOOM = 5;
30
+ var DEFAULT_ASPECT_RATIO_SLUG = "original";
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ DEFAULT_ASPECT_RATIO_SLUG,
34
+ MAX_ZOOM,
35
+ MIN_ZOOM
36
+ });
37
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/constants.ts"],
4
+ "sourcesContent": ["export const MIN_ZOOM = 1;\nexport const MAX_ZOOM = 5;\nexport const DEFAULT_ASPECT_RATIO_SLUG = 'original';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,WAAW;AACjB,IAAM,WAAW;AACjB,IAAM,4BAA4B;",
6
+ "names": []
7
+ }
package/build/index.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // packages/image-cropper/src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ ImageCropper: () => import_image_cropper.default,
35
+ ImageCropperProvider: () => import_provider.default,
36
+ normalizeRotation: () => import_utils.normalizeRotation,
37
+ useImageCropper: () => import_provider.useImageCropper
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+ var import_image_cropper = __toESM(require("./components/image-cropper"));
41
+ var import_provider = __toESM(require("./provider"));
42
+ __reExport(index_exports, require("./types"), module.exports);
43
+ var import_utils = require("./utils");
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ ImageCropper,
47
+ ImageCropperProvider,
48
+ normalizeRotation,
49
+ useImageCropper,
50
+ ...require("./types")
51
+ });
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export { default as ImageCropper } from './components/image-cropper';\nexport { useImageCropper, default as ImageCropperProvider } from './provider';\nexport * from './types';\nexport { normalizeRotation } from './utils';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAwC;AACxC,sBAAiE;AACjE,0BAAc,oBAFd;AAGA,mBAAkC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/image-cropper/src/provider/index.tsx
31
+ var provider_exports = {};
32
+ __export(provider_exports, {
33
+ ImageCropperContext: () => ImageCropperContext,
34
+ default: () => ImageCropperProvider,
35
+ useImageCropper: () => useImageCropper
36
+ });
37
+ module.exports = __toCommonJS(provider_exports);
38
+ var import_element = require("@wordpress/element");
39
+ var import_use_image_cropper = __toESM(require("./use-image-cropper"));
40
+ var import_constants = require("../constants");
41
+ var import_jsx_runtime = require("react/jsx-runtime");
42
+ var ImageCropperContext = (0, import_element.createContext)({
43
+ cropperState: {
44
+ crop: { x: 0, y: 0 },
45
+ croppedArea: { x: 0, y: 0, width: 100, height: 100 },
46
+ croppedAreaPixels: null,
47
+ zoom: import_constants.MIN_ZOOM,
48
+ rotation: 0,
49
+ aspectRatio: 1,
50
+ flip: { horizontal: false, vertical: false },
51
+ mediaSize: null
52
+ },
53
+ setCropperState: () => {
54
+ },
55
+ resetState: null,
56
+ setResetState: () => {
57
+ },
58
+ isDirty: false,
59
+ reset: () => {
60
+ },
61
+ getCroppedImage: () => Promise.resolve(null)
62
+ });
63
+ function ImageCropperProvider({
64
+ children
65
+ }) {
66
+ const cropperApi = (0, import_use_image_cropper.default)();
67
+ const contextValue = (0, import_element.useMemo)(() => {
68
+ return {
69
+ ...cropperApi
70
+ };
71
+ }, [cropperApi]);
72
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ImageCropperContext.Provider, { value: contextValue, children });
73
+ }
74
+ var useImageCropper = () => {
75
+ const context = (0, import_element.useContext)(ImageCropperContext);
76
+ if (!context) {
77
+ throw new Error("Missing ImageCropperContext");
78
+ }
79
+ return context;
80
+ };
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ ImageCropperContext,
84
+ useImageCropper
85
+ });
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/provider/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useCropper from './use-image-cropper';\nimport type { ImageCropperContextValue } from '../types';\nimport { MIN_ZOOM } from '../constants';\n\nexport const ImageCropperContext = createContext< ImageCropperContextValue >( {\n\tcropperState: {\n\t\tcrop: { x: 0, y: 0 },\n\t\tcroppedArea: { x: 0, y: 0, width: 100, height: 100 },\n\t\tcroppedAreaPixels: null,\n\t\tzoom: MIN_ZOOM,\n\t\trotation: 0,\n\t\taspectRatio: 1,\n\t\tflip: { horizontal: false, vertical: false },\n\t\tmediaSize: null,\n\t},\n\tsetCropperState: () => {},\n\tresetState: null,\n\tsetResetState: () => {},\n\tisDirty: false,\n\treset: () => {},\n\tgetCroppedImage: () => Promise.resolve( null ),\n} );\n\nexport default function ImageCropperProvider( {\n\tchildren,\n}: {\n\tchildren: React.ReactNode;\n} ) {\n\tconst cropperApi = useCropper();\n\tconst contextValue = useMemo( () => {\n\t\treturn {\n\t\t\t...cropperApi,\n\t\t};\n\t}, [ cropperApi ] );\n\n\treturn (\n\t\t<ImageCropperContext.Provider value={ contextValue }>\n\t\t\t{ children }\n\t\t</ImageCropperContext.Provider>\n\t);\n}\n\nexport const useImageCropper = () => {\n\tconst context = useContext( ImageCropperContext );\n\tif ( ! context ) {\n\t\tthrow new Error( 'Missing ImageCropperContext' );\n\t}\n\treturn context;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAmD;AAKnD,+BAAuB;AAEvB,uBAAyB;AAkCvB;AAhCK,IAAM,0BAAsB,8BAA2C;AAAA,EAC7E,cAAc;AAAA,IACb,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE;AAAA,IACnB,aAAa,EAAE,GAAG,GAAG,GAAG,GAAG,OAAO,KAAK,QAAQ,IAAI;AAAA,IACnD,mBAAmB;AAAA,IACnB,MAAM;AAAA,IACN,UAAU;AAAA,IACV,aAAa;AAAA,IACb,MAAM,EAAE,YAAY,OAAO,UAAU,MAAM;AAAA,IAC3C,WAAW;AAAA,EACZ;AAAA,EACA,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,YAAY;AAAA,EACZ,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,SAAS;AAAA,EACT,OAAO,MAAM;AAAA,EAAC;AAAA,EACd,iBAAiB,MAAM,QAAQ,QAAS,IAAK;AAC9C,CAAE;AAEa,SAAR,qBAAuC;AAAA,EAC7C;AACD,GAEI;AACH,QAAM,iBAAa,yBAAAA,SAAW;AAC9B,QAAM,mBAAe,wBAAS,MAAM;AACnC,WAAO;AAAA,MACN,GAAG;AAAA,IACJ;AAAA,EACD,GAAG,CAAE,UAAW,CAAE;AAElB,SACC,4CAAC,oBAAoB,UAApB,EAA6B,OAAQ,cACnC,UACH;AAEF;AAEO,IAAM,kBAAkB,MAAM;AACpC,QAAM,cAAU,2BAAY,mBAAoB;AAChD,MAAK,CAAE,SAAU;AAChB,UAAM,IAAI,MAAO,6BAA8B;AAAA,EAChD;AACA,SAAO;AACR;",
6
+ "names": ["useCropper"]
7
+ }