@threekit-tools/treble 0.0.81 → 0.0.84
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/dist/Treble/Treble.d.ts +11 -5
- package/dist/Treble/Treble.js +41 -12
- package/dist/Treble/index.d.ts +2 -2
- package/dist/Treble/index.js +7 -3
- package/dist/Treble/{Snapshots.d.ts → snapshots.d.ts} +4 -9
- package/dist/Treble/snapshots.js +247 -0
- package/dist/Treble/{Wishlist.d.ts → wishlist.d.ts} +2 -6
- package/dist/Treble/wishlist.js +135 -0
- package/dist/api/catalog.js +6 -6
- package/dist/api/configurations.js +3 -3
- package/dist/api/datatables.js +5 -5
- package/dist/api/index.js +5 -1
- package/dist/api/orders.d.ts +5 -7
- package/dist/api/orders.js +12 -12
- package/dist/api/price.js +2 -2
- package/dist/api/products.js +2 -2
- package/dist/components/Accordion/index.js +6 -7
- package/dist/components/AttributeTitle/index.d.ts +0 -9
- package/dist/components/AttributeTitle/index.js +0 -9
- package/dist/components/AttributeValue/index.d.ts +0 -6
- package/dist/components/AttributeValue/index.js +2 -8
- package/dist/components/Button/index.d.ts +0 -27
- package/dist/components/Button/index.js +0 -27
- package/dist/components/Cards/index.d.ts +2 -55
- package/dist/components/Cards/index.js +3 -60
- package/dist/components/Drawer/index.js +7 -16
- package/dist/components/Dropdown/index.d.ts +2 -59
- package/dist/components/Dropdown/index.js +11 -72
- package/dist/components/FlatForm/index.d.ts +0 -21
- package/dist/components/FlatForm/index.js +10 -25
- package/dist/components/Modal/index.js +2 -15
- package/dist/components/Player/index.d.ts +1 -1
- package/dist/components/PortalToArOverlay/index.js +5 -1
- package/dist/components/PortalToElement/index.js +0 -8
- package/dist/components/ProductDescription/index.d.ts +0 -6
- package/dist/components/ProductDescription/index.js +0 -6
- package/dist/components/ProductName/index.d.ts +0 -9
- package/dist/components/ProductName/index.js +0 -9
- package/dist/components/Share/index.d.ts +0 -12
- package/dist/components/Share/index.js +2 -14
- package/dist/components/Snapshots/index.d.ts +0 -8
- package/dist/components/Snapshots/index.js +2 -10
- package/dist/components/Strips/index.d.ts +2 -55
- package/dist/components/Strips/index.js +3 -60
- package/dist/components/Swatch/index.d.ts +2 -64
- package/dist/components/Swatch/index.js +3 -69
- package/dist/components/Switch/index.d.ts +2 -34
- package/dist/components/Switch/index.js +2 -38
- package/dist/components/Tabs/index.js +5 -1
- package/dist/components/TextInput/index.d.ts +2 -1
- package/dist/components/TextInput/index.js +2 -3
- package/dist/components/ThreekitProvider/index.js +5 -1
- package/dist/components/Tiles/index.d.ts +2 -29
- package/dist/components/Tiles/index.js +3 -33
- package/dist/components/TilesGroup/index.d.ts +2 -26
- package/dist/components/TilesGroup/index.js +3 -30
- package/dist/components/TotalPrice/index.d.ts +0 -6
- package/dist/components/TotalPrice/index.js +0 -6
- package/dist/components/TrebleApp/index.js +5 -1
- package/dist/components/Upload/index.d.ts +2 -1
- package/dist/components/Upload/index.js +21 -17
- package/dist/components/UploadArea/index.d.ts +2 -1
- package/dist/components/UploadArea/index.js +18 -15
- package/dist/components/Wishlist/index.d.ts +0 -3
- package/dist/components/Wishlist/index.js +12 -10
- package/dist/components/Zoom/index.d.ts +0 -17
- package/dist/components/Zoom/index.js +5 -21
- package/dist/components/formComponents.d.ts +12 -0
- package/dist/components/formComponents.js +10 -8
- package/dist/components/message/index.d.ts +0 -9
- package/dist/components/message/index.js +4 -31
- package/dist/connection.js +2 -2
- package/dist/constants.d.ts +0 -49
- package/dist/constants.js +1 -59
- package/dist/hooks/useAttribute/index.d.ts +1 -1
- package/dist/hooks/useAttribute/index.js +6 -6
- package/dist/hooks/useConfigurationLoader/index.js +5 -5
- package/dist/hooks/useNestedConfigurator/index.js +2 -2
- package/dist/hooks/useShare/index.js +3 -3
- package/dist/hooks/useSingleAnimation/index.js +20 -25
- package/dist/http/datatables.js +0 -1
- package/dist/http/index.js +5 -1
- package/dist/http/orders.d.ts +6 -8
- package/dist/icons/Spinner.js +5 -1
- package/dist/icons/index.d.ts +0 -41
- package/dist/icons/index.js +0 -42
- package/dist/index.d.ts +42 -3
- package/dist/index.js +84 -26
- package/dist/store/attributes.d.ts +0 -12
- package/dist/store/attributes.js +2 -15
- package/dist/store/index.d.ts +1 -1
- package/dist/store/price.d.ts +0 -12
- package/dist/store/price.js +2 -16
- package/dist/store/product.d.ts +6 -21
- package/dist/store/product.js +26 -38
- package/dist/store/translations.d.ts +1 -13
- package/dist/store/translations.js +2 -12
- package/dist/store/treble.d.ts +1 -16
- package/dist/store/treble.js +31 -66
- package/dist/store/wishlist.d.ts +0 -12
- package/dist/store/wishlist.js +4 -17
- package/dist/types.d.ts +118 -65
- package/dist/types.js +54 -0
- package/dist/utils.d.ts +10 -10
- package/dist/utils.js +8 -16
- package/package.json +16 -4
- package/dist/Treble/Snapshots.js +0 -251
- package/dist/Treble/Wishlist.js +0 -136
- package/dist/hooks/useImageEditor/index.d.ts +0 -14
- package/dist/hooks/useImageEditor/index.js +0 -320
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var react_1 = require("react");
|
|
4
|
-
var CANVAS_HEIGHT = 600;
|
|
5
|
-
var CANVAS_WIDTH = 900;
|
|
6
|
-
var INVERT_COLOR = false;
|
|
7
|
-
var APPLY_GRAYSCALE = false;
|
|
8
|
-
var CORNER_BOX_SIZE = 4;
|
|
9
|
-
var CROP_RATIO = 'custom';
|
|
10
|
-
function useImageEditor(image, config) {
|
|
11
|
-
var _a = Object.assign({}, {
|
|
12
|
-
canvasHeight: CANVAS_HEIGHT,
|
|
13
|
-
canvasWidth: CANVAS_WIDTH,
|
|
14
|
-
cornerCircleSize: CORNER_BOX_SIZE,
|
|
15
|
-
cropRatio: CROP_RATIO,
|
|
16
|
-
}, config), canvasHeight = _a.canvasHeight, canvasWidth = _a.canvasWidth, cornerCircleSize = _a.cornerCircleSize;
|
|
17
|
-
var _b = (0, react_1.useState)(INVERT_COLOR), invertColor = _b[0], setInvertColor = _b[1];
|
|
18
|
-
var _c = (0, react_1.useState)(APPLY_GRAYSCALE), applyGrayscale = _c[0], setApplyGrayscale = _c[1];
|
|
19
|
-
var imageRef = (0, react_1.useRef)(null);
|
|
20
|
-
var canvasRef = (0, react_1.useRef)(null);
|
|
21
|
-
var cropStartRef = (0, react_1.useRef)(null);
|
|
22
|
-
var cropBoxRef = (0, react_1.useRef)(null);
|
|
23
|
-
var moveCropBoxOffsetRef = (0, react_1.useRef)(null);
|
|
24
|
-
var resizeCropBoxOffsetRef = (0, react_1.useRef)(null);
|
|
25
|
-
(0, react_1.useEffect)(function () {
|
|
26
|
-
if (!image || !canvasRef.current)
|
|
27
|
-
return;
|
|
28
|
-
var ctx = canvasRef.current.getContext('2d');
|
|
29
|
-
if (!ctx)
|
|
30
|
-
return;
|
|
31
|
-
canvasRef.current.height = canvasHeight;
|
|
32
|
-
canvasRef.current.width = canvasWidth;
|
|
33
|
-
var background = new Image();
|
|
34
|
-
background.src = image;
|
|
35
|
-
background.onload = function () {
|
|
36
|
-
imageRef.current = background;
|
|
37
|
-
drawImage(ctx, background);
|
|
38
|
-
};
|
|
39
|
-
}, [image, canvasHeight, canvasWidth]);
|
|
40
|
-
(0, react_1.useEffect)(function () {
|
|
41
|
-
if (!image)
|
|
42
|
-
return function () { };
|
|
43
|
-
if (canvasRef && canvasRef.current) {
|
|
44
|
-
canvasRef.current.addEventListener('mousedown', handleMouseDown);
|
|
45
|
-
canvasRef.current.addEventListener('mousemove', handleMouseMove);
|
|
46
|
-
canvasRef.current.addEventListener('mouseup', handleMouseUp);
|
|
47
|
-
return function () {
|
|
48
|
-
var _a, _b, _c;
|
|
49
|
-
(_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mousedown', handleMouseDown);
|
|
50
|
-
(_b = canvasRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mousemove', handleMouseMove);
|
|
51
|
-
(_c = canvasRef.current) === null || _c === void 0 ? void 0 : _c.removeEventListener('mouseup', handleMouseUp);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return function () { };
|
|
55
|
-
function handleMouseDown(e) {
|
|
56
|
-
if (cropBoxRef === null || cropBoxRef === void 0 ? void 0 : cropBoxRef.current) {
|
|
57
|
-
if (e.offsetX >= cropBoxRef.current.startX &&
|
|
58
|
-
e.offsetX <= cropBoxRef.current.startX + cropBoxRef.current.deltaX &&
|
|
59
|
-
e.offsetY >= cropBoxRef.current.startY &&
|
|
60
|
-
e.offsetY <= cropBoxRef.current.startY + cropBoxRef.current.deltaY) {
|
|
61
|
-
moveCropBoxOffsetRef.current = { x: e.offsetX, y: e.offsetY };
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (e.offsetX >=
|
|
65
|
-
cropBoxRef.current.startX +
|
|
66
|
-
cropBoxRef.current.deltaX -
|
|
67
|
-
cornerCircleSize / 2 &&
|
|
68
|
-
e.offsetX <=
|
|
69
|
-
cropBoxRef.current.startX +
|
|
70
|
-
cropBoxRef.current.deltaX +
|
|
71
|
-
cornerCircleSize / 2 &&
|
|
72
|
-
e.offsetY >=
|
|
73
|
-
cropBoxRef.current.startY +
|
|
74
|
-
cropBoxRef.current.deltaY -
|
|
75
|
-
cornerCircleSize / 2 &&
|
|
76
|
-
e.offsetY <=
|
|
77
|
-
cropBoxRef.current.startY +
|
|
78
|
-
cropBoxRef.current.deltaY +
|
|
79
|
-
cornerCircleSize / 2) {
|
|
80
|
-
resizeCropBoxOffsetRef.current = { x: e.offsetX, y: e.offsetY };
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
cropStartRef.current = { x: e.offsetX, y: e.offsetY };
|
|
85
|
-
cropBoxRef.current = null;
|
|
86
|
-
}
|
|
87
|
-
function handleMouseMove(e) {
|
|
88
|
-
var _a, _b, _c, _d;
|
|
89
|
-
var ctx = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getContext('2d');
|
|
90
|
-
if (!ctx || !cropBoxRef.current)
|
|
91
|
-
return;
|
|
92
|
-
if ((_b = moveCropBoxOffsetRef.current) === null || _b === void 0 ? void 0 : _b.x) {
|
|
93
|
-
var deltaX = e.offsetX - moveCropBoxOffsetRef.current.x;
|
|
94
|
-
var deltaY = e.offsetY - moveCropBoxOffsetRef.current.y;
|
|
95
|
-
var rect_1 = Object.assign({}, cropBoxRef.current, {
|
|
96
|
-
startX: cropBoxRef.current.startX + deltaX,
|
|
97
|
-
startY: cropBoxRef.current.startY + deltaY,
|
|
98
|
-
});
|
|
99
|
-
draw(ctx, rect_1, { invertColor: invertColor, applyGrayscale: applyGrayscale });
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if ((_c = resizeCropBoxOffsetRef === null || resizeCropBoxOffsetRef === void 0 ? void 0 : resizeCropBoxOffsetRef.current) === null || _c === void 0 ? void 0 : _c.x) {
|
|
103
|
-
var deltaX = e.offsetX - resizeCropBoxOffsetRef.current.x;
|
|
104
|
-
var deltaY = e.offsetY - resizeCropBoxOffsetRef.current.y;
|
|
105
|
-
var rect_2 = Object.assign({}, cropBoxRef.current, {
|
|
106
|
-
deltaX: cropBoxRef.current.deltaX + deltaX,
|
|
107
|
-
deltaY: cropBoxRef.current.deltaY + deltaY,
|
|
108
|
-
});
|
|
109
|
-
draw(ctx, rect_2, { invertColor: invertColor, applyGrayscale: applyGrayscale });
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (!((_d = cropStartRef === null || cropStartRef === void 0 ? void 0 : cropStartRef.current) === null || _d === void 0 ? void 0 : _d.x))
|
|
113
|
-
return;
|
|
114
|
-
var rect = {
|
|
115
|
-
startX: cropStartRef.current.x,
|
|
116
|
-
startY: cropStartRef.current.y,
|
|
117
|
-
deltaX: e.offsetX - cropStartRef.current.x,
|
|
118
|
-
deltaY: e.offsetY - cropStartRef.current.y,
|
|
119
|
-
};
|
|
120
|
-
draw(ctx, rect, { invertColor: invertColor, applyGrayscale: applyGrayscale });
|
|
121
|
-
}
|
|
122
|
-
function handleMouseUp(e) {
|
|
123
|
-
var _a, _b;
|
|
124
|
-
var ctx = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getContext('2d');
|
|
125
|
-
if (!ctx || !cropBoxRef.current || !cropStartRef.current)
|
|
126
|
-
return;
|
|
127
|
-
if (moveCropBoxOffsetRef.current) {
|
|
128
|
-
var deltaX_1 = moveCropBoxOffsetRef.current.x - e.offsetX;
|
|
129
|
-
var deltaY_1 = moveCropBoxOffsetRef.current.y - e.offsetY;
|
|
130
|
-
var rect_3 = Object.assign(cropBoxRef.current, {
|
|
131
|
-
startX: cropBoxRef.current.startX - deltaX_1,
|
|
132
|
-
startY: cropBoxRef.current.startY - deltaY_1,
|
|
133
|
-
});
|
|
134
|
-
draw(ctx, rect_3, { drawCornerBoxes: true, invertColor: invertColor, applyGrayscale: applyGrayscale });
|
|
135
|
-
cropBoxRef.current = rect_3;
|
|
136
|
-
moveCropBoxOffsetRef.current = null;
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if ((_b = resizeCropBoxOffsetRef === null || resizeCropBoxOffsetRef === void 0 ? void 0 : resizeCropBoxOffsetRef.current) === null || _b === void 0 ? void 0 : _b.x) {
|
|
140
|
-
var deltaX_2 = e.offsetX - resizeCropBoxOffsetRef.current.x;
|
|
141
|
-
var deltaY_2 = e.offsetY - resizeCropBoxOffsetRef.current.y;
|
|
142
|
-
var rect_4 = Object.assign({}, cropBoxRef.current, {
|
|
143
|
-
deltaX: cropBoxRef.current.deltaX + deltaX_2,
|
|
144
|
-
deltaY: cropBoxRef.current.deltaY + deltaY_2,
|
|
145
|
-
});
|
|
146
|
-
draw(ctx, rect_4, { drawCornerBoxes: true, invertColor: invertColor, applyGrayscale: applyGrayscale });
|
|
147
|
-
cropBoxRef.current = rect_4;
|
|
148
|
-
resizeCropBoxOffsetRef.current = null;
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
var deltaX = e.offsetX - cropStartRef.current.x;
|
|
152
|
-
var deltaY = e.offsetY - cropStartRef.current.y;
|
|
153
|
-
var rect = {
|
|
154
|
-
startX: deltaX > 0 ? cropStartRef.current.x : cropStartRef.current.x + deltaX,
|
|
155
|
-
startY: deltaY > 0 ? cropStartRef.current.y : cropStartRef.current.y + deltaY,
|
|
156
|
-
deltaX: Math.abs(deltaX),
|
|
157
|
-
deltaY: Math.abs(deltaY),
|
|
158
|
-
};
|
|
159
|
-
cropBoxRef.current = rect;
|
|
160
|
-
draw(ctx, rect, { drawCornerBoxes: true });
|
|
161
|
-
cropStartRef.current = null;
|
|
162
|
-
}
|
|
163
|
-
}, [image, canvasHeight, canvasWidth]);
|
|
164
|
-
// useEffect(() => {
|
|
165
|
-
// if (!image) return;
|
|
166
|
-
// if (canvasRef && canvasRef.current) {
|
|
167
|
-
// canvasRef.current.addEventListener("mousemove", handleMouseMove);
|
|
168
|
-
// return () => {
|
|
169
|
-
// canvasRef.current.removeEventListener("mousemove", handleMouseMove);
|
|
170
|
-
// };
|
|
171
|
-
// }
|
|
172
|
-
// function handleMouseMove(e) {
|
|
173
|
-
// if (cropBoxRef?.current) {
|
|
174
|
-
// if (
|
|
175
|
-
// e.offsetX >= cropBoxRef.current.startX &&
|
|
176
|
-
// e.offsetX <= cropBoxRef.current.startX + cropBoxRef.current.deltaX &&
|
|
177
|
-
// e.offsetY >= cropBoxRef.current.startY &&
|
|
178
|
-
// e.offsetY <= cropBoxRef.current.startY + cropBoxRef.current.deltaY
|
|
179
|
-
// ) {
|
|
180
|
-
// canvasRef.current.style.cursor = "move";
|
|
181
|
-
// return;
|
|
182
|
-
// }
|
|
183
|
-
// if (
|
|
184
|
-
// e.offsetX >=
|
|
185
|
-
// cropBoxRef.current.startX +
|
|
186
|
-
// cropBoxRef.current.deltaX -
|
|
187
|
-
// cornerCircleSize / 2 &&
|
|
188
|
-
// e.offsetX <=
|
|
189
|
-
// cropBoxRef.current.startX +
|
|
190
|
-
// cropBoxRef.current.deltaX +
|
|
191
|
-
// cornerCircleSize / 2 &&
|
|
192
|
-
// e.offsetY >=
|
|
193
|
-
// cropBoxRef.current.startY +
|
|
194
|
-
// cropBoxRef.current.deltaY -
|
|
195
|
-
// cornerCircleSize / 2 &&
|
|
196
|
-
// e.offsetY <=
|
|
197
|
-
// cropBoxRef.current.startY +
|
|
198
|
-
// cropBoxRef.current.deltaY +
|
|
199
|
-
// cornerCircleSize / 2
|
|
200
|
-
// ) {
|
|
201
|
-
// canvasRef.current.style.cursor = "pointer";
|
|
202
|
-
// return;
|
|
203
|
-
// }
|
|
204
|
-
// }
|
|
205
|
-
// canvasRef.current.style.cursor = "default";
|
|
206
|
-
// }
|
|
207
|
-
// }, [image, canvasHeight, canvasWidth]);
|
|
208
|
-
function drawImage(ctx, image, config) {
|
|
209
|
-
var _a = config || {}, invertColor = _a.invertColor, applyGrayscale = _a.applyGrayscale;
|
|
210
|
-
if (invertColor)
|
|
211
|
-
ctx.filter = 'invert(1)';
|
|
212
|
-
else if (applyGrayscale)
|
|
213
|
-
ctx.filter = 'grayscale(1)';
|
|
214
|
-
else
|
|
215
|
-
ctx.filter = 'invert(0)';
|
|
216
|
-
// else ctx.filter = "grayscale(0)";
|
|
217
|
-
var wRatio = ctx.canvas.width / image.width;
|
|
218
|
-
var hRatio = ctx.canvas.height / image.height;
|
|
219
|
-
var ratio = Math.min(wRatio, hRatio);
|
|
220
|
-
var centerOffsetX = (ctx.canvas.width - image.width * ratio) / 2;
|
|
221
|
-
var centerOffsetY = (ctx.canvas.height - image.height * ratio) / 2;
|
|
222
|
-
ctx.drawImage(image, 0, 0, image.width, image.height, centerOffsetX, centerOffsetY, image.width * ratio, image.height * ratio);
|
|
223
|
-
}
|
|
224
|
-
function draw(ctx, rect, config) {
|
|
225
|
-
var _a = config || {}, drawCornerBoxes = _a.drawCornerBoxes, invertColor = _a.invertColor;
|
|
226
|
-
// clear the canvas
|
|
227
|
-
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
228
|
-
// redraw the image
|
|
229
|
-
if (!imageRef.current)
|
|
230
|
-
return;
|
|
231
|
-
drawImage(ctx, imageRef.current, { invertColor: invertColor });
|
|
232
|
-
if (!rect)
|
|
233
|
-
return;
|
|
234
|
-
// redraw one or more things based on their javascript objects
|
|
235
|
-
ctx.beginPath();
|
|
236
|
-
ctx.setLineDash([]);
|
|
237
|
-
ctx.rect(rect.startX, rect.startY, rect.deltaX, rect.deltaY);
|
|
238
|
-
ctx.rect(canvasWidth, 0, 0 - canvasWidth, canvasHeight);
|
|
239
|
-
ctx.closePath();
|
|
240
|
-
ctx.strokeStyle = '#fff';
|
|
241
|
-
ctx.stroke();
|
|
242
|
-
ctx.fillStyle = '#00000055';
|
|
243
|
-
ctx.fill();
|
|
244
|
-
if (!drawCornerBoxes)
|
|
245
|
-
return;
|
|
246
|
-
ctx.beginPath();
|
|
247
|
-
ctx.arc(rect.startX, rect.startY, cornerCircleSize, 0, 2 * Math.PI);
|
|
248
|
-
ctx.fillStyle = '#fff';
|
|
249
|
-
ctx.fill();
|
|
250
|
-
ctx.closePath();
|
|
251
|
-
ctx.beginPath();
|
|
252
|
-
ctx.arc(rect.startX, rect.startY + rect.deltaY, cornerCircleSize, 0, 2 * Math.PI);
|
|
253
|
-
ctx.fillStyle = '#fff';
|
|
254
|
-
ctx.fill();
|
|
255
|
-
ctx.closePath();
|
|
256
|
-
ctx.beginPath();
|
|
257
|
-
ctx.arc(rect.startX + rect.deltaX, rect.startY, cornerCircleSize, 0, 2 * Math.PI);
|
|
258
|
-
ctx.fillStyle = '#fff';
|
|
259
|
-
ctx.fill();
|
|
260
|
-
ctx.closePath();
|
|
261
|
-
ctx.beginPath();
|
|
262
|
-
ctx.arc(rect.startX + rect.deltaX, rect.startY + rect.deltaY, cornerCircleSize, 0, 2 * Math.PI);
|
|
263
|
-
ctx.fillStyle = '#fff';
|
|
264
|
-
ctx.fill();
|
|
265
|
-
ctx.closePath();
|
|
266
|
-
}
|
|
267
|
-
function handleCrop() {
|
|
268
|
-
var _a, _b;
|
|
269
|
-
if (!cropBoxRef.current)
|
|
270
|
-
return;
|
|
271
|
-
var ctx = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getContext('2d');
|
|
272
|
-
if (!ctx || !imageRef.current)
|
|
273
|
-
return;
|
|
274
|
-
var rect = cropBoxRef.current;
|
|
275
|
-
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
276
|
-
drawImage(ctx, imageRef.current, { invertColor: invertColor, applyGrayscale: applyGrayscale });
|
|
277
|
-
var imageData = ctx.getImageData(rect.startX, rect.startY, rect.deltaX, rect.deltaY);
|
|
278
|
-
var clone = (_b = canvasRef.current) === null || _b === void 0 ? void 0 : _b.cloneNode();
|
|
279
|
-
if (!clone)
|
|
280
|
-
return;
|
|
281
|
-
clone.width = rect.deltaX;
|
|
282
|
-
clone.height = rect.deltaY;
|
|
283
|
-
var cloneCtx = clone.getContext('2d');
|
|
284
|
-
if (!cloneCtx)
|
|
285
|
-
return;
|
|
286
|
-
cloneCtx.putImageData(imageData, 0, 0);
|
|
287
|
-
var url = clone.toDataURL();
|
|
288
|
-
console.log(url);
|
|
289
|
-
cropBoxRef.current = null;
|
|
290
|
-
}
|
|
291
|
-
function handleInvert() {
|
|
292
|
-
var _a;
|
|
293
|
-
if (!cropBoxRef.current)
|
|
294
|
-
return;
|
|
295
|
-
var updated = !invertColor;
|
|
296
|
-
setInvertColor(updated);
|
|
297
|
-
var ctx = (_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.getContext('2d');
|
|
298
|
-
if (!ctx)
|
|
299
|
-
return;
|
|
300
|
-
draw(ctx, cropBoxRef.current, {
|
|
301
|
-
invertColor: updated,
|
|
302
|
-
drawCornerBoxes: true,
|
|
303
|
-
applyGrayscale: applyGrayscale,
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
function handleGrayscale() {
|
|
307
|
-
setApplyGrayscale(!applyGrayscale);
|
|
308
|
-
}
|
|
309
|
-
if (!image)
|
|
310
|
-
return [null, null];
|
|
311
|
-
var crop = {
|
|
312
|
-
handleCrop: handleCrop,
|
|
313
|
-
};
|
|
314
|
-
var color = {
|
|
315
|
-
handleInvert: handleInvert,
|
|
316
|
-
handleGrayscale: handleGrayscale,
|
|
317
|
-
};
|
|
318
|
-
return [canvasRef, crop, color];
|
|
319
|
-
}
|
|
320
|
-
exports.default = useImageEditor;
|