@codeleap/web 6.2.3 → 6.3.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 (31) hide show
  1. package/dist/components/CropPicker/components/CropPickerFooter.d.ts +11 -0
  2. package/dist/components/CropPicker/components/CropPickerFooter.js +12 -0
  3. package/dist/components/CropPicker/components/CropPickerFooter.js.map +1 -0
  4. package/dist/components/CropPicker/hooks.d.ts +39 -0
  5. package/dist/components/CropPicker/hooks.js +184 -0
  6. package/dist/components/CropPicker/hooks.js.map +1 -0
  7. package/dist/components/CropPicker/index.d.ts +3 -1
  8. package/dist/components/CropPicker/index.js +19 -32
  9. package/dist/components/CropPicker/index.js.map +1 -1
  10. package/dist/components/CropPicker/styles.d.ts +2 -2
  11. package/dist/components/CropPicker/types.d.ts +13 -15
  12. package/dist/components/CropPicker/utils.d.ts +10 -0
  13. package/dist/components/CropPicker/utils.js +117 -0
  14. package/dist/components/CropPicker/utils.js.map +1 -0
  15. package/dist/lib/hooks/index.d.ts +0 -1
  16. package/dist/lib/hooks/index.js +0 -1
  17. package/dist/lib/hooks/index.js.map +1 -1
  18. package/package.json +17 -17
  19. package/package.json.bak +1 -1
  20. package/src/components/CropPicker/components/CropPickerFooter.tsx +39 -0
  21. package/src/components/CropPicker/hooks.ts +173 -0
  22. package/src/components/CropPicker/index.tsx +49 -77
  23. package/src/components/CropPicker/styles.ts +8 -5
  24. package/src/components/CropPicker/types.ts +11 -16
  25. package/src/components/CropPicker/utils.ts +95 -0
  26. package/src/components/View/index.tsx +1 -1
  27. package/src/lib/hooks/index.ts +0 -1
  28. package/dist/lib/hooks/useCropPicker.d.ts +0 -36
  29. package/dist/lib/hooks/useCropPicker.js +0 -216
  30. package/dist/lib/hooks/useCropPicker.js.map +0 -1
  31. package/src/lib/hooks/useCropPicker.ts +0 -192
@@ -0,0 +1,11 @@
1
+ import { ICSS } from '@codeleap/styles';
2
+ import { ButtonComposition } from '../../Button';
3
+ import { AnyFunction, StylesOf } from '@codeleap/types';
4
+ export type CropPickerFooterProps = {
5
+ footerStyle: ICSS;
6
+ confirmStyles: StylesOf<ButtonComposition>;
7
+ cancelStyles: StylesOf<ButtonComposition>;
8
+ onConfirmCrop: AnyFunction;
9
+ onCancelCrop: AnyFunction;
10
+ };
11
+ export declare const CropPickerFooter: (props: CropPickerFooterProps) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CropPickerFooter = void 0;
4
+ var jsx_runtime_1 = require("@emotion/react/jsx-runtime");
5
+ var Button_1 = require("../../Button");
6
+ var View_1 = require("../../View");
7
+ var CropPickerFooter = function (props) {
8
+ var footerStyle = props.footerStyle, confirmStyles = props.confirmStyles, cancelStyles = props.cancelStyles, onConfirmCrop = props.onConfirmCrop, onCancelCrop = props.onCancelCrop;
9
+ return ((0, jsx_runtime_1.jsxs)(View_1.View, { style: footerStyle, children: [(0, jsx_runtime_1.jsx)(Button_1.Button, { text: 'Cancel', onPress: onCancelCrop, debugName: 'cropModal:cancel', style: cancelStyles }), (0, jsx_runtime_1.jsx)(Button_1.Button, { text: 'Confirm', onPress: onConfirmCrop, debugName: 'cropModal:confirm', style: confirmStyles })] }));
10
+ };
11
+ exports.CropPickerFooter = CropPickerFooter;
12
+ //# sourceMappingURL=CropPickerFooter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CropPickerFooter.js","sourceRoot":"","sources":["../../../../src/components/CropPicker/components/CropPickerFooter.tsx"],"names":[],"mappings":";;;;AACA,uCAAwD;AACxD,mCAAiC;AAW1B,IAAM,gBAAgB,GAAG,UAAC,KAA4B;IAEzD,IAAA,WAAW,GAKT,KAAK,YALI,EACX,aAAa,GAIX,KAAK,cAJM,EACb,YAAY,GAGV,KAAK,aAHK,EACZ,aAAa,GAEX,KAAK,cAFM,EACb,YAAY,GACV,KAAK,aADK,CACL;IAET,OAAO,CACL,wBAAC,WAAI,IAAC,KAAK,EAAE,WAAW,aACtB,uBAAC,eAAM,IACL,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,kBAAkB,EAC7B,KAAK,EAAE,YAAY,GACnB,EACF,uBAAC,eAAM,IACL,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,mBAAmB,EAC9B,KAAK,EAAE,aAAa,GACpB,IACG,CACR,CAAA;AACH,CAAC,CAAA;AAzBY,QAAA,gBAAgB,oBAyB5B"}
@@ -0,0 +1,39 @@
1
+ import { WebInputFile } from '@codeleap/types';
2
+ import { Crop } from 'react-image-crop';
3
+ export type UseCropPicker = {
4
+ file: File;
5
+ aspect?: number;
6
+ minWidth?: number;
7
+ minHeight?: number;
8
+ onCrop?: (croppedFile: WebInputFile | null) => void;
9
+ };
10
+ export declare function useCropPicker({ aspect, minWidth: minW, minHeight: minH, file, onCrop, }: UseCropPicker): {
11
+ containerStyles: {
12
+ width?: undefined;
13
+ height?: undefined;
14
+ maxWidth?: undefined;
15
+ maxHeight?: undefined;
16
+ margin?: undefined;
17
+ } | {
18
+ width: number;
19
+ height: number;
20
+ maxWidth: string;
21
+ maxHeight: string;
22
+ margin: string;
23
+ };
24
+ imageStyles: {
25
+ width?: undefined;
26
+ height?: undefined;
27
+ objectFit?: undefined;
28
+ } | {
29
+ width: number;
30
+ height: number;
31
+ objectFit: "contain";
32
+ };
33
+ handleCropChange: (newCrop: Crop) => void;
34
+ handleConfirmCrop: () => Promise<void>;
35
+ handleCancelCrop: () => void;
36
+ setRelativeCrop: import("react").Dispatch<import("react").SetStateAction<Crop>>;
37
+ crop: Crop;
38
+ image: HTMLImageElement;
39
+ };
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.useCropPicker = useCropPicker;
51
+ var react_1 = require("react");
52
+ var react_2 = require("react");
53
+ var utils_1 = require("./utils");
54
+ function useCropPicker(_a) {
55
+ var _this = this;
56
+ var aspect = _a.aspect, minW = _a.minWidth, minH = _a.minHeight, file = _a.file, onCrop = _a.onCrop;
57
+ var _b = (0, react_2.useState)(null), image = _b[0], setImage = _b[1];
58
+ var _c = (0, react_2.useState)(), crop = _c[0], setCrop = _c[1];
59
+ var _d = (0, react_2.useState)(), relativeCrop = _d[0], setRelativeCrop = _d[1];
60
+ var _e = (0, react_2.useState)(null), imageDimensions = _e[0], setImageDimensions = _e[1];
61
+ var cleanup = function () {
62
+ setRelativeCrop(null);
63
+ setCrop(undefined);
64
+ setImageDimensions(null);
65
+ setTimeout(function () { return setImage(null); }, 500);
66
+ };
67
+ var handleConfirmCrop = function () { return __awaiter(_this, void 0, void 0, function () {
68
+ var _a, preview, croppedBlob, newImage;
69
+ return __generator(this, function (_b) {
70
+ switch (_b.label) {
71
+ case 0: return [4 /*yield*/, (0, utils_1.cropImage)(image, relativeCrop)];
72
+ case 1:
73
+ _a = _b.sent(), preview = _a[0], croppedBlob = _a[1];
74
+ newImage = {
75
+ file: new File([croppedBlob], 'cropped.jpg', {
76
+ type: 'image/jpeg',
77
+ lastModified: Date.now(),
78
+ }),
79
+ preview: preview,
80
+ };
81
+ onCrop(newImage);
82
+ setTimeout(function () { return cleanup(); });
83
+ return [2 /*return*/];
84
+ }
85
+ });
86
+ }); };
87
+ var handleCancelCrop = function () {
88
+ onCrop(null);
89
+ setTimeout(function () { return cleanup(); });
90
+ };
91
+ var loadFile = (0, react_2.useCallback)(function (toReadFile) { return __awaiter(_this, void 0, void 0, function () {
92
+ var imageData, naturalWidth, naturalHeight, dimensions, targetAspect, imageAspect, initialCrop, v;
93
+ return __generator(this, function (_a) {
94
+ switch (_a.label) {
95
+ case 0: return [4 /*yield*/, (0, utils_1.readImage)(toReadFile)];
96
+ case 1:
97
+ imageData = _a.sent();
98
+ naturalWidth = imageData.naturalWidth, naturalHeight = imageData.naturalHeight;
99
+ dimensions = (0, utils_1.calculateProportionalDimensions)(naturalWidth, naturalHeight);
100
+ setImageDimensions(dimensions);
101
+ targetAspect = aspect || dimensions.aspectRatio;
102
+ imageAspect = dimensions.aspectRatio;
103
+ if (aspect) {
104
+ v = imageAspect >= targetAspect
105
+ ? {
106
+ width: ((naturalHeight * targetAspect) / naturalWidth) * 100,
107
+ height: 100,
108
+ }
109
+ : {
110
+ width: 100,
111
+ height: (naturalWidth / targetAspect / naturalHeight) * 100,
112
+ };
113
+ initialCrop = __assign(__assign({}, v), { x: (100 - v.width) / 2, y: (100 - v.height) / 2, unit: '%' });
114
+ }
115
+ else {
116
+ initialCrop = {
117
+ width: 100,
118
+ height: 100,
119
+ x: 0,
120
+ y: 0,
121
+ unit: '%',
122
+ };
123
+ }
124
+ setCrop(initialCrop);
125
+ setRelativeCrop(initialCrop);
126
+ setImage(imageData);
127
+ return [2 /*return*/];
128
+ }
129
+ });
130
+ }); }, []);
131
+ var getMinDimensions = (0, react_2.useCallback)(function () {
132
+ if (!imageDimensions)
133
+ return { minWidth: minW !== null && minW !== void 0 ? minW : 100, minHeight: minH !== null && minH !== void 0 ? minH : 100 };
134
+ var targetAspect = aspect || imageDimensions.aspectRatio;
135
+ var calculatedMinWidth = (minW !== null && minW !== void 0 ? minW : 100) * targetAspect;
136
+ var calculatedMinHeight = minH !== null && minH !== void 0 ? minH : 100;
137
+ return {
138
+ minWidth: Math.max(calculatedMinWidth, 50),
139
+ minHeight: Math.max(calculatedMinHeight, 50),
140
+ };
141
+ }, [aspect, imageDimensions, minW, minH]);
142
+ var handleCropChange = (0, react_2.useCallback)(function (newCrop) {
143
+ if (!imageDimensions) {
144
+ setCrop(newCrop);
145
+ return;
146
+ }
147
+ var _a = getMinDimensions(), minWidth = _a.minWidth, minHeight = _a.minHeight;
148
+ setCrop(__assign(__assign({}, newCrop), { width: newCrop.width < minWidth ? minWidth : newCrop.width, height: newCrop.height < minHeight ? minHeight : newCrop.height }));
149
+ }, [imageDimensions, getMinDimensions]);
150
+ var containerStyles = (0, react_1.useMemo)(function () {
151
+ if (!imageDimensions)
152
+ return {};
153
+ return {
154
+ width: imageDimensions.displayWidth,
155
+ height: imageDimensions.displayHeight,
156
+ maxWidth: '90vw',
157
+ maxHeight: '70vh',
158
+ margin: '0 auto',
159
+ };
160
+ }, [imageDimensions]);
161
+ var imageStyles = (0, react_1.useMemo)(function () {
162
+ if (!imageDimensions)
163
+ return {};
164
+ return {
165
+ width: imageDimensions.displayWidth,
166
+ height: imageDimensions.displayHeight,
167
+ objectFit: 'contain',
168
+ };
169
+ }, [imageDimensions]);
170
+ (0, react_2.useEffect)(function () {
171
+ loadFile(file);
172
+ }, []);
173
+ return {
174
+ containerStyles: containerStyles,
175
+ imageStyles: imageStyles,
176
+ handleCropChange: handleCropChange,
177
+ handleConfirmCrop: handleConfirmCrop,
178
+ handleCancelCrop: handleCancelCrop,
179
+ setRelativeCrop: setRelativeCrop,
180
+ crop: crop,
181
+ image: image,
182
+ };
183
+ }
184
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/components/CropPicker/hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,sCA8JC;AA5KD,+BAA+B;AAE/B,+BAAwD;AAExD,iCAA+E;AAU/E,SAAgB,aAAa,CAAC,EAMd;IANhB,iBA8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O,CAAC,KAAK,EAC1D,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,IAC/D,CAAA;IACJ,CAAC,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC,CAAA;IAEvC,IAAM,eAAe,GAAG,IAAA,eAAO,EAAC;QAC9B,IAAI,CAAC,eAAe;YAAE,OAAO,EAAE,CAAA;QAE/B,OAAO;YACL,KAAK,EAAE,eAAe,CAAC,YAAY;YACnC,MAAM,EAAE,eAAe,CAAC,aAAa;YACrC,QAAQ,EAAE,MAAM;YAChB,SAAS,EAAE,MAAM;YACjB,MAAM,EAAE,QAAQ;SACjB,CAAA;IACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAA;IAErB,IAAM,WAAW,GAAG,IAAA,eAAO,EAAC;QAC1B,IAAI,CAAC,eAAe;YAAE,OAAO,EAAE,CAAA;QAE/B,OAAO;YACL,KAAK,EAAE,eAAe,CAAC,YAAY;YACnC,MAAM,EAAE,eAAe,CAAC,aAAa;YACrC,SAAS,EAAE,SAAkB;SAC9B,CAAA;IACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAA;IAErB,IAAA,iBAAS,EAAC;QACR,QAAQ,CAAC,IAAI,CAAC,CAAA;IAChB,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,eAAe,iBAAA;QACf,WAAW,aAAA;QACX,gBAAgB,kBAAA;QAChB,iBAAiB,mBAAA;QACjB,gBAAgB,kBAAA;QAChB,eAAe,iBAAA;QACf,IAAI,MAAA;QACJ,KAAK,OAAA;KACN,CAAA;AACH,CAAC"}
@@ -1,8 +1,10 @@
1
+ import { StyledComponentProps, AnyRecord, IJSX } from '@codeleap/styles';
1
2
  import { CropPickerProps } from './types';
2
- import { AnyRecord, IJSX, StyledComponentProps } from '@codeleap/styles';
3
3
  import 'react-image-crop/dist/ReactCrop.css';
4
4
  export * from './styles';
5
5
  export * from './types';
6
+ export * from './hooks';
7
+ export * from './components/CropPickerFooter';
6
8
  export declare const CropPicker: {
7
9
  (props: CropPickerProps): import("@emotion/react/jsx-runtime").JSX.Element;
8
10
  styleRegistryName: string;
@@ -24,56 +24,43 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
24
24
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
25
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
26
  };
27
- var __rest = (this && this.__rest) || function (s, e) {
28
- var t = {};
29
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
30
- t[p] = s[p];
31
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
32
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
33
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
34
- t[p[i]] = s[p[i]];
35
- }
36
- return t;
37
- };
38
27
  Object.defineProperty(exports, "__esModule", { value: true });
39
28
  exports.CropPicker = void 0;
40
29
  var jsx_runtime_1 = require("@emotion/react/jsx-runtime");
41
30
  var styles_1 = require("@codeleap/styles");
42
- var lib_1 = require("../../lib");
43
31
  var WebStyleRegistry_1 = require("../../lib/WebStyleRegistry");
44
32
  var useStylesFor_1 = require("../../lib/hooks/useStylesFor");
45
- var FileInput_1 = require("../FileInput");
46
- var Modal_1 = require("../Modal");
47
- var Button_1 = require("../Button");
48
- var LoadingOverlay_1 = require("../LoadingOverlay");
49
- var ReactCrop = require('react-image-crop').Component;
33
+ var View_1 = require("../View");
34
+ var ActivityIndicator_1 = require("../ActivityIndicator");
35
+ var CropPickerFooter_1 = require("./components/CropPickerFooter");
50
36
  require("react-image-crop/dist/ReactCrop.css");
37
+ var ReactCrop = require('react-image-crop').Component;
51
38
  __exportStar(require("./styles"), exports);
52
39
  __exportStar(require("./types"), exports);
40
+ __exportStar(require("./hooks"), exports);
41
+ __exportStar(require("./components/CropPickerFooter"), exports);
53
42
  var CropPicker = function (props) {
54
- var _a = __assign(__assign({}, exports.CropPicker.defaultProps), props), onFileSelect = _a.onFileSelect, targetCrop = _a.targetCrop, modalProps = _a.modalProps, title = _a.title, confirmButton = _a.confirmButton, debugName = _a.debugName, handle = _a.handle, withLoading = _a.withLoading, style = _a.style, confirmButtonProps = _a.confirmButtonProps, ref = _a.ref, fileInputProps = __rest(_a, ["onFileSelect", "targetCrop", "modalProps", "title", "confirmButton", "debugName", "handle", "withLoading", "style", "confirmButtonProps", "ref"]);
55
- var _b = handle || (0, lib_1.useCropPicker)(__assign({ onFileSelect: onFileSelect, ref: ref }, targetCrop)), onConfirmCrop = _b.onConfirmCrop, onFilesReturned = _b.onFilesReturned, onClose = _b.onClose, fileInputRef = _b.fileInputRef, visible = _b.visible, image = _b.image, crop = _b.crop, setRelativeCrop = _b.setRelativeCrop, isLoading = _b.isLoading, handleCropChange = _b.handleCropChange;
43
+ var _a = __assign(__assign({}, exports.CropPicker.defaultProps), props), style = _a.style, handle = _a.handle, reactCrop = _a.reactCrop, aspect = _a.aspect, children = _a.children, FooterComponent = _a.FooterComponent;
56
44
  var styles = (0, useStylesFor_1.useStylesFor)(exports.CropPicker.styleRegistryName, style);
57
- var composition = (0, styles_1.useCompositionStyles)(['confirmButton', 'modal'], styles);
58
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(FileInput_1.FileInput
59
- // @ts-ignore
60
- , __assign({
61
- // @ts-ignore
62
- ref: fileInputRef, onChange: function (files) { return onFilesReturned(files); } }, fileInputProps)), (0, jsx_runtime_1.jsxs)(Modal_1.Modal, __assign({ visible: visible, toggle: onClose, title: title, footer: (0, jsx_runtime_1.jsx)(Button_1.Button, __assign({ text: confirmButton, style: composition === null || composition === void 0 ? void 0 : composition.confirmButton, onPress: onConfirmCrop, debugName: debugName }, confirmButtonProps)) }, modalProps, { style: composition === null || composition === void 0 ? void 0 : composition.modal, children: [!!(image === null || image === void 0 ? void 0 : image.src) ? ((0, jsx_runtime_1.jsx)(ReactCrop, __assign({ crop: crop, onChange: handleCropChange, onComplete: function (_, relCrop) { return setRelativeCrop(relCrop); } }, targetCrop, { style: styles.previewSize, children: (0, jsx_runtime_1.jsx)("img", { src: image === null || image === void 0 ? void 0 : image.src,
63
- // @ts-ignore
64
- css: [styles.cropPreview, styles.previewSize] }) }))) : null, withLoading ? (0, jsx_runtime_1.jsx)(LoadingOverlay_1.LoadingOverlay, { debugName: 'CropPicker', visible: isLoading }) : null] }))] }));
45
+ var compositionStyles = (0, styles_1.useCompositionStyles)(['indicator', 'confirm', 'cancel'], styles);
46
+ if (!handle)
47
+ return null;
48
+ var image = handle.image, crop = handle.crop, setRelativeCrop = handle.setRelativeCrop, handleCropChange = handle.handleCropChange, handleConfirmCrop = handle.handleConfirmCrop, handleCancelCrop = handle.handleCancelCrop;
49
+ if (!(image === null || image === void 0 ? void 0 : image.src))
50
+ return (0, jsx_runtime_1.jsx)(View_1.View, { style: styles.loadingWrapper, children: (0, jsx_runtime_1.jsx)(ActivityIndicator_1.ActivityIndicator, { style: compositionStyles.indicator, debugName: 'CropPickerLoading' }) });
51
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ReactCrop, __assign({}, reactCrop, { crop: crop, onChange: handleCropChange, onComplete: function (_, relCrop) { return setRelativeCrop(relCrop); }, style: styles.crop, aspect: aspect !== null && aspect !== void 0 ? aspect : reactCrop === null || reactCrop === void 0 ? void 0 : reactCrop.aspect, children: (0, jsx_runtime_1.jsx)("img", { src: image.src,
52
+ // @ts-ignore
53
+ css: [styles === null || styles === void 0 ? void 0 : styles.image] }) })), children, (0, jsx_runtime_1.jsx)(FooterComponent, { footerStyle: styles.footer, confirmStyles: compositionStyles.confirm, cancelStyles: compositionStyles.cancel, onConfirmCrop: handleConfirmCrop, onCancelCrop: handleCancelCrop })] }));
65
54
  };
66
55
  exports.CropPicker = CropPicker;
67
56
  exports.CropPicker.styleRegistryName = 'CropPicker';
68
- exports.CropPicker.elements = ['previewSize', 'cropPreview', 'confirmButton', 'modal'];
69
- exports.CropPicker.rootElement = 'previewSize';
57
+ exports.CropPicker.elements = ['crop', 'image', 'footer', 'confirm', 'cancel', 'indicator', 'loadingWrapper'];
58
+ exports.CropPicker.rootElement = 'crop';
70
59
  exports.CropPicker.withVariantTypes = function (styles) {
71
60
  return exports.CropPicker;
72
61
  };
73
62
  exports.CropPicker.defaultProps = {
74
- title: 'Crop Image',
75
- confirmButton: 'Confirm Crop',
76
- withLoading: false,
63
+ FooterComponent: CropPickerFooter_1.CropPickerFooter,
77
64
  };
78
65
  WebStyleRegistry_1.WebStyleRegistry.registerComponent(exports.CropPicker);
79
66
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/CropPicker/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAAiF;AAEjF,iCAAyC;AACzC,+DAA6D;AAC7D,6DAA2D;AAE3D,0CAAsD;AACtD,kCAAgC;AAChC,oCAAkC;AAClC,oDAAkD;AAElD,IAAM,SAAS,GAAsB,OAAO,CAAC,kBAAkB,CAAC,CAAC,SAAS,CAAA;AAE1E,+CAA4C;AAE5C,2CAAwB;AACxB,0CAAuB;AAEhB,IAAM,UAAU,GAAG,UAAC,KAAsB;IAC/C,IAAM,2BAcD,kBAAU,CAAC,YAAY,GACvB,KAAK,CACT,EAfC,YAAY,kBAAA,EACZ,UAAU,gBAAA,EACV,UAAU,gBAAA,EACV,KAAK,WAAA,EACL,aAAa,mBAAA,EACb,SAAS,eAAA,EACT,MAAM,YAAA,EACN,WAAW,iBAAA,EACX,KAAK,WAAA,EACL,kBAAkB,wBAAA,EAClB,GAAG,SAAA,EACA,cAAc,cAZb,kJAaL,CAGA,CAAA;IAEK,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AS,CAAE,MAAM,YAEnC,gCACE,GAAG,EAAE,KAAK,CAAC,GAAG;oBACd,aAAa;oBACb,GAAG,EAAE,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,GACpB,IACQ,EAEX,QAAQ,EAET,uBAAC,eAAe,IACd,WAAW,EAAE,MAAM,CAAC,MAAM,EAC1B,aAAa,EAAE,iBAAiB,CAAC,OAAO,EACxC,YAAY,EAAE,iBAAiB,CAAC,MAAM,EACtC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,GAC9B,IACD,CACJ,CAAA;AACH,CAAC,CAAA;AAzDY,QAAA,UAAU,cAyDtB;AAED,kBAAU,CAAC,iBAAiB,GAAG,YAAY,CAAA;AAC3C,kBAAU,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAA;AACrG,kBAAU,CAAC,WAAW,GAAG,MAAM,CAAA;AAC/B,kBAAU,CAAC,gBAAgB,GAAG,UAAsB,MAAS;IAC3D,OAAO,kBAAmF,CAAA;AAC5F,CAAC,CAAA;AAED,kBAAU,CAAC,YAAY,GAAG;IACxB,eAAe,EAAE,mCAAgB;CACN,CAAA;AAE7B,mCAAgB,CAAC,iBAAiB,CAAC,kBAAU,CAAC,CAAA"}
@@ -1,3 +1,3 @@
1
+ import { ActivityIndicatorComposition } from '../ActivityIndicator';
1
2
  import { ButtonComposition } from '../Button';
2
- import { ModalComposition } from '../Modal';
3
- export type CropPickerComposition = 'cropPreview' | 'previewSize' | `confirmButton${Capitalize<ButtonComposition>}` | `modal${Capitalize<ModalComposition>}`;
3
+ export type CropPickerComposition = 'crop' | 'image' | 'footer' | `indicator${Capitalize<ActivityIndicatorComposition>}` | `confirm${Capitalize<ButtonComposition>}` | `cancel${Capitalize<ButtonComposition>}` | 'loadingWrapper';
@@ -1,22 +1,20 @@
1
1
  import { StyledProp } from '@codeleap/styles';
2
- import { FileInputProps, FileInputRef } from '../FileInput';
2
+ import { FileInputRef } from '../FileInput';
3
+ import type { ReactCropProps } from 'react-image-crop';
3
4
  import { CropPickerComposition } from './styles';
4
- import { ReactCropProps } from 'react-image-crop';
5
- import { ModalProps } from '../Modal';
6
- import { useCropPicker } from '../../lib';
7
- import { ButtonProps } from '../Button';
5
+ import React from 'react';
6
+ import { useCropPicker } from './hooks';
8
7
  import { RefObject } from 'react';
9
- export type BaseCropProps = Partial<ReactCropProps>;
10
- export type CropPickerProps = Partial<FileInputProps> & {
11
- style?: StyledProp<CropPickerComposition>;
12
- targetCrop?: BaseCropProps;
13
- modalProps?: Partial<ModalProps>;
14
- title?: string;
15
- confirmButton?: string;
8
+ import { CropPickerFooterProps } from './components/CropPickerFooter';
9
+ type NativeCropProps = Omit<ReactCropProps, 'crop' | 'onChange' | 'onComplete' | 'style'>;
10
+ export type CropPickerProps = {
11
+ FooterComponent?: React.ComponentType<Partial<CropPickerFooterProps>>;
16
12
  debugName: string;
13
+ style?: StyledProp<CropPickerComposition>;
17
14
  handle?: ReturnType<typeof useCropPicker>;
18
- withLoading?: boolean;
19
- confirmButtonProps?: Partial<ButtonProps>;
15
+ aspect?: number;
16
+ reactCrop?: NativeCropProps;
17
+ children?: React.ReactNode;
20
18
  ref?: RefObject<FileInputRef | null>;
21
19
  };
22
- export type ImageReading = HTMLImageElement;
20
+ export {};
@@ -0,0 +1,10 @@
1
+ import { Crop } from 'react-image-crop';
2
+ export declare function readImage(file: File | Blob): Promise<HTMLImageElement>;
3
+ export declare function cropImage(image: HTMLImageElement, crop: Crop): Promise<[string, Blob]>;
4
+ export declare const calculateProportionalDimensions: (naturalWidth: number, naturalHeight: number) => {
5
+ naturalWidth: number;
6
+ naturalHeight: number;
7
+ displayWidth: number;
8
+ displayHeight: number;
9
+ aspectRatio: number;
10
+ };
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.calculateProportionalDimensions = void 0;
40
+ exports.readImage = readImage;
41
+ exports.cropImage = cropImage;
42
+ function readImage(file) {
43
+ return new Promise(function (resolve, reject) {
44
+ var reader = new FileReader();
45
+ reader.onload = function () {
46
+ var image = new Image();
47
+ image.onload = function () { return resolve(image); };
48
+ image.onerror = function () { return reject(new Error('Failed to load image')); };
49
+ image.src = reader.result;
50
+ };
51
+ reader.onerror = function () { return reject(new Error('Failed to read file')); };
52
+ reader.readAsDataURL(file);
53
+ });
54
+ }
55
+ function cropImage(image, crop) {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var canvas, ctx, scaleX, scaleY, blob, croppedImage, error_1;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0:
61
+ if (!crop.width || !crop.height) {
62
+ throw new Error('Invalid crop dimensions');
63
+ }
64
+ canvas = document.createElement('canvas');
65
+ ctx = canvas.getContext('2d', { willReadFrequently: true });
66
+ if (!ctx) {
67
+ throw new Error('Could not get canvas 2d context');
68
+ }
69
+ scaleX = image.naturalWidth / 100;
70
+ scaleY = image.naturalHeight / 100;
71
+ canvas.width = crop.width * scaleX;
72
+ canvas.height = crop.height * scaleY;
73
+ ctx.drawImage(image, crop.x * scaleX, crop.y * scaleY, canvas.width, canvas.height, 0, 0, canvas.width, canvas.height);
74
+ _a.label = 1;
75
+ case 1:
76
+ _a.trys.push([1, 4, , 5]);
77
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
78
+ canvas.toBlob(function (blob) { return blob ? resolve(blob) : reject(new Error('Canvas is empty')); }, 'image/png', 1);
79
+ })];
80
+ case 2:
81
+ blob = _a.sent();
82
+ return [4 /*yield*/, readImage(blob)];
83
+ case 3:
84
+ croppedImage = _a.sent();
85
+ return [2 /*return*/, [croppedImage.src, blob]];
86
+ case 4:
87
+ error_1 = _a.sent();
88
+ throw new Error("Failed to crop image: ".concat(error_1 instanceof Error ? error_1.message : String(error_1)));
89
+ case 5: return [2 /*return*/];
90
+ }
91
+ });
92
+ });
93
+ }
94
+ var calculateProportionalDimensions = function (naturalWidth, naturalHeight) {
95
+ var aspectRatio = naturalWidth / naturalHeight;
96
+ var maxWidth = 600;
97
+ var maxHeight = 400;
98
+ var displayWidth = naturalWidth;
99
+ var displayHeight = naturalHeight;
100
+ if (displayHeight > maxHeight) {
101
+ displayHeight = maxHeight;
102
+ displayWidth = displayHeight * aspectRatio;
103
+ }
104
+ if (displayWidth > maxWidth) {
105
+ displayWidth = maxWidth;
106
+ displayHeight = displayWidth / aspectRatio;
107
+ }
108
+ return {
109
+ naturalWidth: naturalWidth,
110
+ naturalHeight: naturalHeight,
111
+ displayWidth: Math.round(displayWidth),
112
+ displayHeight: Math.round(displayHeight),
113
+ aspectRatio: aspectRatio,
114
+ };
115
+ };
116
+ exports.calculateProportionalDimensions = calculateProportionalDimensions;
117
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/CropPicker/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,8BAcC;AAED,8BAgDC;AAhED,SAAgB,SAAS,CAAC,IAAiB;IACzC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,IAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAA;QAE/B,MAAM,CAAC,MAAM,GAAG;YACd,IAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAA;YACzB,KAAK,CAAC,MAAM,GAAG,cAAM,OAAA,OAAO,CAAC,KAAK,CAAC,EAAd,CAAc,CAAA;YACnC,KAAK,CAAC,OAAO,GAAG,cAAM,OAAA,MAAM,CAAC,IAAI,KAAK,C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,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;QACtC,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;QACxC,WAAW,aAAA;KACZ,CAAA;AACH,CAAC,CAAA;AA1BY,QAAA,+BAA+B,mCA0B3C"}
@@ -15,6 +15,5 @@ export * from './useWindowFocus';
15
15
  export * from './useWindowSize';
16
16
  export * from './useKeydown';
17
17
  export * from './useRefresh';
18
- export * from './useCropPicker';
19
18
  export * from './useFileInput';
20
19
  export * from './useStylesFor';
@@ -31,7 +31,6 @@ __exportStar(require("./useWindowFocus"), exports);
31
31
  __exportStar(require("./useWindowSize"), exports);
32
32
  __exportStar(require("./useKeydown"), exports);
33
33
  __exportStar(require("./useRefresh"), exports);
34
- __exportStar(require("./useCropPicker"), exports);
35
34
  __exportStar(require("./useFileInput"), exports);
36
35
  __exportStar(require("./useStylesFor"), exports);
37
36
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC;AAClC,6DAA0C;AAC1C,uDAAoC;AACpC,6CAA0B;AAC1B,oDAAiC;AACjC,kDAA+B;AAC/B,uDAAoC;AACpC,kDAA+B;AAC/B,gDAA6B;AAC7B,oDAAiC;AACjC,wDAAqC;AACrC,oDAAiC;AACjC,6DAA0C;AAC1C,mDAAgC;AAChC,kDAA+B;AAC/B,+CAA4B;AAC5B,+CAA4B;AAC5B,kDAA+B;AAC/B,iDAA8B;AAC9B,iDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC;AAClC,6DAA0C;AAC1C,uDAAoC;AACpC,6CAA0B;AAC1B,oDAAiC;AACjC,kDAA+B;AAC/B,uDAAoC;AACpC,kDAA+B;AAC/B,gDAA6B;AAC7B,oDAAiC;AACjC,wDAAqC;AACrC,oDAAiC;AACjC,6DAA0C;AAC1C,mDAAgC;AAChC,kDAA+B;AAC/B,+CAA4B;AAC5B,+CAA4B;AAC5B,iDAA8B;AAC9B,iDAA8B"}