@willphan1712000/frontend 1.4.4 → 1.5.1

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/index.mjs CHANGED
@@ -10,6 +10,12 @@ function _array_with_holes(arr) {
10
10
  function _array_without_holes(arr) {
11
11
  if (Array.isArray(arr)) return _array_like_to_array(arr);
12
12
  }
13
+ function _assert_this_initialized(self) {
14
+ if (self === void 0) {
15
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
16
+ }
17
+ return self;
18
+ }
13
19
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
14
20
  try {
15
21
  var info = gen[key](arg);
@@ -39,6 +45,10 @@ function _async_to_generator(fn) {
39
45
  });
40
46
  };
41
47
  }
48
+ function _call_super(_this, derived, args) {
49
+ derived = _get_prototype_of(derived);
50
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
51
+ }
42
52
  function _class_call_check(instance, Constructor) {
43
53
  if (!(instance instanceof Constructor)) {
44
54
  throw new TypeError("Cannot call a class as a function");
@@ -85,6 +95,25 @@ function _extends() {
85
95
  };
86
96
  return _extends.apply(this, arguments);
87
97
  }
98
+ function _get_prototype_of(o) {
99
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
100
+ return o.__proto__ || Object.getPrototypeOf(o);
101
+ };
102
+ return _get_prototype_of(o);
103
+ }
104
+ function _inherits(subClass, superClass) {
105
+ if (typeof superClass !== "function" && superClass !== null) {
106
+ throw new TypeError("Super expression must either be null or a function");
107
+ }
108
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
109
+ constructor: {
110
+ value: subClass,
111
+ writable: true,
112
+ configurable: true
113
+ }
114
+ });
115
+ if (superClass) _set_prototype_of(subClass, superClass);
116
+ }
88
117
  function _iterable_to_array(iter) {
89
118
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
90
119
  }
@@ -188,12 +217,29 @@ function _object_without_properties_loose(source, excluded) {
188
217
  }
189
218
  return target;
190
219
  }
220
+ function _possible_constructor_return(self, call) {
221
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
222
+ return call;
223
+ }
224
+ return _assert_this_initialized(self);
225
+ }
226
+ function _set_prototype_of(o, p) {
227
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
228
+ o.__proto__ = p;
229
+ return o;
230
+ };
231
+ return _set_prototype_of(o, p);
232
+ }
191
233
  function _sliced_to_array(arr, i) {
192
234
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
193
235
  }
194
236
  function _to_consumable_array(arr) {
195
237
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
196
238
  }
239
+ function _type_of(obj) {
240
+ "@swc/helpers - typeof";
241
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
242
+ }
197
243
  function _unsupported_iterable_to_array(o, minLen) {
198
244
  if (!o) return;
199
245
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -202,6 +248,14 @@ function _unsupported_iterable_to_array(o, minLen) {
202
248
  if (n === "Map" || n === "Set") return Array.from(n);
203
249
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
204
250
  }
251
+ function _is_native_reflect_construct() {
252
+ try {
253
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
254
+ } catch (_) {}
255
+ return (_is_native_reflect_construct = function() {
256
+ return !!result;
257
+ })();
258
+ }
205
259
  function _ts_generator(thisArg, body) {
206
260
  var f, y, t, _ = {
207
261
  label: 0,
@@ -1692,42 +1746,44 @@ var styles8 = {
1692
1746
  var styles_default8 = styles8;
1693
1747
  // src/components/Avatar/Avatar.tsx
1694
1748
  import { useEffect as useEffect7, useRef as useRef7, useState as useState7 } from "react";
1695
- import { Fragment, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
1749
+ import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
1696
1750
  var Avatar = function(param) {
1697
- var src = param.src, setValue = param.setValue;
1698
- var setSrc = function setSrc() {
1699
- return _async_to_generator(function() {
1700
- var translatedSrc;
1701
- return _ts_generator(this, function(_state) {
1702
- switch(_state.label){
1703
- case 0:
1704
- return [
1705
- 4,
1706
- Image_default2.FromStringToImageSrc(src)
1707
- ];
1708
- case 1:
1709
- translatedSrc = _state.sent();
1710
- if (!translatedSrc) return [
1711
- 2
1712
- ];
1713
- defaultImage.current = translatedSrc;
1714
- setValue(translatedSrc);
1715
- return [
1716
- 2
1717
- ];
1718
- }
1719
- });
1720
- })();
1721
- };
1751
+ var src = param.src, setValue = param.setValue, options = param.options;
1722
1752
  var _useState7 = _sliced_to_array(useState7(false), 2), isOpen = _useState7[0], setOpen = _useState7[1];
1723
1753
  var _useState71 = _sliced_to_array(useState7(false), 2), isNew = _useState71[0], setNew = _useState71[1];
1754
+ var defaultImage = useRef7(void 0);
1755
+ var initialImage = useRef7(void 0);
1724
1756
  var uploadImageRef = useRef7(null);
1725
- var defaultImage = useRef7("");
1757
+ var isAbleToEdit = initialImage.current ? src !== defaultImage.current && src !== initialImage.current : false;
1758
+ var isAbleToRemove = initialImage.current ? src !== defaultImage.current : false;
1726
1759
  useEffect7(function() {
1727
- setSrc();
1728
- }, [
1729
- src
1730
- ]);
1760
+ (function setSrc() {
1761
+ return _async_to_generator(function() {
1762
+ var _ref, _ref1;
1763
+ return _ts_generator(this, function(_state) {
1764
+ switch(_state.label){
1765
+ case 0:
1766
+ return [
1767
+ 4,
1768
+ Image_default2.FromStringToImageSrc(options === null || options === void 0 ? void 0 : options.defaultImage)
1769
+ ];
1770
+ case 1:
1771
+ defaultImage.current = (_ref = _state.sent()) !== null && _ref !== void 0 ? _ref : options === null || options === void 0 ? void 0 : options.defaultImage;
1772
+ return [
1773
+ 4,
1774
+ Image_default2.FromStringToImageSrc(src)
1775
+ ];
1776
+ case 2:
1777
+ initialImage.current = (_ref1 = _state.sent()) !== null && _ref1 !== void 0 ? _ref1 : src;
1778
+ setValue(src ? initialImage.current : defaultImage.current);
1779
+ return [
1780
+ 2
1781
+ ];
1782
+ }
1783
+ });
1784
+ })();
1785
+ })();
1786
+ }, []);
1731
1787
  return /* @__PURE__ */ jsxs11("div", {
1732
1788
  style: styles_default8.container,
1733
1789
  children: [
@@ -1765,38 +1821,35 @@ var Avatar = function(param) {
1765
1821
  });
1766
1822
  }
1767
1823
  }),
1768
- src !== defaultImage.current && /* @__PURE__ */ jsxs11(Fragment, {
1824
+ isAbleToRemove && /* @__PURE__ */ jsxs11(Button_default, {
1825
+ style: styles_default8.remove,
1826
+ onClick: function() {
1827
+ var _defaultImage_current;
1828
+ setValue((_defaultImage_current = defaultImage.current) !== null && _defaultImage_current !== void 0 ? _defaultImage_current : void 0);
1829
+ setNew(function(prev) {
1830
+ return !prev;
1831
+ });
1832
+ },
1769
1833
  children: [
1770
- /* @__PURE__ */ jsxs11(Button_default, {
1771
- style: styles_default8.remove,
1772
- onClick: function() {
1773
- setValue(defaultImage.current);
1774
- setNew(function(prev) {
1775
- return !prev;
1776
- });
1777
- },
1778
- children: [
1779
- /* @__PURE__ */ jsx13(FaTrashCan, {
1780
- size: others.iconSize,
1781
- color: "red"
1782
- }),
1783
- "Remove"
1784
- ]
1834
+ /* @__PURE__ */ jsx13(FaTrashCan, {
1835
+ size: others.iconSize,
1836
+ color: "red"
1785
1837
  }),
1786
- /* @__PURE__ */ jsxs11(Button_default, {
1787
- style: styles_default8.edit,
1788
- onClick: function() {
1789
- return setOpen(function(prev) {
1790
- return !prev;
1791
- });
1792
- },
1793
- children: [
1794
- /* @__PURE__ */ jsx13(RiEditLine, {
1795
- size: others.iconSize
1796
- }),
1797
- "Edit"
1798
- ]
1799
- })
1838
+ "Remove"
1839
+ ]
1840
+ }),
1841
+ isAbleToEdit && /* @__PURE__ */ jsxs11(Button_default, {
1842
+ style: styles_default8.edit,
1843
+ onClick: function() {
1844
+ return setOpen(function(prev) {
1845
+ return !prev;
1846
+ });
1847
+ },
1848
+ children: [
1849
+ /* @__PURE__ */ jsx13(RiEditLine, {
1850
+ size: others.iconSize
1851
+ }),
1852
+ "Edit"
1800
1853
  ]
1801
1854
  })
1802
1855
  ]
@@ -2050,7 +2103,7 @@ var InputFile = function(_param) {
2050
2103
  };
2051
2104
  var InputFile_default = InputFile;
2052
2105
  // src/components/Image/UploadImage.tsx
2053
- import { Fragment as Fragment2, jsx as jsx17 } from "react/jsx-runtime";
2106
+ import { Fragment, jsx as jsx17 } from "react/jsx-runtime";
2054
2107
  var UploadImage = function(_param) {
2055
2108
  var handleSetSrc = function handleSetSrc(file) {
2056
2109
  return _async_to_generator(function() {
@@ -2078,7 +2131,7 @@ var UploadImage = function(_param) {
2078
2131
  var _param_setSrc = _param.setSrc, setSrc = _param_setSrc === void 0 ? function() {} : _param_setSrc, props = _object_without_properties(_param, [
2079
2132
  "setSrc"
2080
2133
  ]);
2081
- return /* @__PURE__ */ jsx17(Fragment2, {
2134
+ return /* @__PURE__ */ jsx17(Fragment, {
2082
2135
  children: /* @__PURE__ */ jsx17(InputFile_default, _object_spread_props(_object_spread({
2083
2136
  onChoose: handleSetSrc,
2084
2137
  acceptType: "image/*"
@@ -2104,7 +2157,7 @@ var Image = function(_param) {
2104
2157
  };
2105
2158
  var Image_default = Image;
2106
2159
  // src/components/Image/ImageEditor/ImageEditor.tsx
2107
- import { useEffect as useEffect10, useMemo, useRef as useRef10, useState as useState11 } from "react";
2160
+ import { useEffect as useEffect12, useMemo, useRef as useRef10, useState as useState13 } from "react";
2108
2161
  // src/components/Image/ImageEditor/ImageEditor.styles.ts
2109
2162
  var imageEditorStyles = {
2110
2163
  imageEditor: {
@@ -2118,36 +2171,7 @@ var imageEditorStyles = {
2118
2171
  top: 0,
2119
2172
  left: 0,
2120
2173
  backdropFilter: "blur(20px)",
2121
- zIndex: 99,
2122
- paddingLeft: "30px",
2123
- paddingRight: "30px"
2124
- },
2125
- frame: {
2126
- padding: "50px",
2127
- backgroundColor: "white",
2128
- border: "solid 4px #000",
2129
- borderStyle: "dashed",
2130
- borderRadius: "50%",
2131
- overflow: "hidden",
2132
- maxWidth: "500px",
2133
- width: "100%",
2134
- maxHeight: "500px",
2135
- aspectRatio: 1 / 1,
2136
- position: "relative"
2137
- },
2138
- wrapper: {
2139
- position: "absolute",
2140
- transformOrigin: "top left",
2141
- userSelect: "none"
2142
- },
2143
- img: {
2144
- objectFit: "contain",
2145
- position: "absolute",
2146
- top: 0,
2147
- left: 0,
2148
- display: "block",
2149
- zIndex: 1,
2150
- transform: "translate(-50%, -50%)"
2174
+ zIndex: 99
2151
2175
  },
2152
2176
  buttons: {
2153
2177
  display: "flex",
@@ -2155,234 +2179,1218 @@ var imageEditorStyles = {
2155
2179
  alignItems: "center",
2156
2180
  gap: "20px",
2157
2181
  padding: "30px"
2182
+ },
2183
+ instruction: {
2184
+ fontWeight: "bold",
2185
+ fontSize: "20px"
2158
2186
  }
2159
2187
  };
2160
2188
  var ImageEditor_styles_default = imageEditorStyles;
2161
- // src/components/Image/ImageEditor/ImageEditor.tsx
2162
- import { jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
2163
- var ImageEditor = function(param) {
2164
- var src = param.src, _param_setSrc = param.setSrc, setSrc = _param_setSrc === void 0 ? function() {} : _param_setSrc, _param_isOpen = param.isOpen, isOpen = _param_isOpen === void 0 ? false : _param_isOpen, _param_setOpen = param.setOpen, setOpen = _param_setOpen === void 0 ? function() {} : _param_setOpen, _param_isNew = param.isNew, isNew = _param_isNew === void 0 ? false : _param_isNew;
2165
- var createTransform = function createTransform() {
2166
- return _async_to_generator(function() {
2167
- var transform2;
2168
- return _ts_generator(this, function(_state) {
2169
- switch(_state.label){
2170
- case 0:
2171
- if (!frame.current || !wrapper.current || !img.current) return [
2172
- 2
2173
- ];
2174
- transform2 = new Transform(wrapper.current, frame.current);
2175
- return [
2176
- 4,
2177
- transform2.initialize()
2178
- ];
2179
- case 1:
2180
- _state.sent();
2181
- if (transformState.current) {
2182
- transform2.setState(transformState.current);
2183
- } else {
2184
- transform2.reset();
2185
- }
2186
- setTransform(transform2);
2187
- return [
2188
- 2
2189
- ];
2190
- }
2191
- });
2192
- })();
2193
- };
2194
- var handleCanvasToSrc = function handleCanvasToSrc() {
2195
- if (!frame.current || !wrapper.current || !img.current || !transform) return;
2196
- var canvasInstance = new Canvas();
2197
- var _canvasInstance_createCanvas = canvasInstance.createCanvas(700, 700), canvas = _canvasInstance_createCanvas.canvas, context = _canvasInstance_createCanvas.context;
2198
- var _transform_exportData = transform.exportData(), x = _transform_exportData.x, y = _transform_exportData.y, angle = _transform_exportData.angle;
2199
- transformState.current = transform.exportData();
2200
- var _canvasInstance_drawImage = canvasInstance.drawImage(img.current, context, x, y, 1, angle, canvas, frame.current.clientWidth, frame.current.clientHeight), src2 = _canvasInstance_drawImage.src;
2201
- return src2;
2202
- };
2203
- var handleAccept = function handleAccept() {
2204
- setSrc(handleCanvasToSrc());
2205
- setOpen(false);
2206
- };
2207
- var handleCancel = function handleCancel() {
2208
- setOpen(false);
2209
- };
2210
- var handleReset = function handleReset() {
2211
- if (!transform) return;
2212
- transform.reset();
2213
- };
2214
- var frame = useRef10(null);
2215
- var wrapper = useRef10(null);
2216
- var img = useRef10(null);
2217
- var _useState11 = _sliced_to_array(useState11(void 0), 2), transform = _useState11[0], setTransform = _useState11[1];
2218
- var transformState = useRef10(void 0);
2219
- var originalSrc = useMemo(function() {
2220
- transformState.current = void 0;
2221
- return src;
2222
- }, [
2223
- isNew
2224
- ]);
2225
- useEffect10(function() {
2226
- isOpen ? createTransform() : setTransform(void 0);
2227
- }, [
2228
- isOpen
2229
- ]);
2230
- if (!isOpen) return;
2231
- return /* @__PURE__ */ jsxs14("div", {
2232
- style: ImageEditor_styles_default.imageEditor,
2233
- children: [
2234
- /* @__PURE__ */ jsx19("p", {
2235
- children: "Drag, Zoom, or Rotate image"
2236
- }),
2237
- /* @__PURE__ */ jsx19("div", {
2238
- ref: frame,
2239
- style: ImageEditor_styles_default.frame,
2240
- children: /* @__PURE__ */ jsx19("div", {
2241
- ref: wrapper,
2242
- style: ImageEditor_styles_default.wrapper,
2243
- children: /* @__PURE__ */ jsx19("img", {
2244
- src: originalSrc,
2245
- style: ImageEditor_styles_default.img,
2246
- ref: img
2247
- })
2248
- })
2249
- }),
2250
- /* @__PURE__ */ jsxs14("div", {
2251
- style: ImageEditor_styles_default.buttons,
2252
- children: [
2253
- /* @__PURE__ */ jsx19(Button_default, {
2254
- buttonType: "solid",
2255
- content: "Accept",
2256
- onClick: handleAccept
2257
- }),
2258
- /* @__PURE__ */ jsx19(Button_default, {
2259
- buttonType: "solid",
2260
- content: "Cancel",
2261
- onClick: handleCancel
2262
- }),
2263
- /* @__PURE__ */ jsx19(Button_default, {
2264
- buttonType: "solid",
2265
- content: "Reset",
2266
- onClick: handleReset
2267
- })
2268
- ]
2269
- })
2270
- ]
2271
- });
2272
- };
2273
- var ImageEditor_default = ImageEditor;
2274
- // src/utilities/canvas/Canvas.ts
2275
- var Canvas = /*#__PURE__*/ function() {
2189
+ // src/utilities/Transform/Events/MouseEvents.ts
2190
+ var WMouseEvent = /*#__PURE__*/ function() {
2276
2191
  "use strict";
2277
- function Canvas() {
2278
- _class_call_check(this, Canvas);
2192
+ function WMouseEvent(transformOperation2) {
2193
+ _class_call_check(this, WMouseEvent);
2194
+ this.transformOperation = transformOperation2;
2279
2195
  }
2280
- _create_class(Canvas, [
2196
+ _create_class(WMouseEvent, [
2281
2197
  {
2282
- key: "createCanvas",
2283
- value: function createCanvas(width, height) {
2284
- var canvas = document.createElement("canvas");
2285
- var context = canvas.getContext("2d");
2286
- canvas.width = width;
2287
- canvas.height = height;
2288
- return {
2289
- canvas: canvas,
2290
- context: context
2198
+ key: "drag",
2199
+ value: function drag(e) {
2200
+ var _this = this;
2201
+ e.stopPropagation();
2202
+ var controller = new AbortController();
2203
+ var _this_transformOperation_getDimension = this.transformOperation.getDimension(), initX = _this_transformOperation_getDimension.x, initY = _this_transformOperation_getDimension.y;
2204
+ var mousePressX = e.clientX;
2205
+ var mousePressY = e.clientY;
2206
+ var onMouseMove = function(event) {
2207
+ var x = event.clientX;
2208
+ var y = event.clientY;
2209
+ var posX = initX + (x - mousePressX);
2210
+ var posY = initY + (y - mousePressY);
2211
+ _this.transformOperation.setDimension({
2212
+ x: posX,
2213
+ y: posY
2214
+ });
2291
2215
  };
2216
+ var onMouseUp = function() {
2217
+ controller.abort();
2218
+ };
2219
+ window.addEventListener("mousemove", onMouseMove, {
2220
+ signal: controller.signal
2221
+ });
2222
+ window.addEventListener("mouseup", onMouseUp, {
2223
+ signal: controller.signal
2224
+ });
2292
2225
  }
2293
2226
  },
2294
2227
  {
2295
- key: "drawImage",
2296
- value: function drawImage(e, ctx, x, y, scale, angle, canvas, containerWidth, containerHeight) {
2297
- var ratioX = canvas.width / containerWidth;
2298
- var ratioY = canvas.height / containerHeight;
2299
- var finalX = x * ratioX;
2300
- var finalY = y * ratioY;
2301
- var midleWidth = e.width * ratioX;
2302
- var midleHeight = e.height * ratioY;
2303
- var finalWidth = e.width * ratioX * scale;
2304
- var finalHeight = e.height * ratioY * scale;
2305
- ctx.save();
2306
- ctx.translate(finalX + midleWidth / 2, finalY + midleHeight / 2);
2307
- ctx.rotate(angle * Math.PI / 180);
2308
- ctx.drawImage(e, -finalWidth / 2, -finalHeight / 2, finalWidth, finalHeight);
2309
- ctx.restore();
2310
- var src = ctx.canvas.toDataURL();
2311
- var srcEncoded = src.split(",")[1];
2312
- return {
2313
- context: ctx,
2314
- src: src
2228
+ key: "rotate",
2229
+ value: function rotate(e) {
2230
+ var _this = this;
2231
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
2232
+ top: false,
2233
+ bottom: false
2315
2234
  };
2235
+ e.stopPropagation();
2236
+ var controller = new AbortController();
2237
+ var _this_transformOperation_getDimension = this.transformOperation.getDimension(), x = _this_transformOperation_getDimension.x, y = _this_transformOperation_getDimension.y, width = _this_transformOperation_getDimension.width, height = _this_transformOperation_getDimension.height;
2238
+ var centerX = x + width / 2;
2239
+ var centerY = y + height / 2;
2240
+ var _this_transformOperation_getOrigin = this.transformOperation.getOrigin(), xOrigin = _this_transformOperation_getOrigin.x, yOrigin = _this_transformOperation_getOrigin.y;
2241
+ var compensation = options.top ? 0 : 180;
2242
+ compensation = options.bottom ? 180 : 0;
2243
+ var onMouseMove = function(event) {
2244
+ var x2 = event.clientX - xOrigin;
2245
+ var y2 = event.clientY - yOrigin;
2246
+ var angle = Math.atan2(y2 - centerY, x2 - centerX) + Math.PI / 2;
2247
+ angle *= 180 / Math.PI;
2248
+ angle += compensation;
2249
+ _this.transformOperation.setDimension({
2250
+ angle: angle
2251
+ });
2252
+ };
2253
+ var onMouseUp = function() {
2254
+ controller.abort();
2255
+ };
2256
+ window.addEventListener("mousemove", onMouseMove, {
2257
+ signal: controller.signal
2258
+ });
2259
+ window.addEventListener("mouseup", onMouseUp, {
2260
+ signal: controller.signal
2261
+ });
2316
2262
  }
2317
2263
  },
2318
2264
  {
2319
- key: "drawColor",
2320
- value: function drawColor(type, color, ctx, width, ratio) {
2321
- if (type === "") color = "#ffffff";
2322
- if (type === "gradient") {
2323
- var breakdownArr = color.split(",");
2324
- var _ref = [
2325
- Number(breakdownArr[0]),
2326
- breakdownArr[1],
2327
- Number(breakdownArr[2]),
2328
- breakdownArr[3],
2329
- Number(breakdownArr[4])
2330
- ], angle = _ref[0], color1 = _ref[1], percent1 = _ref[2], color2 = _ref[3], percent2 = _ref[4];
2331
- var radians = (angle - 180) * Math.PI / 180;
2332
- var x0 = width / 2 + width / 2 * Math.cos(radians - Math.PI / 2);
2333
- var y0 = width * ratio / 2 + width * ratio / 2 * Math.sin(radians - Math.PI / 2);
2334
- var x1 = width / 2 - width / 2 * Math.cos(radians - Math.PI / 2);
2335
- var y1 = width * ratio / 2 - width * ratio / 2 * Math.sin(radians - Math.PI / 2);
2336
- var gradient = ctx.createLinearGradient(x0, y0, x1, y1);
2337
- gradient.addColorStop(percent1 / 100, color1);
2338
- gradient.addColorStop(percent2 / 100, color2);
2339
- ctx.fillStyle = gradient;
2340
- ctx.fillRect(0, 0, width, width * ratio);
2341
- var srcEncoded = ctx.canvas.toDataURL().split(",")[1];
2342
- return [
2343
- ctx,
2344
- srcEncoded
2345
- ];
2265
+ key: "resize",
2266
+ value: function resize(e, param) {
2267
+ var _this = this;
2268
+ var _param_topLeft = param.topLeft, topLeft = _param_topLeft === void 0 ? false : _param_topLeft, _param_topRight = param.topRight, topRight = _param_topRight === void 0 ? false : _param_topRight, _param_bottomLeft = param.bottomLeft, bottomLeft = _param_bottomLeft === void 0 ? false : _param_bottomLeft, _param_bottomRight = param.bottomRight, bottomRight = _param_bottomRight === void 0 ? false : _param_bottomRight;
2269
+ e.stopPropagation();
2270
+ var controller = new AbortController();
2271
+ var minWidth = 40;
2272
+ var _this_transformOperation_getDimension = this.transformOperation.getDimension(), initX = _this_transformOperation_getDimension.x, initY = _this_transformOperation_getDimension.y, initAngleDegree = _this_transformOperation_getDimension.angle, initW = _this_transformOperation_getDimension.width, initH = _this_transformOperation_getDimension.height, ratio = _this_transformOperation_getDimension.ratio;
2273
+ var _this_transformOperation_getOrigin = this.transformOperation.getOrigin(), xOrigin = _this_transformOperation_getOrigin.x, yOrigin = _this_transformOperation_getOrigin.y;
2274
+ var initAngle = initAngleDegree * Math.PI / 180;
2275
+ var topLeftResizer = [
2276
+ initX,
2277
+ initY,
2278
+ 1
2279
+ ];
2280
+ var topRightResizer = [
2281
+ initX + initW,
2282
+ initY,
2283
+ 1
2284
+ ];
2285
+ var bottomLeftResizer = [
2286
+ initX,
2287
+ initY + initH,
2288
+ 1
2289
+ ];
2290
+ var bottomRightResizer = [
2291
+ initX + initW,
2292
+ initY + initH,
2293
+ 1
2294
+ ];
2295
+ var p, q;
2296
+ if (topLeft) {
2297
+ q = topLeftResizer;
2298
+ p = bottomRightResizer;
2299
+ } else if (topRight) {
2300
+ q = topRightResizer;
2301
+ p = bottomLeftResizer;
2302
+ } else if (bottomLeft) {
2303
+ q = bottomLeftResizer, p = topRightResizer;
2304
+ } else if (bottomRight) {
2305
+ q = bottomRightResizer, p = topLeftResizer;
2346
2306
  } else {
2347
- ctx.fillStyle = color;
2348
- ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
2349
- var srcEncoded1 = ctx.canvas.toDataURL().split(",")[1];
2350
- return [
2351
- ctx,
2352
- srcEncoded1
2353
- ];
2307
+ return;
2354
2308
  }
2309
+ var rotated_p = LinearAlgebra_default.NicolasMattia(p, LinearAlgebra_default.getMiddleVectorFrom(q, p), initAngle);
2310
+ var rotated_q = LinearAlgebra_default.NicolasMattia(q, LinearAlgebra_default.getMiddleVectorFrom(p, q), initAngle);
2311
+ var rotated_diagonal = LinearAlgebra_default.plusVectors(rotated_q, LinearAlgebra_default.getOppositeVector(rotated_p));
2312
+ var rotated_diagonal_magnitude = LinearAlgebra_default.getVectorMagnitude(rotated_diagonal);
2313
+ var onMouseMove = function(event) {
2314
+ var cursor = [
2315
+ event.clientX - xOrigin,
2316
+ event.clientY - yOrigin,
2317
+ 1
2318
+ ];
2319
+ var moved = LinearAlgebra_default.plusVectors(cursor, LinearAlgebra_default.getOppositeVector(rotated_q));
2320
+ var moved_projection_coefficient = LinearAlgebra_default.dotProduct(rotated_diagonal, moved) / (rotated_diagonal_magnitude * rotated_diagonal_magnitude);
2321
+ var moved_projection = LinearAlgebra_default.setCoefficient(moved_projection_coefficient, rotated_diagonal);
2322
+ var moved_q = LinearAlgebra_default.plusVectors(rotated_q, moved_projection);
2323
+ var newP = LinearAlgebra_default.NicolasMattia(rotated_p, LinearAlgebra_default.getMiddleVectorFrom(moved_q, rotated_p), -initAngle);
2324
+ var newQ = LinearAlgebra_default.NicolasMattia(moved_q, LinearAlgebra_default.getMiddleVectorFrom(moved_q, rotated_p), -initAngle);
2325
+ var newWH = LinearAlgebra_default.plusVectors(newQ, LinearAlgebra_default.getOppositeVector(newP));
2326
+ var newW = Math.abs(newWH[0]);
2327
+ if (newW <= minWidth) {
2328
+ newW = minWidth;
2329
+ return;
2330
+ }
2331
+ if (topLeft) {
2332
+ _this.transformOperation.setDimension({
2333
+ x: newP[0] - newW,
2334
+ y: newP[1] - newW / ratio,
2335
+ width: newW,
2336
+ height: newW / ratio
2337
+ });
2338
+ } else if (topRight) {
2339
+ _this.transformOperation.setDimension({
2340
+ x: newP[0],
2341
+ y: newP[1] - newW / ratio,
2342
+ width: newW,
2343
+ height: newW / ratio
2344
+ });
2345
+ } else if (bottomLeft) {
2346
+ _this.transformOperation.setDimension({
2347
+ x: newP[0] - newW,
2348
+ y: newP[1],
2349
+ width: newW,
2350
+ height: newW / ratio
2351
+ });
2352
+ } else if (bottomRight) {
2353
+ _this.transformOperation.setDimension({
2354
+ x: newP[0],
2355
+ y: newP[1],
2356
+ width: newW,
2357
+ height: newW / ratio
2358
+ });
2359
+ } else {
2360
+ return;
2361
+ }
2362
+ };
2363
+ var onMouseUp = function() {
2364
+ controller.abort();
2365
+ };
2366
+ window.addEventListener("mousemove", onMouseMove, {
2367
+ signal: controller.signal
2368
+ });
2369
+ window.addEventListener("mouseup", onMouseUp, {
2370
+ signal: controller.signal
2371
+ });
2355
2372
  }
2356
2373
  }
2357
2374
  ]);
2358
- return Canvas;
2375
+ return WMouseEvent;
2359
2376
  }();
2360
- // src/utilities/canvas/Image.ts
2361
- var Image2 = {
2362
- /**
2363
- * Convert file (blob) to base64 string format
2364
- * @param file
2365
- * @returns
2366
- */ FromFileToImageSrc: function FromFileToImageSrc(file) {
2367
- return new Promise(function(resolve, reject) {
2368
- if (!file) return resolve(null);
2369
- var reader = new FileReader();
2370
- reader.readAsDataURL(file);
2371
- reader.onload = function(readerEvent) {
2372
- var _readerEvent_target;
2373
- if ((_readerEvent_target = readerEvent.target) === null || _readerEvent_target === void 0 ? void 0 : _readerEvent_target.result) {
2374
- var _readerEvent_target1;
2375
- return resolve((_readerEvent_target1 = readerEvent.target) === null || _readerEvent_target1 === void 0 ? void 0 : _readerEvent_target1.result);
2376
- }
2377
- reject("Error getting the image source");
2378
- };
2379
- reader.onerror = function() {
2380
- reject("Error getting the image source");
2381
- };
2382
- });
2383
- },
2384
- FromStringToImageSrc: /**
2385
- * Convert urlst
2377
+ // src/utilities/Transform/Events/TouchEvents.ts
2378
+ var WTouchEvent = /*#__PURE__*/ function() {
2379
+ "use strict";
2380
+ function WTouchEvent(transformOperation2) {
2381
+ _class_call_check(this, WTouchEvent);
2382
+ this.transformOperation = transformOperation2;
2383
+ }
2384
+ _create_class(WTouchEvent, [
2385
+ {
2386
+ key: "drag",
2387
+ value: function drag(e) {
2388
+ var _this = this;
2389
+ e.stopPropagation();
2390
+ var controller = new AbortController();
2391
+ var _this_transformOperation_getDimension = this.transformOperation.getDimension(), initX = _this_transformOperation_getDimension.x, initY = _this_transformOperation_getDimension.y;
2392
+ var mousePressX = e.touches[0].clientX;
2393
+ var mousePressY = e.touches[0].clientY;
2394
+ var onTouchMove = function(event) {
2395
+ var x = event.touches[0].clientX;
2396
+ var y = event.touches[0].clientY;
2397
+ var posX = initX + (x - mousePressX);
2398
+ var posY = initY + (y - mousePressY);
2399
+ _this.transformOperation.setDimension({
2400
+ x: posX,
2401
+ y: posY
2402
+ });
2403
+ };
2404
+ var onTouchEnd = function() {
2405
+ controller.abort();
2406
+ };
2407
+ window.addEventListener("touchmove", onTouchMove, {
2408
+ signal: controller.signal,
2409
+ passive: true
2410
+ });
2411
+ window.addEventListener("touchend", onTouchEnd, {
2412
+ signal: controller.signal
2413
+ });
2414
+ }
2415
+ },
2416
+ {
2417
+ key: "rotate",
2418
+ value: function rotate(e) {
2419
+ var _this = this;
2420
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
2421
+ top: false,
2422
+ bottom: false
2423
+ };
2424
+ e.stopPropagation();
2425
+ var controller = new AbortController();
2426
+ var _this_transformOperation_getDimension = this.transformOperation.getDimension(), x = _this_transformOperation_getDimension.x, y = _this_transformOperation_getDimension.y, width = _this_transformOperation_getDimension.width, height = _this_transformOperation_getDimension.height;
2427
+ var centerX = x + width / 2;
2428
+ var centerY = y + height / 2;
2429
+ var _this_transformOperation_getOrigin = this.transformOperation.getOrigin(), xOrigin = _this_transformOperation_getOrigin.x, yOrigin = _this_transformOperation_getOrigin.y;
2430
+ var compensation = options.top ? 0 : 180;
2431
+ compensation = options.bottom ? 180 : 0;
2432
+ var onTouchMove = function(event) {
2433
+ var x2 = event.touches[0].clientX - xOrigin;
2434
+ var y2 = event.touches[0].clientY - yOrigin;
2435
+ var angle = Math.atan2(y2 - centerY, x2 - centerX) + Math.PI / 2;
2436
+ angle *= 180 / Math.PI;
2437
+ angle += compensation;
2438
+ _this.transformOperation.setDimension({
2439
+ angle: angle
2440
+ });
2441
+ };
2442
+ var onTouchEnd = function() {
2443
+ controller.abort();
2444
+ };
2445
+ window.addEventListener("touchmove", onTouchMove, {
2446
+ signal: controller.signal,
2447
+ passive: true
2448
+ });
2449
+ window.addEventListener("touchend", onTouchEnd, {
2450
+ signal: controller.signal
2451
+ });
2452
+ }
2453
+ },
2454
+ {
2455
+ key: "resize",
2456
+ value: function resize(e, param) {
2457
+ var _this = this;
2458
+ var _param_topLeft = param.topLeft, topLeft = _param_topLeft === void 0 ? false : _param_topLeft, _param_topRight = param.topRight, topRight = _param_topRight === void 0 ? false : _param_topRight, _param_bottomLeft = param.bottomLeft, bottomLeft = _param_bottomLeft === void 0 ? false : _param_bottomLeft, _param_bottomRight = param.bottomRight, bottomRight = _param_bottomRight === void 0 ? false : _param_bottomRight;
2459
+ e.stopPropagation();
2460
+ var controller = new AbortController();
2461
+ var minWidth = 40;
2462
+ var _this_transformOperation_getDimension = this.transformOperation.getDimension(), initX = _this_transformOperation_getDimension.x, initY = _this_transformOperation_getDimension.y, initAngleDegree = _this_transformOperation_getDimension.angle, initW = _this_transformOperation_getDimension.width, initH = _this_transformOperation_getDimension.height, ratio = _this_transformOperation_getDimension.ratio;
2463
+ var _this_transformOperation_getOrigin = this.transformOperation.getOrigin(), xOrigin = _this_transformOperation_getOrigin.x, yOrigin = _this_transformOperation_getOrigin.y;
2464
+ var initAngle = initAngleDegree * Math.PI / 180;
2465
+ var topLeftResizer = [
2466
+ initX,
2467
+ initY,
2468
+ 1
2469
+ ];
2470
+ var topRightResizer = [
2471
+ initX + initW,
2472
+ initY,
2473
+ 1
2474
+ ];
2475
+ var bottomLeftResizer = [
2476
+ initX,
2477
+ initY + initH,
2478
+ 1
2479
+ ];
2480
+ var bottomRightResizer = [
2481
+ initX + initW,
2482
+ initY + initH,
2483
+ 1
2484
+ ];
2485
+ var p, q;
2486
+ if (topLeft) {
2487
+ q = topLeftResizer;
2488
+ p = bottomRightResizer;
2489
+ } else if (topRight) {
2490
+ q = topRightResizer;
2491
+ p = bottomLeftResizer;
2492
+ } else if (bottomLeft) {
2493
+ q = bottomLeftResizer, p = topRightResizer;
2494
+ } else if (bottomRight) {
2495
+ q = bottomRightResizer, p = topLeftResizer;
2496
+ } else {
2497
+ return;
2498
+ }
2499
+ var rotated_p = LinearAlgebra_default.NicolasMattia(p, LinearAlgebra_default.getMiddleVectorFrom(q, p), initAngle);
2500
+ var rotated_q = LinearAlgebra_default.NicolasMattia(q, LinearAlgebra_default.getMiddleVectorFrom(p, q), initAngle);
2501
+ var rotated_diagonal = LinearAlgebra_default.plusVectors(rotated_q, LinearAlgebra_default.getOppositeVector(rotated_p));
2502
+ var rotated_diagonal_magnitude = LinearAlgebra_default.getVectorMagnitude(rotated_diagonal);
2503
+ var onTouchMove = function(event) {
2504
+ var cursor = [
2505
+ event.touches[0].clientX - xOrigin,
2506
+ event.touches[0].clientY - yOrigin,
2507
+ 1
2508
+ ];
2509
+ var moved = LinearAlgebra_default.plusVectors(cursor, LinearAlgebra_default.getOppositeVector(rotated_q));
2510
+ var moved_projection_coefficient = LinearAlgebra_default.dotProduct(rotated_diagonal, moved) / (rotated_diagonal_magnitude * rotated_diagonal_magnitude);
2511
+ var moved_projection = LinearAlgebra_default.setCoefficient(moved_projection_coefficient, rotated_diagonal);
2512
+ var moved_q = LinearAlgebra_default.plusVectors(rotated_q, moved_projection);
2513
+ var newP = LinearAlgebra_default.NicolasMattia(rotated_p, LinearAlgebra_default.getMiddleVectorFrom(moved_q, rotated_p), -initAngle);
2514
+ var newQ = LinearAlgebra_default.NicolasMattia(moved_q, LinearAlgebra_default.getMiddleVectorFrom(moved_q, rotated_p), -initAngle);
2515
+ var newWH = LinearAlgebra_default.plusVectors(newQ, LinearAlgebra_default.getOppositeVector(newP));
2516
+ var newW = Math.abs(newWH[0]);
2517
+ if (newW <= minWidth) {
2518
+ newW = minWidth;
2519
+ return;
2520
+ }
2521
+ if (topLeft) {
2522
+ _this.transformOperation.setDimension({
2523
+ x: newP[0] - newW,
2524
+ y: newP[1] - newW / ratio,
2525
+ width: newW,
2526
+ height: newW / ratio
2527
+ });
2528
+ } else if (topRight) {
2529
+ _this.transformOperation.setDimension({
2530
+ x: newP[0],
2531
+ y: newP[1] - newW / ratio,
2532
+ width: newW,
2533
+ height: newW / ratio
2534
+ });
2535
+ } else if (bottomLeft) {
2536
+ _this.transformOperation.setDimension({
2537
+ x: newP[0] - newW,
2538
+ y: newP[1],
2539
+ width: newW,
2540
+ height: newW / ratio
2541
+ });
2542
+ } else if (bottomRight) {
2543
+ _this.transformOperation.setDimension({
2544
+ x: newP[0],
2545
+ y: newP[1],
2546
+ width: newW,
2547
+ height: newW / ratio
2548
+ });
2549
+ } else {
2550
+ return;
2551
+ }
2552
+ };
2553
+ var onTouchEnd = function() {
2554
+ controller.abort();
2555
+ };
2556
+ window.addEventListener("touchmove", onTouchMove, {
2557
+ signal: controller.signal,
2558
+ passive: true
2559
+ });
2560
+ window.addEventListener("touchend", onTouchEnd, {
2561
+ signal: controller.signal
2562
+ });
2563
+ }
2564
+ }
2565
+ ]);
2566
+ return WTouchEvent;
2567
+ }();
2568
+ // src/components/Image/ImageEditor/MainElements/MainElements.tsx
2569
+ import { useEffect as useEffect11, useState as useState12 } from "react";
2570
+ // src/components/Image/ImageEditor/context.ts
2571
+ import { createContext as createContext4, useContext as useContext4 } from "react";
2572
+ var MyContext3 = createContext4(void 0);
2573
+ function useMyContext3() {
2574
+ var data = useContext4(MyContext3);
2575
+ if (data === void 0) throw new Error("Context is undefined");
2576
+ return data;
2577
+ }
2578
+ // src/components/Image/ImageEditor/MainElements/MainElements.styles.ts
2579
+ var resize = {
2580
+ position: "absolute",
2581
+ backgroundColor: "white",
2582
+ width: "20px",
2583
+ height: "20px",
2584
+ borderRadius: "50%",
2585
+ boxShadow: "rgba(0, 0, 0, 0.35) 0px 5px 15px",
2586
+ transition: "all .1s linear",
2587
+ cursor: "pointer"
2588
+ };
2589
+ var background = {
2590
+ visibility: "hidden",
2591
+ position: "absolute",
2592
+ top: "50%",
2593
+ left: "50%",
2594
+ transform: "translate(-50%, -50%)",
2595
+ width: "60px",
2596
+ height: "60px",
2597
+ borderRadius: "50%",
2598
+ boxShadow: "rgba(0, 0, 0, 0.35) 0px 5px 15px",
2599
+ zIndex: -1,
2600
+ transition: "all .1s linear"
2601
+ };
2602
+ var MainElementStyles = {
2603
+ container: {
2604
+ position: "relative",
2605
+ border: "solid 4px #000",
2606
+ borderStyle: "dashed",
2607
+ borderRadius: "50%",
2608
+ width: "100%",
2609
+ maxWidth: "508px",
2610
+ aspectRatio: 1,
2611
+ display: "flex",
2612
+ justifyContent: "center",
2613
+ alignItems: "center",
2614
+ boxSizing: "border-box"
2615
+ },
2616
+ frame: {
2617
+ borderRadius: "50%",
2618
+ boxSizing: "border-box",
2619
+ padding: "50px",
2620
+ backgroundColor: "white",
2621
+ overflow: "hidden",
2622
+ maxWidth: "500px",
2623
+ width: "100%",
2624
+ maxHeight: "500px",
2625
+ aspectRatio: 1 / 1,
2626
+ position: "relative"
2627
+ },
2628
+ img: {
2629
+ objectFit: "contain",
2630
+ position: "absolute",
2631
+ userSelect: "none",
2632
+ top: 0,
2633
+ left: 0,
2634
+ display: "block",
2635
+ zIndex: 0
2636
+ },
2637
+ controller: {
2638
+ position: "absolute",
2639
+ userSelect: "none",
2640
+ border: "solid 3px #6924d5",
2641
+ top: 0,
2642
+ left: 0
2643
+ },
2644
+ resizeDown: {
2645
+ color: "white",
2646
+ backgroundColor: "#6924d5"
2647
+ },
2648
+ topLeft: _object_spread_props(_object_spread({}, resize), {
2649
+ top: "-10px",
2650
+ left: "-10px"
2651
+ }),
2652
+ topRight: _object_spread_props(_object_spread({}, resize), {
2653
+ top: "-10px",
2654
+ right: "-10px"
2655
+ }),
2656
+ bottomLeft: _object_spread_props(_object_spread({}, resize), {
2657
+ bottom: "-10px",
2658
+ left: "-10px"
2659
+ }),
2660
+ bottomRight: _object_spread_props(_object_spread({}, resize), {
2661
+ bottom: "-10px",
2662
+ right: "-10px"
2663
+ }),
2664
+ buttonBackground: _object_spread({}, background),
2665
+ buttonBackgroundDown: _object_spread_props(_object_spread({}, background), {
2666
+ visibility: "visible"
2667
+ }),
2668
+ rotate: _object_spread_props(_object_spread({}, resize), {
2669
+ top: "-50px",
2670
+ width: "30px",
2671
+ height: "30px",
2672
+ left: "50%",
2673
+ transform: "translate(-50%, 0%)",
2674
+ display: "flex",
2675
+ justifyContent: "center",
2676
+ alignItems: "center",
2677
+ cursor: "alias"
2678
+ }),
2679
+ rotateBottom: _object_spread_props(_object_spread({}, resize), {
2680
+ display: "none",
2681
+ bottom: "-50px",
2682
+ width: "30px",
2683
+ height: "30px",
2684
+ left: "50%",
2685
+ transform: "translate(-50%, 0%)",
2686
+ justifyContent: "center",
2687
+ alignItems: "center",
2688
+ cursor: "alias"
2689
+ }),
2690
+ label: {
2691
+ position: "absolute",
2692
+ top: "-100px",
2693
+ left: "50%",
2694
+ transformOrigin: "left",
2695
+ transform: "translate(-50%, 0)",
2696
+ margin: 0,
2697
+ color: "black",
2698
+ width: "max-content"
2699
+ }
2700
+ };
2701
+ var MainElements_styles_default = MainElementStyles;
2702
+ // src/components/Image/ImageEditor/MainElements/Rotate.tsx
2703
+ import { useEffect as useEffect10, useState as useState11 } from "react";
2704
+ import { FaArrowRotateLeft } from "react-icons/fa6";
2705
+ import { Fragment as Fragment2, jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
2706
+ var Rotate = function() {
2707
+ var _useState11 = _sliced_to_array(useState11(false), 2), rotate = _useState11[0], setRotate = _useState11[1];
2708
+ var _useMyContext3 = useMyContext3(), transformOperation2 = _useMyContext3.transformOperation, refs = _useMyContext3.refs;
2709
+ var mouseEvent = new WMouseEvent(transformOperation2);
2710
+ var touchEvent = new WTouchEvent(transformOperation2);
2711
+ var angle = transformOperation2.getDimension().angle;
2712
+ var handleBackground = function(value) {
2713
+ return value ? MainElements_styles_default.buttonBackgroundDown : MainElements_styles_default.buttonBackground;
2714
+ };
2715
+ useEffect10(function() {
2716
+ var controller = new AbortController();
2717
+ var handler = function() {
2718
+ setRotate(false);
2719
+ };
2720
+ window.addEventListener("mouseup", function() {
2721
+ handler();
2722
+ }, {
2723
+ signal: controller.signal
2724
+ });
2725
+ window.addEventListener("touchend", function() {
2726
+ handler();
2727
+ }, {
2728
+ signal: controller.signal
2729
+ });
2730
+ return function() {
2731
+ controller.abort();
2732
+ };
2733
+ }, []);
2734
+ return /* @__PURE__ */ jsxs14(Fragment2, {
2735
+ children: [
2736
+ /* @__PURE__ */ jsxs14("div", {
2737
+ ref: refs.rotate,
2738
+ style: rotate ? _object_spread({}, MainElements_styles_default.rotate, MainElements_styles_default.resizeDown) : MainElements_styles_default.rotate,
2739
+ onMouseDown: function(e) {
2740
+ setRotate(true);
2741
+ mouseEvent.rotate(e, {
2742
+ top: true
2743
+ });
2744
+ },
2745
+ onTouchStart: function(e) {
2746
+ setRotate(true);
2747
+ touchEvent.rotate(e, {
2748
+ top: true
2749
+ });
2750
+ },
2751
+ children: [
2752
+ /* @__PURE__ */ jsx19("div", {
2753
+ style: handleBackground(rotate)
2754
+ }),
2755
+ /* @__PURE__ */ jsx19(FaArrowRotateLeft, {
2756
+ size: "15"
2757
+ }),
2758
+ rotate && /* @__PURE__ */ jsxs14("p", {
2759
+ style: _object_spread_props(_object_spread({}, MainElements_styles_default.label), {
2760
+ rotate: "".concat(-angle.toFixed(0), "deg")
2761
+ }),
2762
+ children: [
2763
+ angle.toFixed(0),
2764
+ "\xB0"
2765
+ ]
2766
+ })
2767
+ ]
2768
+ }),
2769
+ /* @__PURE__ */ jsxs14("div", {
2770
+ ref: refs.rotateBottom,
2771
+ style: rotate ? _object_spread({}, MainElements_styles_default.rotateBottom, MainElements_styles_default.resizeDown) : _object_spread({}, MainElements_styles_default.rotateBottom),
2772
+ onMouseDown: function(e) {
2773
+ setRotate(true);
2774
+ mouseEvent.rotate(e, {
2775
+ bottom: true
2776
+ });
2777
+ },
2778
+ onTouchStart: function(e) {
2779
+ setRotate(true);
2780
+ touchEvent.rotate(e, {
2781
+ bottom: true
2782
+ });
2783
+ },
2784
+ children: [
2785
+ /* @__PURE__ */ jsx19("div", {
2786
+ style: handleBackground(rotate)
2787
+ }),
2788
+ /* @__PURE__ */ jsx19(FaArrowRotateLeft, {
2789
+ size: "15"
2790
+ }),
2791
+ rotate && /* @__PURE__ */ jsxs14("p", {
2792
+ style: _object_spread_props(_object_spread({}, MainElements_styles_default.label), {
2793
+ top: "auto",
2794
+ bottom: "-100px",
2795
+ rotate: "".concat(-angle.toFixed(0), "deg")
2796
+ }),
2797
+ children: [
2798
+ angle.toFixed(0),
2799
+ "\xB0"
2800
+ ]
2801
+ })
2802
+ ]
2803
+ })
2804
+ ]
2805
+ });
2806
+ };
2807
+ var Rotate_default = Rotate;
2808
+ // src/components/Image/ImageEditor/MainElements/MainElements.tsx
2809
+ import { jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
2810
+ var MainElements = function() {
2811
+ var _useMyContext3 = useMyContext3(), refs = _useMyContext3.refs, imgRefs = _useMyContext3.imgRefs, originalSrc = _useMyContext3.src, transformOperation2 = _useMyContext3.transformOperation;
2812
+ var mouseEvent = new WMouseEvent(transformOperation2);
2813
+ var touchEvent = new WTouchEvent(transformOperation2);
2814
+ var _useState12 = _sliced_to_array(useState12(false), 2), topLeft = _useState12[0], settopLeft = _useState12[1];
2815
+ var _useState121 = _sliced_to_array(useState12(false), 2), topRight = _useState121[0], settopRight = _useState121[1];
2816
+ var _useState122 = _sliced_to_array(useState12(false), 2), bottomLeft = _useState122[0], setbottomLeft = _useState122[1];
2817
+ var _useState123 = _sliced_to_array(useState12(false), 2), bottomRight = _useState123[0], setbottomRight = _useState123[1];
2818
+ var _useState124 = _sliced_to_array(useState12(false), 2), reRender = _useState124[0], triggierReRender = _useState124[1];
2819
+ var _transformOperation2_getDimension = transformOperation2.getDimension(), angle = _transformOperation2_getDimension.angle, width = _transformOperation2_getDimension.width, height = _transformOperation2_getDimension.height;
2820
+ var handleBackground = function(value) {
2821
+ return value ? MainElements_styles_default.buttonBackgroundDown : MainElements_styles_default.buttonBackground;
2822
+ };
2823
+ useEffect11(function() {
2824
+ var controller = new AbortController();
2825
+ var handler = function() {
2826
+ settopLeft(false);
2827
+ settopRight(false);
2828
+ setbottomLeft(false);
2829
+ setbottomRight(false);
2830
+ };
2831
+ window.addEventListener("mousemove", function() {
2832
+ triggierReRender(function(prev) {
2833
+ return !prev;
2834
+ });
2835
+ }, {
2836
+ signal: controller.signal
2837
+ });
2838
+ window.addEventListener("touchmove", function() {
2839
+ triggierReRender(function(prev) {
2840
+ return !prev;
2841
+ });
2842
+ }, {
2843
+ signal: controller.signal
2844
+ });
2845
+ window.addEventListener("mouseup", function() {
2846
+ handler();
2847
+ }, {
2848
+ signal: controller.signal
2849
+ });
2850
+ window.addEventListener("touchend", function() {
2851
+ handler();
2852
+ }, {
2853
+ signal: controller.signal
2854
+ });
2855
+ return function() {
2856
+ controller.abort();
2857
+ };
2858
+ }, [
2859
+ reRender
2860
+ ]);
2861
+ return /* @__PURE__ */ jsxs15("div", {
2862
+ ref: refs.container,
2863
+ style: MainElements_styles_default.container,
2864
+ children: [
2865
+ /* @__PURE__ */ jsx20("div", {
2866
+ ref: refs.frame,
2867
+ style: MainElements_styles_default.frame,
2868
+ children: /* @__PURE__ */ jsx20("img", {
2869
+ src: originalSrc,
2870
+ style: MainElements_styles_default.img,
2871
+ ref: imgRefs.img
2872
+ })
2873
+ }),
2874
+ /* @__PURE__ */ jsxs15("div", {
2875
+ style: MainElements_styles_default.controller,
2876
+ ref: refs.controller,
2877
+ onMouseDown: function(e) {
2878
+ return mouseEvent.drag(e);
2879
+ },
2880
+ onTouchStart: function(e) {
2881
+ return touchEvent.drag(e);
2882
+ },
2883
+ children: [
2884
+ /* @__PURE__ */ jsx20("div", {
2885
+ ref: refs.topLeft,
2886
+ style: topLeft ? _object_spread({}, MainElements_styles_default.topLeft, MainElements_styles_default.resizeDown) : MainElements_styles_default.topLeft,
2887
+ onMouseDown: function(e) {
2888
+ settopLeft(true);
2889
+ mouseEvent.resize(e, {
2890
+ topLeft: true
2891
+ });
2892
+ },
2893
+ onTouchStart: function(e) {
2894
+ settopLeft(true);
2895
+ touchEvent.resize(e, {
2896
+ topLeft: true
2897
+ });
2898
+ },
2899
+ children: /* @__PURE__ */ jsx20("div", {
2900
+ style: handleBackground(topLeft)
2901
+ })
2902
+ }),
2903
+ /* @__PURE__ */ jsx20("div", {
2904
+ ref: refs.topRight,
2905
+ style: topRight ? _object_spread({}, MainElements_styles_default.topRight, MainElements_styles_default.resizeDown) : MainElements_styles_default.topRight,
2906
+ onMouseDown: function(e) {
2907
+ settopRight(true);
2908
+ mouseEvent.resize(e, {
2909
+ topRight: true
2910
+ });
2911
+ },
2912
+ onTouchStart: function(e) {
2913
+ settopRight(true);
2914
+ touchEvent.resize(e, {
2915
+ topRight: true
2916
+ });
2917
+ },
2918
+ children: /* @__PURE__ */ jsx20("div", {
2919
+ style: handleBackground(topRight)
2920
+ })
2921
+ }),
2922
+ /* @__PURE__ */ jsx20("div", {
2923
+ ref: refs.bottomLeft,
2924
+ style: bottomLeft ? _object_spread({}, MainElements_styles_default.bottomLeft, MainElements_styles_default.resizeDown) : MainElements_styles_default.bottomLeft,
2925
+ onMouseDown: function(e) {
2926
+ setbottomLeft(true);
2927
+ mouseEvent.resize(e, {
2928
+ bottomLeft: true
2929
+ });
2930
+ },
2931
+ onTouchStart: function(e) {
2932
+ setbottomLeft(true);
2933
+ touchEvent.resize(e, {
2934
+ bottomLeft: true
2935
+ });
2936
+ },
2937
+ children: /* @__PURE__ */ jsx20("div", {
2938
+ style: handleBackground(bottomLeft)
2939
+ })
2940
+ }),
2941
+ /* @__PURE__ */ jsx20("div", {
2942
+ ref: refs.bottomRight,
2943
+ style: bottomRight ? _object_spread({}, MainElements_styles_default.bottomRight, MainElements_styles_default.resizeDown) : MainElements_styles_default.bottomRight,
2944
+ onMouseDown: function(e) {
2945
+ setbottomRight(true);
2946
+ mouseEvent.resize(e, {
2947
+ bottomRight: true
2948
+ });
2949
+ },
2950
+ onTouchStart: function(e) {
2951
+ setbottomRight(true);
2952
+ touchEvent.resize(e, {
2953
+ bottomRight: true
2954
+ });
2955
+ },
2956
+ children: /* @__PURE__ */ jsx20("div", {
2957
+ style: handleBackground(bottomRight)
2958
+ })
2959
+ }),
2960
+ /* @__PURE__ */ jsx20(Rotate_default, {}),
2961
+ (topLeft || topRight || bottomLeft || bottomRight) && /* @__PURE__ */ jsxs15("p", {
2962
+ style: _object_spread_props(_object_spread({}, MainElements_styles_default.label), {
2963
+ rotate: "".concat(-angle.toFixed(0), "deg")
2964
+ }),
2965
+ children: [
2966
+ "w: ",
2967
+ width.toFixed(0),
2968
+ "px, h: ",
2969
+ height.toFixed(0),
2970
+ "px"
2971
+ ]
2972
+ })
2973
+ ]
2974
+ })
2975
+ ]
2976
+ });
2977
+ };
2978
+ var MainElements_default = MainElements;
2979
+ // src/components/Image/ImageEditor/Instruction.tsx
2980
+ import { jsx as jsx21 } from "react/jsx-runtime";
2981
+ var Instruction = function() {
2982
+ return /* @__PURE__ */ jsx21("p", {
2983
+ style: ImageEditor_styles_default.instruction,
2984
+ children: "Drag, Zoom, or Rotate image"
2985
+ });
2986
+ };
2987
+ var Instruction_default = Instruction;
2988
+ // src/utilities/Transform/TransformOperationExtension.ts
2989
+ var TransformOperationExtension = /*#__PURE__*/ function() {
2990
+ "use strict";
2991
+ function TransformOperationExtension() {
2992
+ _class_call_check(this, TransformOperationExtension);
2993
+ this.xOrigin = 0;
2994
+ this.yOrigin = 0;
2995
+ this.wOrigin = 0;
2996
+ this.hOrigin = 0;
2997
+ this.isSideEffect = false;
2998
+ this.sideEffectList = [];
2999
+ }
3000
+ _create_class(TransformOperationExtension, [
3001
+ {
3002
+ key: "subscribeSideEffect",
3003
+ value: function subscribeSideEffect(element) {
3004
+ this.sideEffectList.push(element);
3005
+ }
3006
+ },
3007
+ {
3008
+ key: "runSideEffectHandler",
3009
+ value: function runSideEffectHandler() {
3010
+ this.sideEffectList.forEach(function(element) {
3011
+ element.runSideEffectHandler();
3012
+ });
3013
+ }
3014
+ },
3015
+ {
3016
+ key: "setSideEffectState",
3017
+ value: function setSideEffectState() {
3018
+ var value = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
3019
+ this.isSideEffect = value;
3020
+ }
3021
+ },
3022
+ {
3023
+ key: "getSideEffectState",
3024
+ value: function getSideEffectState() {
3025
+ return this.isSideEffect;
3026
+ }
3027
+ },
3028
+ {
3029
+ key: "setOrigin",
3030
+ value: function setOrigin(param) {
3031
+ var x = param.x, y = param.y, width = param.width, height = param.height;
3032
+ this.xOrigin = x;
3033
+ this.yOrigin = y;
3034
+ this.wOrigin = width;
3035
+ this.hOrigin = height;
3036
+ }
3037
+ },
3038
+ {
3039
+ key: "getOrigin",
3040
+ value: function getOrigin() {
3041
+ return {
3042
+ x: this.xOrigin,
3043
+ y: this.yOrigin,
3044
+ width: this.wOrigin,
3045
+ height: this.hOrigin
3046
+ };
3047
+ }
3048
+ }
3049
+ ]);
3050
+ return TransformOperationExtension;
3051
+ }();
3052
+ // src/utilities/Transform/TransformOperation.ts
3053
+ var TransformOperation = /*#__PURE__*/ function(TransformOperationExtension) {
3054
+ "use strict";
3055
+ _inherits(TransformOperation, TransformOperationExtension);
3056
+ function TransformOperation() {
3057
+ _class_call_check(this, TransformOperation);
3058
+ var _this;
3059
+ _this = _call_super(this, TransformOperation, arguments);
3060
+ _this.list = [];
3061
+ _this.x = 0;
3062
+ _this.y = 0;
3063
+ _this.angle = 0;
3064
+ _this.width = 0;
3065
+ _this.height = 0;
3066
+ return _this;
3067
+ }
3068
+ _create_class(TransformOperation, [
3069
+ {
3070
+ key: "setPosition",
3071
+ value: function setPosition(position) {
3072
+ this.list.forEach(function(element) {
3073
+ element.setPosition(position);
3074
+ });
3075
+ }
3076
+ },
3077
+ {
3078
+ key: "addEventListener",
3079
+ value: function addEventListener(type, listener, options) {
3080
+ this.list[0].addEventListener(type, listener, options);
3081
+ }
3082
+ },
3083
+ {
3084
+ key: "setDimension",
3085
+ value: function setDimension(param) {
3086
+ var x = param.x, y = param.y, angle = param.angle, width = param.width, height = param.height;
3087
+ this.x = x !== void 0 ? x : this.x;
3088
+ this.y = y !== void 0 ? y : this.y;
3089
+ this.angle = angle !== void 0 ? angle : this.angle;
3090
+ this.width = width !== void 0 ? width : this.width;
3091
+ this.height = height !== void 0 ? height : this.height;
3092
+ this.drag(x, y);
3093
+ this.rotate(angle);
3094
+ this.resize(width, height);
3095
+ }
3096
+ },
3097
+ {
3098
+ key: "getDimension",
3099
+ value: function getDimension() {
3100
+ return {
3101
+ x: this.x,
3102
+ y: this.y,
3103
+ angle: this.angle,
3104
+ width: this.width,
3105
+ height: this.height,
3106
+ ratio: this.width / this.height
3107
+ };
3108
+ }
3109
+ },
3110
+ {
3111
+ /**
3112
+ * Register an HTML Element to the TransformOperation
3113
+ * @param element
3114
+ */ key: "subscribe",
3115
+ value: function subscribe(element) {
3116
+ this.list.push(element);
3117
+ }
3118
+ },
3119
+ {
3120
+ key: "drag",
3121
+ value: function drag(x, y) {
3122
+ this.list.forEach(function(element) {
3123
+ element.drag(x, y);
3124
+ });
3125
+ }
3126
+ },
3127
+ {
3128
+ key: "rotate",
3129
+ value: function rotate(angle) {
3130
+ this.list.forEach(function(element) {
3131
+ element.rotate(angle);
3132
+ });
3133
+ }
3134
+ },
3135
+ {
3136
+ key: "resize",
3137
+ value: function resize(width, height) {
3138
+ this.list.forEach(function(element) {
3139
+ element.resize(width, height);
3140
+ });
3141
+ }
3142
+ }
3143
+ ]);
3144
+ return TransformOperation;
3145
+ }(TransformOperationExtension);
3146
+ var TransformOperation_default = TransformOperation;
3147
+ // src/components/Image/ImageEditor/ImageEditor.tsx
3148
+ import { jsx as jsx22, jsxs as jsxs16 } from "react/jsx-runtime";
3149
+ var transformOperation = new TransformOperation_default();
3150
+ var ImageEditor = function(param) {
3151
+ var src = param.src, _param_setSrc = param.setSrc, setSrc = _param_setSrc === void 0 ? function() {} : _param_setSrc, _param_isOpen = param.isOpen, isOpen = _param_isOpen === void 0 ? false : _param_isOpen, _param_setOpen = param.setOpen, setOpen = _param_setOpen === void 0 ? function() {} : _param_setOpen, _param_isNew = param.isNew, isNew = _param_isNew === void 0 ? false : _param_isNew;
3152
+ var createTransform = function createTransform() {
3153
+ if (!frame.current || !img.current) return;
3154
+ var transform2 = new Transform({
3155
+ container: container.current,
3156
+ frame: frame.current,
3157
+ img: img.current,
3158
+ controller: controller.current,
3159
+ topLeft: topLeft.current,
3160
+ topRight: topRight.current,
3161
+ bottomLeft: bottomLeft.current,
3162
+ bottomRight: bottomRight.current,
3163
+ rotate: rotate.current,
3164
+ transformOperation: transformOperation
3165
+ });
3166
+ transform2.initialize();
3167
+ if (transformState.current) {
3168
+ transform2.setState(transformState.current);
3169
+ } else {
3170
+ transform2.reset();
3171
+ }
3172
+ setTransform(transform2);
3173
+ };
3174
+ var handleCanvasToSrc = function handleCanvasToSrc() {
3175
+ if (!frame.current || !img.current || !transform) return;
3176
+ var canvas = new Canvas(700, 700);
3177
+ var _transform_getState = transform.getState(), x = _transform_getState.x, y = _transform_getState.y, angle = _transform_getState.angle, width = _transform_getState.width, height = _transform_getState.height;
3178
+ var _transformOperation_getOrigin = transformOperation.getOrigin(), containerWidth = _transformOperation_getOrigin.width, containerHeight = _transformOperation_getOrigin.height;
3179
+ transformState.current = transform.getState();
3180
+ canvas.drawImage({
3181
+ e: img.current,
3182
+ x: x,
3183
+ y: y,
3184
+ angle: angle,
3185
+ width: width,
3186
+ height: height,
3187
+ containerHeight: containerHeight,
3188
+ containerWidth: containerWidth
3189
+ });
3190
+ var _canvas_get = canvas.get(), src2 = _canvas_get.src;
3191
+ return src2;
3192
+ };
3193
+ var handleAccept = function handleAccept() {
3194
+ setSrc(handleCanvasToSrc());
3195
+ setOpen(false);
3196
+ };
3197
+ var handleCancel = function handleCancel() {
3198
+ setOpen(false);
3199
+ };
3200
+ var handleReset = function handleReset() {
3201
+ if (!transform) return;
3202
+ transform.reset();
3203
+ };
3204
+ var handleWindowScroll = function handleWindowScroll(isOpen2) {
3205
+ document.body.style.overflow = isOpen2 ? "hidden" : "auto";
3206
+ };
3207
+ var container = useRef10(null);
3208
+ var frame = useRef10(null);
3209
+ var img = useRef10(null);
3210
+ var controller = useRef10(null);
3211
+ var topLeft = useRef10(null);
3212
+ var topRight = useRef10(null);
3213
+ var bottomLeft = useRef10(null);
3214
+ var bottomRight = useRef10(null);
3215
+ var rotate = useRef10(null);
3216
+ var rotateBottom = useRef10(null);
3217
+ var _useState13 = _sliced_to_array(useState13(void 0), 2), transform = _useState13[0], setTransform = _useState13[1];
3218
+ var transformState = useRef10(void 0);
3219
+ var originalSrc = useMemo(function() {
3220
+ transformState.current = void 0;
3221
+ return src;
3222
+ }, [
3223
+ isNew
3224
+ ]);
3225
+ useEffect12(function() {
3226
+ isOpen ? createTransform() : setTransform(void 0);
3227
+ handleWindowScroll(isOpen);
3228
+ return function() {
3229
+ setTransform(void 0);
3230
+ };
3231
+ }, [
3232
+ isOpen
3233
+ ]);
3234
+ if (!isOpen) return;
3235
+ return /* @__PURE__ */ jsx22(MyContext3.Provider, {
3236
+ value: {
3237
+ refs: {
3238
+ container: container,
3239
+ frame: frame,
3240
+ controller: controller,
3241
+ topLeft: topLeft,
3242
+ topRight: topRight,
3243
+ bottomLeft: bottomLeft,
3244
+ bottomRight: bottomRight,
3245
+ rotate: rotate,
3246
+ rotateBottom: rotateBottom
3247
+ },
3248
+ imgRefs: {
3249
+ img: img
3250
+ },
3251
+ src: originalSrc,
3252
+ transformOperation: transformOperation
3253
+ },
3254
+ children: /* @__PURE__ */ jsxs16("div", {
3255
+ style: ImageEditor_styles_default.imageEditor,
3256
+ children: [
3257
+ /* @__PURE__ */ jsx22(Instruction_default, {}),
3258
+ /* @__PURE__ */ jsx22(MainElements_default, {}),
3259
+ /* @__PURE__ */ jsxs16("div", {
3260
+ style: ImageEditor_styles_default.buttons,
3261
+ children: [
3262
+ /* @__PURE__ */ jsx22(Button_default, {
3263
+ buttonType: "solid",
3264
+ content: "Accept",
3265
+ onClick: handleAccept
3266
+ }),
3267
+ /* @__PURE__ */ jsx22(Button_default, {
3268
+ buttonType: "solid",
3269
+ content: "Cancel",
3270
+ onClick: handleCancel
3271
+ }),
3272
+ /* @__PURE__ */ jsx22(Button_default, {
3273
+ buttonType: "solid",
3274
+ content: "Reset",
3275
+ onClick: handleReset
3276
+ })
3277
+ ]
3278
+ })
3279
+ ]
3280
+ })
3281
+ });
3282
+ };
3283
+ var ImageEditor_default = ImageEditor;
3284
+ // src/utilities/canvas/Canvas.ts
3285
+ var Canvas = /*#__PURE__*/ function() {
3286
+ "use strict";
3287
+ function Canvas(width, height) {
3288
+ _class_call_check(this, Canvas);
3289
+ this.canvas = document.createElement("canvas");
3290
+ this.canvas.width = width;
3291
+ this.canvas.height = height;
3292
+ this.canvas2DContext = this.canvas.getContext("2d");
3293
+ }
3294
+ _create_class(Canvas, [
3295
+ {
3296
+ key: "get",
3297
+ value: function get() {
3298
+ return {
3299
+ canvas: this.canvas,
3300
+ context: this.canvas2DContext,
3301
+ src: this.src
3302
+ };
3303
+ }
3304
+ },
3305
+ {
3306
+ key: "drawImage",
3307
+ value: function drawImage(param) {
3308
+ var e = param.e, x = param.x, y = param.y, angle = param.angle, width = param.width, height = param.height, containerHeight = param.containerHeight, containerWidth = param.containerWidth;
3309
+ var ratioX = this.canvas.width / containerWidth;
3310
+ var ratioY = this.canvas.height / containerHeight;
3311
+ var finalX = x * ratioX;
3312
+ var finalY = y * ratioY;
3313
+ var finalWidth = width * ratioX;
3314
+ var finalHeight = height * ratioY;
3315
+ var angleRadians = angle * Math.PI / 180;
3316
+ var reverse_p = LinearAlgebra_default.rotateVector([
3317
+ finalX,
3318
+ finalY,
3319
+ 1
3320
+ ], -angleRadians);
3321
+ var reverse_q = LinearAlgebra_default.rotateVector([
3322
+ finalX + finalWidth,
3323
+ finalY + finalHeight,
3324
+ 1
3325
+ ], -angleRadians);
3326
+ var reverse_p_prime = LinearAlgebra_default.NicolasMattia(reverse_p, LinearAlgebra_default.getMiddleVectorFrom(reverse_p, reverse_q), angleRadians);
3327
+ this.canvas2DContext.save();
3328
+ this.canvas2DContext.rotate(angleRadians);
3329
+ this.canvas2DContext.drawImage(e, reverse_p_prime[0], reverse_p_prime[1], finalWidth, finalHeight);
3330
+ this.src = this.canvas2DContext.canvas.toDataURL();
3331
+ this.canvas2DContext.restore();
3332
+ }
3333
+ },
3334
+ {
3335
+ key: "drawColor",
3336
+ value: function drawColor(type, color, width, ratio) {
3337
+ if (type === "") color = "#ffffff";
3338
+ if (type === "gradient") {
3339
+ var breakdownArr = color.split(",");
3340
+ var _ref = [
3341
+ Number(breakdownArr[0]),
3342
+ breakdownArr[1],
3343
+ Number(breakdownArr[2]),
3344
+ breakdownArr[3],
3345
+ Number(breakdownArr[4])
3346
+ ], angle = _ref[0], color1 = _ref[1], percent1 = _ref[2], color2 = _ref[3], percent2 = _ref[4];
3347
+ var radians = (angle - 180) * Math.PI / 180;
3348
+ var x0 = width / 2 + width / 2 * Math.cos(radians - Math.PI / 2);
3349
+ var y0 = width * ratio / 2 + width * ratio / 2 * Math.sin(radians - Math.PI / 2);
3350
+ var x1 = width / 2 - width / 2 * Math.cos(radians - Math.PI / 2);
3351
+ var y1 = width * ratio / 2 - width * ratio / 2 * Math.sin(radians - Math.PI / 2);
3352
+ var gradient = this.canvas2DContext.createLinearGradient(x0, y0, x1, y1);
3353
+ gradient.addColorStop(percent1 / 100, color1);
3354
+ gradient.addColorStop(percent2 / 100, color2);
3355
+ this.canvas2DContext.fillStyle = gradient;
3356
+ this.canvas2DContext.fillRect(0, 0, width, width * ratio);
3357
+ this.src = this.canvas2DContext.canvas.toDataURL();
3358
+ } else {
3359
+ this.canvas2DContext.fillStyle = color;
3360
+ this.canvas2DContext.fillRect(0, 0, this.canvas2DContext.canvas.width, this.canvas2DContext.canvas.height);
3361
+ this.src = this.canvas2DContext.canvas.toDataURL();
3362
+ }
3363
+ }
3364
+ }
3365
+ ]);
3366
+ return Canvas;
3367
+ }();
3368
+ // src/utilities/canvas/Image.ts
3369
+ var Image2 = {
3370
+ /**
3371
+ * Convert file (blob) to base64 string format
3372
+ * @param file
3373
+ * @returns
3374
+ */ FromFileToImageSrc: function FromFileToImageSrc(file) {
3375
+ return new Promise(function(resolve, reject) {
3376
+ if (!file) return resolve(null);
3377
+ var reader = new FileReader();
3378
+ reader.readAsDataURL(file);
3379
+ reader.onload = function(readerEvent) {
3380
+ var _readerEvent_target;
3381
+ if ((_readerEvent_target = readerEvent.target) === null || _readerEvent_target === void 0 ? void 0 : _readerEvent_target.result) {
3382
+ var _readerEvent_target1;
3383
+ return resolve((_readerEvent_target1 = readerEvent.target) === null || _readerEvent_target1 === void 0 ? void 0 : _readerEvent_target1.result);
3384
+ }
3385
+ reject("Error getting the image source");
3386
+ };
3387
+ reader.onerror = function() {
3388
+ reject("Error getting the image source");
3389
+ };
3390
+ });
3391
+ },
3392
+ FromStringToImageSrc: /**
3393
+ * Take a url, look for the corresponding image file, and convert it to base64 format
2386
3394
  * @param url
2387
3395
  * @returns
2388
3396
  */ function FromStringToImageSrc(url) {
@@ -2434,466 +3442,187 @@ var Image2 = {
2434
3442
  }
2435
3443
  };
2436
3444
  var Image_default2 = Image2;
2437
- // src/utilities/Transform/Transform.ts
2438
- import $2 from "jquery";
2439
- // src/utilities/Transform/TransformController.ts
2440
- import $ from "jquery";
2441
- import { icon } from "@fortawesome/fontawesome-svg-core";
2442
- import { faRotate, faTrash } from "@fortawesome/free-solid-svg-icons";
2443
- var TransformController = /*#__PURE__*/ function() {
3445
+ // src/utilities/Transform/WElement.ts
3446
+ var WElement = /*#__PURE__*/ function() {
2444
3447
  "use strict";
2445
- function TransformController(wrapper, frame, controller) {
2446
- _class_call_check(this, TransformController);
2447
- this.wrapper = wrapper;
2448
- this.frame = frame;
2449
- this.controller = controller;
3448
+ function WElement(element, sideEffectCallback) {
3449
+ _class_call_check(this, WElement);
3450
+ this.element = element;
3451
+ this.sideEffectCallback = sideEffectCallback;
2450
3452
  }
2451
- _create_class(TransformController, [
3453
+ _create_class(WElement, [
2452
3454
  {
2453
- key: "addController",
2454
- value: function addController() {
2455
- var _this = this;
2456
- return new Promise(function(res) {
2457
- var styleElement = document.createElement("style");
2458
- styleElement.textContent = _this.css();
2459
- document.head.appendChild(styleElement);
2460
- $("." + _this.frame).after(_this.controllerTemplate());
2461
- res();
2462
- });
3455
+ key: "runSideEffectHandler",
3456
+ value: function runSideEffectHandler() {
3457
+ if (!this.sideEffectCallback) return;
3458
+ this.sideEffectCallback(this.element);
2463
3459
  }
2464
3460
  },
2465
3461
  {
2466
- key: "css",
2467
- value: function css() {
2468
- return "\n .".concat(this.wrapper, " {\n position: absolute;\n transform-origin: top left;\n user-select: none;\n }\n .").concat(this.wrapper, " > img {\n object-fit: contain;\n position: absolute;\n top: 0;\n left: 0;\n display: block;\n z-index: 1;\n transform: translate(-50%, -50%)\n }\n .").concat(this.controller, "--container {\n position: absolute;\n transform-origin: top left;\n user-select: none;\n }\n .").concat(this.controller, " {\n position: absolute;\n user-select: none;\n border: solid 3px #6924d5;\n z-index: 1;\n top: 0;\n left: 0;\n transform: translate(-50%, -50%);\n }\n .").concat(this.controller, " .resize {\n background-color: #fff;\n width: 20px;\n height: 20px;\n border-radius: 50%;\n box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;\n transition: all .1s linear;\n }\n .").concat(this.controller, " .resize.show {\n background-color: #6924d5;\n }\n .").concat(this.controller, " .resize > .circle {\n background-color: #f0f0f0a8;\n position: absolute;\n top: -15px;\n left: -15px;\n width: 50px;\n height: 50px;\n border-radius: 50%;\n box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;\n z-index: -1;\n visibility: hidden;\n transition: all .1s linear;\n }\n .").concat(this.controller, " .resize > .circle.show {\n visibility: visible;\n }\n .").concat(this.controller, " .resize.resize-topleft {\n position: absolute;\n top: -10px;\n left: -10px;\n }\n .").concat(this.controller, " .resize.resize-topright {\n position: absolute;\n top: -10px;\n right: -10px;\n }\n .").concat(this.controller, " .resize.resize-bottomleft {\n position: absolute;\n bottom: -10px;\n left: -10px;\n }\n .").concat(this.controller, " .resize.resize-bottomright {\n position: absolute;\n bottom: -10px;\n right: -10px;\n }\n .").concat(this.controller, " .rotate {\n position: absolute;\n top: -50px;\n left: calc(50% - 15px);\n width: 30px;\n height: 30px;\n background-color: #fff;\n border-radius: 50%;\n display: flex;\n justify-content: center;\n align-items: center;\n }\n .").concat(this.controller, " .delete {\n position: absolute;\n bottom: -50px;\n left: calc(50% + 40px);\n width: 30px;\n height: 30px;\n background-color: #fff;\n border-radius: 50%;\n display: none;\n justify-content: center;\n align-items: center;\n }\n ");
3462
+ key: "addEventListener",
3463
+ value: function addEventListener(type, listener, options) {
3464
+ this.element.addEventListener(type, listener, options);
2469
3465
  }
2470
3466
  },
2471
3467
  {
2472
- key: "controllerTemplate",
2473
- value: function controllerTemplate() {
2474
- return '\n <div class="'.concat(this.controller, '--container">\n <div class="').concat(this.controller, '">\n <div class="dot resize resize-topleft"><div class="circle"></div></div>\n <div class="dot resize resize-topright"><div class="circle"></div></div>\n <div class="dot resize resize-bottomleft"><div class="circle"></div></div>\n <div class="dot resize resize-bottomright"><div class="circle"></div></div>\n <div class="dot rotate">').concat(icon(faRotate).html[0], '</div>\n <div class="dot rotate shadow" style="visibility: hidden;">').concat(icon(faRotate).html[0], '</div>\n <div class="dot delete">').concat(icon(faTrash).html[0], '</div>\n <div class="dot delete shadow" style="visibility: hidden;">').concat(icon(faTrash).html[0], "</div>\n </div>\n </div>\n ");
3468
+ key: "drag",
3469
+ value: function drag(x, y) {
3470
+ this.element.style.left = x !== void 0 ? (x - this.element.clientLeft).toString() + "px" : this.element.style.left;
3471
+ this.element.style.top = y !== void 0 ? (y - this.element.clientTop).toString() + "px" : this.element.style.top;
2475
3472
  }
2476
- }
2477
- ]);
2478
- return TransformController;
2479
- }();
2480
- // src/utilities/Transform/Transform.ts
2481
- var Transform = /*#__PURE__*/ function() {
2482
- "use strict";
2483
- function Transform(ele1, ele2, ele3) {
2484
- _class_call_check(this, Transform);
2485
- this.ele1 = ele1;
2486
- this.ele2 = ele2;
2487
- this.x = 0;
2488
- this.y = 0;
2489
- this.angle = 90;
2490
- this.w = 0;
2491
- this.h = 0;
2492
- if (this.ele1 === null) {
2493
- throw new Error("wrapper elemenet is not defined or not rendered yet");
2494
- }
2495
- this.wrapperClass = "_" + (Date.now() + 5e3).toString();
2496
- $2(this.ele1).addClass(this.wrapperClass);
2497
- this.imgFrame = this.ele2;
2498
- if (this.imgFrame === null) {
2499
- throw new Error("frame element is not defined or not rendered yet");
2500
- }
2501
- this.frameClass = "_" + (Date.now() - 5e3).toString();
2502
- $2(this.ele2).addClass(this.frameClass);
2503
- this.img = this.ele1.querySelector("img");
2504
- if (this.img === null) {
2505
- throw new Error("image element is not defined or not rendered yet");
2506
- }
2507
- this.ratio = this.img.clientWidth / this.img.clientHeight;
2508
- this.controllerClassName = "_" + Date.now().toString();
2509
- this.isRotateOffScreen = false;
2510
- }
2511
- _create_class(Transform, [
3473
+ },
2512
3474
  {
2513
- key: "initialize",
2514
- value: function initialize() {
2515
- return _async_to_generator(function() {
2516
- var transformController;
2517
- return _ts_generator(this, function(_state) {
2518
- switch(_state.label){
2519
- case 0:
2520
- transformController = new TransformController(this.wrapperClass, this.frameClass, this.controllerClassName);
2521
- return [
2522
- 4,
2523
- transformController.addController()
2524
- ];
2525
- case 1:
2526
- _state.sent();
2527
- this.controllerContainer = document.querySelector("." + this.controllerClassName + "--container");
2528
- this.controller = document.querySelector("." + this.controllerClassName);
2529
- this.handleElementGoOffScreen("." + this.controllerClassName + " .rotate", "." + this.controllerClassName + " .rotate.shadow", "rotate").handleElementGoOffScreen("." + this.controllerClassName + " .delete", "." + this.controllerClassName + " .delete.shadow", "delete").transform();
2530
- return [
2531
- 2
2532
- ];
2533
- }
2534
- });
2535
- }).call(this);
3475
+ key: "rotate",
3476
+ value: function rotate(angle) {
3477
+ this.element.style.rotate = angle !== void 0 ? angle + "deg" : this.element.style.rotate;
2536
3478
  }
2537
3479
  },
2538
3480
  {
2539
- key: "reset",
2540
- value: function reset() {
2541
- this.setState({
2542
- x: 0,
2543
- y: this.imgFrame.clientHeight / 2 - this.img.height / 2,
2544
- angle: 0,
2545
- w: this.imgFrame.clientWidth
2546
- });
3481
+ key: "resize",
3482
+ value: function resize(width, height) {
3483
+ this.element.style.width = width !== void 0 ? width + "px" : this.element.style.width;
3484
+ this.element.style.height = height !== void 0 ? height + "px" : this.element.style.height;
2547
3485
  }
2548
3486
  },
2549
3487
  {
2550
- key: "setState",
2551
- value: function setState(param) {
2552
- var x = param.x, y = param.y, angle = param.angle, w = param.w;
2553
- this.repositionElement(x + this.imgFrame.clientWidth / 2, y + this.img.height / 2);
2554
- this.rotateBox(angle);
2555
- this.resize(w, w / this.ratio);
2556
- this.setValue(x, y, angle, w, w / this.ratio);
3488
+ key: "setPosition",
3489
+ value: function setPosition(position) {
3490
+ this.element.style.setProperty("position", position, "important");
2557
3491
  }
2558
3492
  },
2559
3493
  {
2560
- key: "setValue",
2561
- value: function setValue(x, y, angle, w, h) {
2562
- this.x = x !== void 0 ? x : this.x;
2563
- this.y = y !== void 0 ? y : this.y;
2564
- this.angle = angle !== void 0 ? angle : this.angle;
2565
- this.w = w !== void 0 ? w : this.w;
2566
- this.h = h !== void 0 ? h : this.h;
3494
+ key: "setDimension",
3495
+ value: function setDimension(param) {
3496
+ var x = param.x, y = param.y, angle = param.angle, width = param.width, height = param.height;
3497
+ this.drag(x, y);
3498
+ this.rotate(angle);
3499
+ this.resize(width, height);
2567
3500
  }
2568
3501
  },
2569
3502
  {
2570
- key: "exportData",
2571
- value: function exportData() {
3503
+ key: "getDimension",
3504
+ value: function getDimension() {
2572
3505
  return {
2573
- x: this.x,
2574
- y: this.y,
2575
- angle: this.angle,
2576
- w: this.w,
2577
- h: this.h
3506
+ x: this.element.offsetLeft,
3507
+ y: this.element.offsetTop,
3508
+ angle: this.getCurrentRotation(),
3509
+ width: this.element.clientWidth,
3510
+ height: this.element.clientHeight,
3511
+ ratio: this.element.clientWidth / this.element.clientHeight
2578
3512
  };
2579
3513
  }
2580
3514
  },
2581
3515
  {
2582
- key: "repositionElement",
2583
- value: function repositionElement(x, y) {
2584
- var controllerWrapper = this.controllerContainer;
2585
- var boxWrapper = this.ele1;
2586
- boxWrapper.style.left = x + "px";
2587
- boxWrapper.style.top = y + "px";
2588
- controllerWrapper.style.left = x + this.imgFrame.offsetLeft + 3 + "px";
2589
- controllerWrapper.style.top = y + this.imgFrame.offsetTop + 3 + "px";
3516
+ /**
3517
+ * Get current angle of current element in degrees
3518
+ * @returns angle in degrees
3519
+ */ key: "getCurrentRotation",
3520
+ value: function getCurrentRotation() {
3521
+ if (!this.element) return 0;
3522
+ var st = window.getComputedStyle(this.element, null);
3523
+ var tm = st.getPropertyValue("-webkit-transform") || st.getPropertyValue("-moz-transform") || st.getPropertyValue("-ms-transform") || st.getPropertyValue("-o-transform") || st.getPropertyValue("transform");
3524
+ "none";
3525
+ if (tm != "none") {
3526
+ var values = tm.split("(")[1].split(")")[0].split(",");
3527
+ var angle = Math.round(Math.atan2(Number(values[1]), Number(values[0])) * (180 / Math.PI));
3528
+ return angle < 0 ? angle + 360 : angle;
3529
+ }
3530
+ return 0;
2590
3531
  }
2591
- },
3532
+ }
3533
+ ]);
3534
+ return WElement;
3535
+ }();
3536
+ var WElement_default = WElement;
3537
+ // src/utilities/Transform/Transform.ts
3538
+ var Transform = /*#__PURE__*/ function() {
3539
+ "use strict";
3540
+ function Transform(param) {
3541
+ var container = param.container, frame = param.frame, img = param.img, controller = param.controller, topLeft = param.topLeft, topRight = param.topRight, bottomLeft = param.bottomLeft, bottomRight = param.bottomRight, rotate = param.rotate, transformOperation2 = param.transformOperation;
3542
+ _class_call_check(this, Transform);
3543
+ this.frame = new WElement_default(frame);
3544
+ this.img = new WElement_default(img);
3545
+ this.container = new WElement_default(container);
3546
+ this.controller = new WElement_default(controller);
3547
+ this.topLeft = new WElement_default(topLeft);
3548
+ this.topRight = new WElement_default(topRight);
3549
+ this.bottomLeft = new WElement_default(bottomLeft);
3550
+ this.bottomRight = new WElement_default(bottomRight);
3551
+ this.rotate = new WElement_default(rotate, function(element) {
3552
+ var rotateBottom = element.nextElementSibling;
3553
+ var callback = function(entries) {
3554
+ entries.forEach(function(entry) {
3555
+ if (!entry.isIntersecting) {
3556
+ element.style.visibility = "hidden";
3557
+ rotateBottom.style.display = "flex";
3558
+ } else {
3559
+ element.style.visibility = "visible";
3560
+ rotateBottom.style.display = "none";
3561
+ }
3562
+ });
3563
+ };
3564
+ var observer = new IntersectionObserver(callback, {
3565
+ root: null,
3566
+ rootMargin: "0px",
3567
+ threshold: 0.1
3568
+ });
3569
+ observer.observe(element);
3570
+ });
3571
+ this.transformOperation = transformOperation2;
3572
+ }
3573
+ _create_class(Transform, [
2592
3574
  {
2593
- key: "resize",
2594
- value: function resize(w, h) {
2595
- var controller = this.controller;
2596
- var img = this.img;
2597
- var wrapper = this.ele1;
2598
- controller.style.width = w + "px";
2599
- controller.style.height = h + "px";
2600
- img.style.width = w + "px";
2601
- wrapper.style.width = w + "px";
3575
+ key: "initialize",
3576
+ value: function initialize() {
3577
+ this.container.setPosition("relative");
3578
+ this.controller.setPosition("absolute");
3579
+ this.frame.setPosition("relative");
3580
+ this.img.setPosition("absolute");
3581
+ var _this_container_getDimension = this.container.getDimension(), x = _this_container_getDimension.x, y = _this_container_getDimension.y, width = _this_container_getDimension.width, height = _this_container_getDimension.height;
3582
+ this.transformOperation.setOrigin({
3583
+ x: x,
3584
+ y: y,
3585
+ width: width,
3586
+ height: height
3587
+ });
3588
+ this.transformOperation.subscribe(this.controller);
3589
+ this.transformOperation.subscribe(this.img);
3590
+ this.transformOperation.subscribeSideEffect(this.rotate);
3591
+ this.transformOperation.runSideEffectHandler();
3592
+ return this;
2602
3593
  }
2603
3594
  },
2604
3595
  {
2605
- key: "rotateBox",
2606
- value: function rotateBox(deg) {
2607
- var controllerWrapper = this.controllerContainer;
2608
- var boxWrapper = this.ele1;
2609
- boxWrapper.style.transform = "rotate(".concat(deg, "deg)");
2610
- controllerWrapper.style.rotate = "".concat(deg, "deg");
3596
+ key: "setState",
3597
+ value: function setState(param) {
3598
+ var x = param.x, y = param.y, angle = param.angle, width = param.width, height = param.height;
3599
+ this.transformOperation.setDimension({
3600
+ x: x,
3601
+ y: y,
3602
+ angle: angle,
3603
+ width: width,
3604
+ height: height
3605
+ });
2611
3606
  }
2612
3607
  },
2613
3608
  {
2614
- key: "handleElementGoOffScreen",
2615
- value: function handleElementGoOffScreen(main, shadow, type) {
2616
- var _this = this;
2617
- var mainEle = document.querySelector(main);
2618
- var shadowEle = document.querySelector(shadow);
2619
- var options = {
2620
- root: null,
2621
- rootMargin: "0px",
2622
- threshold: 0.1
2623
- };
2624
- var callback = function(entries) {
2625
- entries.forEach(function(entry) {
2626
- switch(type){
2627
- case "rotate":
2628
- if (!entry.isIntersecting) {
2629
- mainEle.style.top = "auto";
2630
- mainEle.style.bottom = "-50px";
2631
- _this.isRotateOffScreen = true;
2632
- } else {
2633
- mainEle.style.bottom = "auto";
2634
- mainEle.style.top = "-50px";
2635
- _this.isRotateOffScreen = false;
2636
- }
2637
- break;
2638
- case "delete":
2639
- if (!entry.isIntersecting) {
2640
- mainEle.style.bottom = "auto";
2641
- mainEle.style.top = "-50px";
2642
- } else {
2643
- mainEle.style.top = "auto";
2644
- mainEle.style.bottom = "-50px";
2645
- }
2646
- break;
2647
- }
2648
- });
2649
- };
2650
- var observer = new IntersectionObserver(callback, options);
2651
- observer.observe(shadowEle);
2652
- return this;
3609
+ key: "getState",
3610
+ value: function getState() {
3611
+ return this.transformOperation.getDimension();
2653
3612
  }
2654
3613
  },
2655
3614
  {
2656
- key: "transform",
2657
- value: function transform() {
2658
- var _this = this;
2659
- var _this1 = this;
2660
- var controllerWrapper = this.controllerContainer;
2661
- var boxWrapper = this.ele1;
2662
- var minWidth = 40;
2663
- var minHeight = 40;
2664
- var initX, initY, mousePressX, mousePressY, initW, initH, initRotate;
2665
- function getCurrentRotation(el) {
2666
- var st = window.getComputedStyle(el, null);
2667
- var tm = st.getPropertyValue("-webkit-transform") || st.getPropertyValue("-moz-transform") || st.getPropertyValue("-ms-transform") || st.getPropertyValue("-o-transform") || st.getPropertyValue("transform");
2668
- "none";
2669
- if (tm != "none") {
2670
- var values = tm.split("(")[1].split(")")[0].split(",");
2671
- var angle = Math.round(Math.atan2(Number(values[1]), Number(values[0])) * (180 / Math.PI));
2672
- return angle < 0 ? angle + 360 : angle;
2673
- }
2674
- return 0;
2675
- }
2676
- function mousedownCb(event) {
2677
- event.target.classList.add("show");
2678
- event.target.querySelector(".circle").classList.add("show");
2679
- }
2680
- function mouseupCb(event) {
2681
- event.target.classList.remove("show");
2682
- event.target.querySelector(".circle").classList.remove("show");
2683
- }
2684
- var handleDrag = function(event, type) {
2685
- event.stopPropagation();
2686
- var initX2 = boxWrapper.offsetLeft;
2687
- var initY2 = boxWrapper.offsetTop;
2688
- var mousePressX2 = type === "desk" ? event.clientX : event.touches[0].clientX;
2689
- var mousePressY2 = type === "desk" ? event.clientY : event.touches[0].clientY;
2690
- var _this_exportData = _this.exportData(), w = _this_exportData.w, h = _this_exportData.h;
2691
- var eventMoveHandler = function(event2) {
2692
- var x = type === "desk" ? event2.clientX : event2.touches[0].clientX;
2693
- var y = type === "desk" ? event2.clientY : event2.touches[0].clientY;
2694
- var posX = initX2 + (x - mousePressX2);
2695
- var posY = initY2 + (y - mousePressY2);
2696
- _this.repositionElement(posX, posY);
2697
- _this.setValue(posX - w / 2, posY - h / 2, void 0, void 0, void 0);
2698
- };
2699
- if (type === "desk") {
2700
- controllerWrapper.addEventListener("mousemove", eventMoveHandler, false);
2701
- window.addEventListener("mouseup", function eventEndHandler() {
2702
- controllerWrapper.removeEventListener("mousemove", eventMoveHandler, false);
2703
- window.removeEventListener("mouseup", eventEndHandler);
2704
- }, false);
2705
- } else {
2706
- controllerWrapper.addEventListener("touchmove", eventMoveHandler, {
2707
- passive: true
2708
- });
2709
- window.addEventListener("touchend", function eventEndHandler() {
2710
- controllerWrapper.removeEventListener("touchmove", eventMoveHandler);
2711
- window.removeEventListener("touchend", eventEndHandler);
2712
- }, false);
2713
- }
2714
- };
2715
- controllerWrapper.addEventListener("mousedown", function(e) {
2716
- return handleDrag(e, "desk");
2717
- }, false);
2718
- controllerWrapper.addEventListener("touchstart", function(e) {
2719
- return handleDrag(e, "touch");
2720
- }, {
2721
- passive: true
2722
- });
2723
- var leftTop = document.querySelector("." + this.controllerClassName + " .resize-topleft");
2724
- var rightTop = document.querySelector("." + this.controllerClassName + " .resize-topright");
2725
- var rightBottom = document.querySelector("." + this.controllerClassName + " .resize-bottomright");
2726
- var leftBottom = document.querySelector("." + this.controllerClassName + " .resize-bottomleft");
2727
- var resizeHandler = function(event) {
2728
- var left = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, top = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false, xResize = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false, yResize = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : false, type = arguments.length > 5 ? arguments[5] : void 0;
2729
- event.stopPropagation();
2730
- initX = boxWrapper.offsetLeft;
2731
- initY = boxWrapper.offsetTop;
2732
- mousePressX = type === "desk" ? event.clientX : event.touches[0].clientX;
2733
- mousePressY = type === "desk" ? event.clientY : event.touches[0].clientY;
2734
- initW = _this1.img.offsetWidth;
2735
- initH = _this1.img.offsetHeight;
2736
- initRotate = getCurrentRotation(boxWrapper);
2737
- var initRadians = initRotate * Math.PI / 180;
2738
- var cosFraction = Math.cos(initRadians);
2739
- var sinFraction = Math.sin(initRadians);
2740
- mousedownCb(event);
2741
- var vectorC = [
2742
- mousePressX - initX - _this1.imgFrame.offsetLeft,
2743
- mousePressY - initY - _this1.imgFrame.offsetTop
2744
- ];
2745
- var eventMoveHandler = function(event2) {
2746
- var x = type === "desk" ? event2.clientX : event2.touches[0].clientX;
2747
- var y = type === "desk" ? event2.clientY : event2.touches[0].clientY;
2748
- var wDiff = x - mousePressX;
2749
- var hDiff = y - mousePressY;
2750
- var vectorD = [
2751
- wDiff,
2752
- hDiff
2753
- ];
2754
- var c = (vectorC[0] * vectorD[0] + vectorC[1] * vectorD[1]) / (vectorC[0] * vectorC[0] + vectorC[1] * vectorC[1]);
2755
- var vectorH = [
2756
- c * vectorC[0],
2757
- c * vectorC[1]
2758
- ];
2759
- var rotatedWDiff = cosFraction * vectorH[0] + sinFraction * vectorH[1];
2760
- var rotatedHDiff = cosFraction * vectorH[1] - sinFraction * vectorH[0];
2761
- rotatedHDiff = rotatedHDiff * rotatedWDiff > 0 ? rotatedWDiff / _this1.ratio : -rotatedWDiff / _this1.ratio;
2762
- var newW = initW, newH = initH, newX = initX, newY = initY;
2763
- if (xResize) {
2764
- if (left) {
2765
- newW = initW - rotatedWDiff;
2766
- if (newW < minWidth) {
2767
- newW = minWidth;
2768
- rotatedWDiff = initW - minWidth;
2769
- }
2770
- } else {
2771
- newW = initW + rotatedWDiff;
2772
- if (newW < minWidth) {
2773
- newW = minWidth;
2774
- rotatedWDiff = minWidth - initW;
2775
- }
2776
- }
2777
- newX += 0.5 * rotatedWDiff * cosFraction;
2778
- newY += 0.5 * rotatedWDiff * sinFraction;
2779
- }
2780
- if (yResize) {
2781
- if (top) {
2782
- newH = initH - rotatedHDiff;
2783
- if (newH < minHeight) {
2784
- newH = minHeight;
2785
- rotatedHDiff = initH - minHeight;
2786
- }
2787
- } else {
2788
- newH = initH + rotatedHDiff;
2789
- if (newH < minHeight) {
2790
- newH = minHeight;
2791
- rotatedHDiff = minHeight - initH;
2792
- }
2793
- }
2794
- newX -= 0.5 * rotatedHDiff * sinFraction;
2795
- newY += 0.5 * rotatedHDiff * cosFraction;
2796
- }
2797
- _this1.resize(newW, newH);
2798
- _this1.repositionElement(newX, newY);
2799
- _this1.setValue(newX - newW / 2, newY - newH / 2, void 0, newW, newH);
2800
- };
2801
- if (type === "desk") {
2802
- window.addEventListener("mousemove", eventMoveHandler, false);
2803
- window.addEventListener("mouseup", function eventEndHandler() {
2804
- mouseupCb(event);
2805
- window.removeEventListener("mousemove", eventMoveHandler, false);
2806
- window.removeEventListener("mouseup", eventEndHandler);
2807
- }, false);
2808
- } else {
2809
- window.addEventListener("touchmove", eventMoveHandler, {
2810
- passive: true
2811
- });
2812
- window.addEventListener("touchend", function eventEndHandler() {
2813
- mouseupCb(event);
2814
- window.removeEventListener("touchmove", eventMoveHandler, false);
2815
- window.removeEventListener("touchend", eventEndHandler);
2816
- }, false);
2817
- }
2818
- };
2819
- leftTop.addEventListener("mousedown", function(e) {
2820
- return resizeHandler(e, true, true, true, true, "desk");
2821
- });
2822
- rightTop.addEventListener("mousedown", function(e) {
2823
- return resizeHandler(e, false, true, true, true, "desk");
2824
- });
2825
- rightBottom.addEventListener("mousedown", function(e) {
2826
- return resizeHandler(e, false, false, true, true, "desk");
2827
- });
2828
- leftBottom.addEventListener("mousedown", function(e) {
2829
- return resizeHandler(e, true, false, true, true, "desk");
2830
- });
2831
- leftTop.addEventListener("touchstart", function(e) {
2832
- return resizeHandler(e, true, true, true, true, "touch");
2833
- }, {
2834
- passive: true
2835
- });
2836
- rightTop.addEventListener("touchstart", function(e) {
2837
- return resizeHandler(e, false, true, true, true, "touch");
2838
- }, {
2839
- passive: true
2840
- });
2841
- rightBottom.addEventListener("touchstart", function(e) {
2842
- return resizeHandler(e, false, false, true, true, "touch");
2843
- }, {
2844
- passive: true
2845
- });
2846
- leftBottom.addEventListener("touchstart", function(e) {
2847
- return resizeHandler(e, true, false, true, true, "touch");
2848
- }, {
2849
- passive: true
2850
- });
2851
- var rotate = document.querySelector("." + this.controllerClassName + " .rotate");
2852
- var handleRotate = function(event, type) {
2853
- event.stopPropagation();
2854
- initX = event.target.offsetLeft;
2855
- initY = event.target.offsetTop;
2856
- mousePressX = type === "desk" ? event.clientX : event.touches[0].clientX;
2857
- mousePressY = type === "desk" ? event.clientY : event.touches[0].clientY;
2858
- var arrow = _this.controller;
2859
- var arrowRects = arrow.getBoundingClientRect();
2860
- var arrowX = arrowRects.left + arrowRects.width / 2;
2861
- var arrowY = arrowRects.top + arrowRects.height / 2;
2862
- var compensation = _this.isRotateOffScreen ? 180 : 0;
2863
- var eventMoveHandler = function(event2) {
2864
- var x = type === "desk" ? event2.clientX : event2.touches[0].clientX;
2865
- var y = type === "desk" ? event2.clientY : event2.touches[0].clientY;
2866
- var angle = Math.atan2(y - arrowY, x - arrowX) + Math.PI / 2;
2867
- angle *= 180 / Math.PI;
2868
- angle += compensation;
2869
- _this.rotateBox(angle);
2870
- _this.setValue(void 0, void 0, angle, void 0, void 0);
2871
- };
2872
- if (type === "desk") {
2873
- window.addEventListener("mousemove", eventMoveHandler, false);
2874
- window.addEventListener("mouseup", function eventEndHandler() {
2875
- window.removeEventListener("mousemove", eventMoveHandler, false);
2876
- window.removeEventListener("mouseup", eventEndHandler);
2877
- }, false);
2878
- } else {
2879
- window.addEventListener("touchmove", eventMoveHandler, {
2880
- passive: true
2881
- });
2882
- window.addEventListener("touchend", function eventEndHandler() {
2883
- window.removeEventListener("touchmove", eventMoveHandler, false);
2884
- window.removeEventListener("touchend", eventEndHandler);
2885
- }, false);
2886
- }
2887
- };
2888
- rotate.addEventListener("mousedown", function(e) {
2889
- return handleRotate(e, "desk");
2890
- }, false);
2891
- rotate.addEventListener("touchstart", function(e) {
2892
- return handleRotate(e, "touch");
2893
- }, {
2894
- passive: true
3615
+ key: "reset",
3616
+ value: function reset() {
3617
+ var width = this.frame.getDimension().width;
3618
+ var ratio = this.img.getDimension().ratio;
3619
+ this.transformOperation.setDimension({
3620
+ x: 0,
3621
+ y: width / 2 - width / ratio / 2,
3622
+ angle: 0,
3623
+ width: width,
3624
+ height: width / ratio
2895
3625
  });
2896
- this.reset();
2897
3626
  return this;
2898
3627
  }
2899
3628
  }
@@ -2950,29 +3679,29 @@ var tools = {
2950
3679
  };
2951
3680
  var tools_default = tools;
2952
3681
  // src/auth/react/context.tsx
2953
- import { createContext as createContext4, useContext as useContext4 } from "react";
2954
- var SessionContext = createContext4(void 0);
3682
+ import { createContext as createContext5, useContext as useContext5 } from "react";
3683
+ var SessionContext = createContext5(void 0);
2955
3684
  function useSession() {
2956
- var data = useContext4(SessionContext);
3685
+ var data = useContext5(SessionContext);
2957
3686
  if (data === void 0) throw new Error("Session context is undefined");
2958
3687
  return data;
2959
3688
  }
2960
3689
  // src/auth/react/SessionProvider.tsx
2961
- import { jsx as jsx20 } from "react/jsx-runtime";
3690
+ import { jsx as jsx23 } from "react/jsx-runtime";
2962
3691
  var SessionProvider = function(param) {
2963
3692
  var value = param.value, children = param.children;
2964
- return /* @__PURE__ */ jsx20(SessionContext.Provider, {
3693
+ return /* @__PURE__ */ jsx23(SessionContext.Provider, {
2965
3694
  value: value,
2966
3695
  children: children
2967
3696
  });
2968
3697
  };
2969
3698
  var SessionProvider_default = SessionProvider;
2970
3699
  // src/auth/react/useAuthClient.ts
2971
- import { useEffect as useEffect11, useRef as useRef11, useState as useState12 } from "react";
3700
+ import { useEffect as useEffect13, useRef as useRef11, useState as useState14 } from "react";
2972
3701
  var useAuthClient = function(auth) {
2973
- var _useState12 = _sliced_to_array(useState12(false), 2), isLoading = _useState12[0], setLoading = _useState12[1];
3702
+ var _useState14 = _sliced_to_array(useState14(false), 2), isLoading = _useState14[0], setLoading = _useState14[1];
2974
3703
  var sessionRef = useRef11(void 0);
2975
- useEffect11(function() {
3704
+ useEffect13(function() {
2976
3705
  var is = true;
2977
3706
  var getSession = function() {
2978
3707
  return _async_to_generator(function() {
@@ -3013,4 +3742,127 @@ var useAuthClient = function(auth) {
3013
3742
  };
3014
3743
  };
3015
3744
  var useAuthClient_default = useAuthClient;
3016
- export { Avatar_default as Avatar, Button_default as Button, Canvas, ColorPickerSlider_default as ColorPickerSlider, DropdownSelect_default as DropdownSelect, Image_default as Image, ImageEditor_default as ImageEditor, Image_default2 as ImageUtilities, InputFile_default as InputFile, InputGoogle_default as InputGoogle, MultiSelect_default as MultiSelect, OptionSlider_default as OptionSlider, RangeSlider_default as RangeSlider, SessionProvider_default as SessionProvider, TextArea_default as TextArea, Transform, UploadImage_default as UploadImage, tools_default as tools, useAuthClient_default as useAuthClient, useSession };
3745
+ // src/utilities/math/LinearAlgebra.ts
3746
+ var LinearAlgebra = {
3747
+ /**
3748
+ * Translate a point by a vector
3749
+ * @param vector coordinates of a point
3750
+ * @param translateVector vector for translation
3751
+ * @throws Exception if the vector is not in 3 dimension
3752
+ */ translateVector: function translateVector(vector, translateVector) {
3753
+ if (vector.length !== 3) {
3754
+ throw new Error("Vector must be 3 dimension");
3755
+ }
3756
+ return [
3757
+ vector[0] + translateVector[0],
3758
+ vector[1] + translateVector[1],
3759
+ 1
3760
+ ];
3761
+ },
3762
+ /**
3763
+ * Rotate a vector by an angle in radian
3764
+ * @param vector
3765
+ * @param angle
3766
+ * @throws Exception if the vector is not in 3 dimension
3767
+ */ rotateVector: function rotateVector(vector, angle) {
3768
+ if (vector.length !== 3) {
3769
+ throw new Error("Vector must be 3 dimension");
3770
+ }
3771
+ return [
3772
+ vector[0] * Math.cos(angle) - vector[1] * Math.sin(angle),
3773
+ vector[0] * Math.sin(angle) + vector[1] * Math.cos(angle),
3774
+ 1
3775
+ ];
3776
+ },
3777
+ /**
3778
+ * Get opposite vector
3779
+ * @param vector
3780
+ */ getOppositeVector: function getOppositeVector(vector) {
3781
+ return [
3782
+ -1 * vector[0],
3783
+ -1 * vector[1],
3784
+ 1
3785
+ ];
3786
+ },
3787
+ /**
3788
+ * Nicolas Mattia formula
3789
+ * @param vector
3790
+ * @param translate
3791
+ * @param angle
3792
+ * @throws Exception if the vector is not in 3 dimension
3793
+ *
3794
+ * @link https://nmattia.com/posts/2020-03-03-drag-resize-rotate/
3795
+ */ NicolasMattia: function NicolasMattia(vector, translate, angle) {
3796
+ if (vector.length !== 3) {
3797
+ throw new Error("Vector must be 3 dimension");
3798
+ }
3799
+ var c = LinearAlgebra.translateVector(vector, LinearAlgebra.getOppositeVector(translate));
3800
+ var r = LinearAlgebra.rotateVector(c, angle);
3801
+ return LinearAlgebra.translateVector(r, translate);
3802
+ },
3803
+ /**
3804
+ * Set coofficient for a vector
3805
+ * @param coefficient
3806
+ * @param vector
3807
+ * @throws Exception if the vector is not in 3 dimension
3808
+ */ setCoefficient: function setCoefficient(coefficient, vector) {
3809
+ if (vector.length !== 3) {
3810
+ throw new Error("Vector must be 3 dimension");
3811
+ }
3812
+ return [
3813
+ coefficient * vector[0],
3814
+ coefficient * vector[1],
3815
+ 1
3816
+ ];
3817
+ },
3818
+ /**
3819
+ * Plus 2 vectors
3820
+ * @param vector1
3821
+ * @param vector2
3822
+ * @throws Exception if the vector is not in 3 dimension
3823
+ */ plusVectors: function plusVectors(vector1, vector2) {
3824
+ if (vector1.length !== 3 || vector2.length !== 3) {
3825
+ throw new Error("Vector must be 3 dimension");
3826
+ }
3827
+ return [
3828
+ vector1[0] + vector2[0],
3829
+ vector1[1] + vector2[1],
3830
+ 1
3831
+ ];
3832
+ },
3833
+ /**
3834
+ * Get middle vector from 2 vectors
3835
+ * @param vector1
3836
+ * @param vector2
3837
+ * @throws Exception if the vector is not in 3 dimension
3838
+ */ getMiddleVectorFrom: function getMiddleVectorFrom(vector1, vector2) {
3839
+ if (vector1.length !== 3 || vector2.length !== 3) {
3840
+ throw new Error("Vector must be 3 dimension");
3841
+ }
3842
+ return LinearAlgebra.plusVectors(LinearAlgebra.setCoefficient(0.5, vector1), LinearAlgebra.setCoefficient(0.5, vector2));
3843
+ },
3844
+ /**
3845
+ * Compute dot products between two vectors
3846
+ * @param vector1
3847
+ * @param vector2
3848
+ * @throws Exception if the vector is not in 3 dimension
3849
+ */ dotProduct: function dotProduct(vector1, vector2) {
3850
+ if (vector1.length !== 3 || vector2.length !== 3) {
3851
+ throw new Error("Vector must be 3 dimension");
3852
+ }
3853
+ return vector1[0] * vector2[0] + vector1[1] * vector2[1];
3854
+ },
3855
+ /**
3856
+ * Get vector magnitude
3857
+ * - formula : if vector = [x,y] => magnitude = square root of x^2 + y^2
3858
+ * @param vector
3859
+ * @throws Exception if the vector is not in 3 dimension
3860
+ */ getVectorMagnitude: function getVectorMagnitude(vector) {
3861
+ if (vector.length !== 3) {
3862
+ throw new Error("Vector must be 3 dimension");
3863
+ }
3864
+ return Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1]);
3865
+ }
3866
+ };
3867
+ var LinearAlgebra_default = LinearAlgebra;
3868
+ export { Avatar_default as Avatar, Button_default as Button, Canvas, ColorPickerSlider_default as ColorPickerSlider, DropdownSelect_default as DropdownSelect, Image_default as Image, ImageEditor_default as ImageEditor, Image_default2 as ImageUtilities, InputFile_default as InputFile, InputGoogle_default as InputGoogle, LinearAlgebra_default as LinearAlgebra, MultiSelect_default as MultiSelect, OptionSlider_default as OptionSlider, RangeSlider_default as RangeSlider, SessionProvider_default as SessionProvider, TextArea_default as TextArea, Transform, UploadImage_default as UploadImage, tools_default as tools, useAuthClient_default as useAuthClient, useSession };