@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.js 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,6 +217,19 @@ 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
  }
@@ -206,6 +248,14 @@ function _unsupported_iterable_to_array(o, minLen) {
206
248
  if (n === "Map" || n === "Set") return Array.from(n);
207
249
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
208
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
+ }
209
259
  function _ts_generator(thisArg, body) {
210
260
  var f, y, t, _ = {
211
261
  label: 0,
@@ -297,11 +347,9 @@ function _ts_generator(thisArg, body) {
297
347
  };
298
348
  }
299
349
  }
300
- var __create = Object.create;
301
350
  var __defProp = Object.defineProperty;
302
351
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
303
352
  var __getOwnPropNames = Object.getOwnPropertyNames;
304
- var __getProtoOf = Object.getPrototypeOf;
305
353
  var __hasOwnProp = Object.prototype.hasOwnProperty;
306
354
  var __export = function(target, all) {
307
355
  for(var name in all)__defProp(target, name, {
@@ -340,16 +388,6 @@ var __copyProps = function(to, from, except, desc) {
340
388
  }
341
389
  return to;
342
390
  };
343
- var __toESM = function(mod, isNodeMode, target) {
344
- return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
345
- // file that has been converted to a CommonJS file using a Babel-
346
- // compatible transform (i.e. "__esModule" has not been set), then set
347
- // "default" to the CommonJS "module.exports" for node compatibility.
348
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
349
- value: mod,
350
- enumerable: true
351
- }) : target, mod);
352
- };
353
391
  var __toCommonJS = function(mod) {
354
392
  return __copyProps(__defProp({}, "__esModule", {
355
393
  value: true
@@ -388,6 +426,9 @@ __export(index_exports, {
388
426
  InputGoogle: function() {
389
427
  return InputGoogle_default;
390
428
  },
429
+ LinearAlgebra: function() {
430
+ return LinearAlgebra_default;
431
+ },
391
432
  MultiSelect: function() {
392
433
  return MultiSelect_default;
393
434
  },
@@ -1822,40 +1863,42 @@ var styles_default8 = styles8;
1822
1863
  var import_react10 = require("react");
1823
1864
  var import_jsx_runtime13 = require("react/jsx-runtime");
1824
1865
  var Avatar = function(param) {
1825
- var src = param.src, setValue = param.setValue;
1826
- var setSrc = function setSrc() {
1827
- return _async_to_generator(function() {
1828
- var translatedSrc;
1829
- return _ts_generator(this, function(_state) {
1830
- switch(_state.label){
1831
- case 0:
1832
- return [
1833
- 4,
1834
- Image_default2.FromStringToImageSrc(src)
1835
- ];
1836
- case 1:
1837
- translatedSrc = _state.sent();
1838
- if (!translatedSrc) return [
1839
- 2
1840
- ];
1841
- defaultImage.current = translatedSrc;
1842
- setValue(translatedSrc);
1843
- return [
1844
- 2
1845
- ];
1846
- }
1847
- });
1848
- })();
1849
- };
1866
+ var src = param.src, setValue = param.setValue, options = param.options;
1850
1867
  var _ref = _sliced_to_array((0, import_react10.useState)(false), 2), isOpen = _ref[0], setOpen = _ref[1];
1851
1868
  var _ref1 = _sliced_to_array((0, import_react10.useState)(false), 2), isNew = _ref1[0], setNew = _ref1[1];
1869
+ var defaultImage = (0, import_react10.useRef)(void 0);
1870
+ var initialImage = (0, import_react10.useRef)(void 0);
1852
1871
  var uploadImageRef = (0, import_react10.useRef)(null);
1853
- var defaultImage = (0, import_react10.useRef)("");
1872
+ var isAbleToEdit = initialImage.current ? src !== defaultImage.current && src !== initialImage.current : false;
1873
+ var isAbleToRemove = initialImage.current ? src !== defaultImage.current : false;
1854
1874
  (0, import_react10.useEffect)(function() {
1855
- setSrc();
1856
- }, [
1857
- src
1858
- ]);
1875
+ (function setSrc() {
1876
+ return _async_to_generator(function() {
1877
+ var _ref, _ref1;
1878
+ return _ts_generator(this, function(_state) {
1879
+ switch(_state.label){
1880
+ case 0:
1881
+ return [
1882
+ 4,
1883
+ Image_default2.FromStringToImageSrc(options === null || options === void 0 ? void 0 : options.defaultImage)
1884
+ ];
1885
+ case 1:
1886
+ defaultImage.current = (_ref = _state.sent()) !== null && _ref !== void 0 ? _ref : options === null || options === void 0 ? void 0 : options.defaultImage;
1887
+ return [
1888
+ 4,
1889
+ Image_default2.FromStringToImageSrc(src)
1890
+ ];
1891
+ case 2:
1892
+ initialImage.current = (_ref1 = _state.sent()) !== null && _ref1 !== void 0 ? _ref1 : src;
1893
+ setValue(src ? initialImage.current : defaultImage.current);
1894
+ return [
1895
+ 2
1896
+ ];
1897
+ }
1898
+ });
1899
+ })();
1900
+ })();
1901
+ }, []);
1859
1902
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", {
1860
1903
  style: styles_default8.container,
1861
1904
  children: [
@@ -1893,38 +1936,35 @@ var Avatar = function(param) {
1893
1936
  });
1894
1937
  }
1895
1938
  }),
1896
- src !== defaultImage.current && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, {
1939
+ isAbleToRemove && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Button_default, {
1940
+ style: styles_default8.remove,
1941
+ onClick: function() {
1942
+ var _defaultImage_current;
1943
+ setValue((_defaultImage_current = defaultImage.current) !== null && _defaultImage_current !== void 0 ? _defaultImage_current : void 0);
1944
+ setNew(function(prev) {
1945
+ return !prev;
1946
+ });
1947
+ },
1897
1948
  children: [
1898
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Button_default, {
1899
- style: styles_default8.remove,
1900
- onClick: function() {
1901
- setValue(defaultImage.current);
1902
- setNew(function(prev) {
1903
- return !prev;
1904
- });
1905
- },
1906
- children: [
1907
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_fa6.FaTrashCan, {
1908
- size: others.iconSize,
1909
- color: "red"
1910
- }),
1911
- "Remove"
1912
- ]
1949
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_fa6.FaTrashCan, {
1950
+ size: others.iconSize,
1951
+ color: "red"
1913
1952
  }),
1914
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Button_default, {
1915
- style: styles_default8.edit,
1916
- onClick: function() {
1917
- return setOpen(function(prev) {
1918
- return !prev;
1919
- });
1920
- },
1921
- children: [
1922
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ri.RiEditLine, {
1923
- size: others.iconSize
1924
- }),
1925
- "Edit"
1926
- ]
1927
- })
1953
+ "Remove"
1954
+ ]
1955
+ }),
1956
+ isAbleToEdit && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Button_default, {
1957
+ style: styles_default8.edit,
1958
+ onClick: function() {
1959
+ return setOpen(function(prev) {
1960
+ return !prev;
1961
+ });
1962
+ },
1963
+ children: [
1964
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_ri.RiEditLine, {
1965
+ size: others.iconSize
1966
+ }),
1967
+ "Edit"
1928
1968
  ]
1929
1969
  })
1930
1970
  ]
@@ -2232,7 +2272,7 @@ var Image = function(_param) {
2232
2272
  };
2233
2273
  var Image_default = Image;
2234
2274
  // src/components/Image/ImageEditor/ImageEditor.tsx
2235
- var import_react14 = require("react");
2275
+ var import_react17 = require("react");
2236
2276
  // src/components/Image/ImageEditor/ImageEditor.styles.ts
2237
2277
  var imageEditorStyles = {
2238
2278
  imageEditor: {
@@ -2246,36 +2286,7 @@ var imageEditorStyles = {
2246
2286
  top: 0,
2247
2287
  left: 0,
2248
2288
  backdropFilter: "blur(20px)",
2249
- zIndex: 99,
2250
- paddingLeft: "30px",
2251
- paddingRight: "30px"
2252
- },
2253
- frame: {
2254
- padding: "50px",
2255
- backgroundColor: "white",
2256
- border: "solid 4px #000",
2257
- borderStyle: "dashed",
2258
- borderRadius: "50%",
2259
- overflow: "hidden",
2260
- maxWidth: "500px",
2261
- width: "100%",
2262
- maxHeight: "500px",
2263
- aspectRatio: 1 / 1,
2264
- position: "relative"
2265
- },
2266
- wrapper: {
2267
- position: "absolute",
2268
- transformOrigin: "top left",
2269
- userSelect: "none"
2270
- },
2271
- img: {
2272
- objectFit: "contain",
2273
- position: "absolute",
2274
- top: 0,
2275
- left: 0,
2276
- display: "block",
2277
- zIndex: 1,
2278
- transform: "translate(-50%, -50%)"
2289
+ zIndex: 99
2279
2290
  },
2280
2291
  buttons: {
2281
2292
  display: "flex",
@@ -2283,234 +2294,1214 @@ var imageEditorStyles = {
2283
2294
  alignItems: "center",
2284
2295
  gap: "20px",
2285
2296
  padding: "30px"
2297
+ },
2298
+ instruction: {
2299
+ fontWeight: "bold",
2300
+ fontSize: "20px"
2286
2301
  }
2287
2302
  };
2288
2303
  var ImageEditor_styles_default = imageEditorStyles;
2289
- // src/components/Image/ImageEditor/ImageEditor.tsx
2290
- var import_jsx_runtime19 = require("react/jsx-runtime");
2291
- var ImageEditor = function(param) {
2292
- 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;
2293
- var createTransform = function createTransform() {
2294
- return _async_to_generator(function() {
2295
- var transform2;
2296
- return _ts_generator(this, function(_state) {
2297
- switch(_state.label){
2298
- case 0:
2299
- if (!frame.current || !wrapper.current || !img.current) return [
2300
- 2
2301
- ];
2302
- transform2 = new Transform(wrapper.current, frame.current);
2303
- return [
2304
- 4,
2305
- transform2.initialize()
2306
- ];
2307
- case 1:
2308
- _state.sent();
2309
- if (transformState.current) {
2310
- transform2.setState(transformState.current);
2311
- } else {
2312
- transform2.reset();
2313
- }
2314
- setTransform(transform2);
2315
- return [
2316
- 2
2317
- ];
2318
- }
2319
- });
2320
- })();
2321
- };
2322
- var handleCanvasToSrc = function handleCanvasToSrc() {
2323
- if (!frame.current || !wrapper.current || !img.current || !transform) return;
2324
- var canvasInstance = new Canvas();
2325
- var _canvasInstance_createCanvas = canvasInstance.createCanvas(700, 700), canvas = _canvasInstance_createCanvas.canvas, context = _canvasInstance_createCanvas.context;
2326
- var _transform_exportData = transform.exportData(), x = _transform_exportData.x, y = _transform_exportData.y, angle = _transform_exportData.angle;
2327
- transformState.current = transform.exportData();
2328
- var _canvasInstance_drawImage = canvasInstance.drawImage(img.current, context, x, y, 1, angle, canvas, frame.current.clientWidth, frame.current.clientHeight), src2 = _canvasInstance_drawImage.src;
2329
- return src2;
2330
- };
2331
- var handleAccept = function handleAccept() {
2332
- setSrc(handleCanvasToSrc());
2333
- setOpen(false);
2334
- };
2335
- var handleCancel = function handleCancel() {
2336
- setOpen(false);
2337
- };
2338
- var handleReset = function handleReset() {
2339
- if (!transform) return;
2340
- transform.reset();
2341
- };
2342
- var frame = (0, import_react14.useRef)(null);
2343
- var wrapper = (0, import_react14.useRef)(null);
2344
- var img = (0, import_react14.useRef)(null);
2345
- var _ref = _sliced_to_array((0, import_react14.useState)(void 0), 2), transform = _ref[0], setTransform = _ref[1];
2346
- var transformState = (0, import_react14.useRef)(void 0);
2347
- var originalSrc = (0, import_react14.useMemo)(function() {
2348
- transformState.current = void 0;
2349
- return src;
2350
- }, [
2351
- isNew
2352
- ]);
2353
- (0, import_react14.useEffect)(function() {
2354
- isOpen ? createTransform() : setTransform(void 0);
2355
- }, [
2356
- isOpen
2357
- ]);
2358
- if (!isOpen) return;
2359
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", {
2360
- style: ImageEditor_styles_default.imageEditor,
2361
- children: [
2362
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("p", {
2363
- children: "Drag, Zoom, or Rotate image"
2364
- }),
2365
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", {
2366
- ref: frame,
2367
- style: ImageEditor_styles_default.frame,
2368
- children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", {
2369
- ref: wrapper,
2370
- style: ImageEditor_styles_default.wrapper,
2371
- children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("img", {
2372
- src: originalSrc,
2373
- style: ImageEditor_styles_default.img,
2374
- ref: img
2375
- })
2376
- })
2377
- }),
2378
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", {
2379
- style: ImageEditor_styles_default.buttons,
2380
- children: [
2381
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button_default, {
2382
- buttonType: "solid",
2383
- content: "Accept",
2384
- onClick: handleAccept
2385
- }),
2386
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button_default, {
2387
- buttonType: "solid",
2388
- content: "Cancel",
2389
- onClick: handleCancel
2390
- }),
2391
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Button_default, {
2392
- buttonType: "solid",
2393
- content: "Reset",
2394
- onClick: handleReset
2395
- })
2396
- ]
2397
- })
2398
- ]
2399
- });
2400
- };
2401
- var ImageEditor_default = ImageEditor;
2402
- // src/utilities/canvas/Canvas.ts
2403
- var Canvas = /*#__PURE__*/ function() {
2404
- function Canvas() {
2405
- _class_call_check(this, Canvas);
2304
+ // src/utilities/Transform/Events/MouseEvents.ts
2305
+ var WMouseEvent = /*#__PURE__*/ function() {
2306
+ function WMouseEvent(transformOperation2) {
2307
+ _class_call_check(this, WMouseEvent);
2308
+ this.transformOperation = transformOperation2;
2406
2309
  }
2407
- _create_class(Canvas, [
2310
+ _create_class(WMouseEvent, [
2408
2311
  {
2409
- key: "createCanvas",
2410
- value: function createCanvas(width, height) {
2411
- var canvas = document.createElement("canvas");
2412
- var context = canvas.getContext("2d");
2413
- canvas.width = width;
2414
- canvas.height = height;
2415
- return {
2416
- canvas: canvas,
2417
- context: context
2312
+ key: "drag",
2313
+ value: function drag(e) {
2314
+ var _this = this;
2315
+ e.stopPropagation();
2316
+ var controller = new AbortController();
2317
+ var _this_transformOperation_getDimension = this.transformOperation.getDimension(), initX = _this_transformOperation_getDimension.x, initY = _this_transformOperation_getDimension.y;
2318
+ var mousePressX = e.clientX;
2319
+ var mousePressY = e.clientY;
2320
+ var onMouseMove = function(event) {
2321
+ var x = event.clientX;
2322
+ var y = event.clientY;
2323
+ var posX = initX + (x - mousePressX);
2324
+ var posY = initY + (y - mousePressY);
2325
+ _this.transformOperation.setDimension({
2326
+ x: posX,
2327
+ y: posY
2328
+ });
2329
+ };
2330
+ var onMouseUp = function() {
2331
+ controller.abort();
2418
2332
  };
2333
+ window.addEventListener("mousemove", onMouseMove, {
2334
+ signal: controller.signal
2335
+ });
2336
+ window.addEventListener("mouseup", onMouseUp, {
2337
+ signal: controller.signal
2338
+ });
2419
2339
  }
2420
2340
  },
2421
2341
  {
2422
- key: "drawImage",
2423
- value: function drawImage(e, ctx, x, y, scale, angle, canvas, containerWidth, containerHeight) {
2424
- var ratioX = canvas.width / containerWidth;
2425
- var ratioY = canvas.height / containerHeight;
2426
- var finalX = x * ratioX;
2427
- var finalY = y * ratioY;
2428
- var midleWidth = e.width * ratioX;
2429
- var midleHeight = e.height * ratioY;
2430
- var finalWidth = e.width * ratioX * scale;
2431
- var finalHeight = e.height * ratioY * scale;
2432
- ctx.save();
2433
- ctx.translate(finalX + midleWidth / 2, finalY + midleHeight / 2);
2434
- ctx.rotate(angle * Math.PI / 180);
2435
- ctx.drawImage(e, -finalWidth / 2, -finalHeight / 2, finalWidth, finalHeight);
2436
- ctx.restore();
2437
- var src = ctx.canvas.toDataURL();
2438
- var srcEncoded = src.split(",")[1];
2439
- return {
2440
- context: ctx,
2441
- src: src
2342
+ key: "rotate",
2343
+ value: function rotate(e) {
2344
+ var _this = this;
2345
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
2346
+ top: false,
2347
+ bottom: false
2348
+ };
2349
+ e.stopPropagation();
2350
+ var controller = new AbortController();
2351
+ 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;
2352
+ var centerX = x + width / 2;
2353
+ var centerY = y + height / 2;
2354
+ var _this_transformOperation_getOrigin = this.transformOperation.getOrigin(), xOrigin = _this_transformOperation_getOrigin.x, yOrigin = _this_transformOperation_getOrigin.y;
2355
+ var compensation = options.top ? 0 : 180;
2356
+ compensation = options.bottom ? 180 : 0;
2357
+ var onMouseMove = function(event) {
2358
+ var x2 = event.clientX - xOrigin;
2359
+ var y2 = event.clientY - yOrigin;
2360
+ var angle = Math.atan2(y2 - centerY, x2 - centerX) + Math.PI / 2;
2361
+ angle *= 180 / Math.PI;
2362
+ angle += compensation;
2363
+ _this.transformOperation.setDimension({
2364
+ angle: angle
2365
+ });
2366
+ };
2367
+ var onMouseUp = function() {
2368
+ controller.abort();
2442
2369
  };
2370
+ window.addEventListener("mousemove", onMouseMove, {
2371
+ signal: controller.signal
2372
+ });
2373
+ window.addEventListener("mouseup", onMouseUp, {
2374
+ signal: controller.signal
2375
+ });
2443
2376
  }
2444
2377
  },
2445
2378
  {
2446
- key: "drawColor",
2447
- value: function drawColor(type, color, ctx, width, ratio) {
2448
- if (type === "") color = "#ffffff";
2449
- if (type === "gradient") {
2450
- var breakdownArr = color.split(",");
2451
- var _ref = [
2452
- Number(breakdownArr[0]),
2453
- breakdownArr[1],
2454
- Number(breakdownArr[2]),
2455
- breakdownArr[3],
2456
- Number(breakdownArr[4])
2457
- ], angle = _ref[0], color1 = _ref[1], percent1 = _ref[2], color2 = _ref[3], percent2 = _ref[4];
2458
- var radians = (angle - 180) * Math.PI / 180;
2459
- var x0 = width / 2 + width / 2 * Math.cos(radians - Math.PI / 2);
2460
- var y0 = width * ratio / 2 + width * ratio / 2 * Math.sin(radians - Math.PI / 2);
2461
- var x1 = width / 2 - width / 2 * Math.cos(radians - Math.PI / 2);
2462
- var y1 = width * ratio / 2 - width * ratio / 2 * Math.sin(radians - Math.PI / 2);
2463
- var gradient = ctx.createLinearGradient(x0, y0, x1, y1);
2464
- gradient.addColorStop(percent1 / 100, color1);
2465
- gradient.addColorStop(percent2 / 100, color2);
2466
- ctx.fillStyle = gradient;
2467
- ctx.fillRect(0, 0, width, width * ratio);
2468
- var srcEncoded = ctx.canvas.toDataURL().split(",")[1];
2469
- return [
2470
- ctx,
2471
- srcEncoded
2472
- ];
2379
+ key: "resize",
2380
+ value: function resize(e, param) {
2381
+ var _this = this;
2382
+ 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;
2383
+ e.stopPropagation();
2384
+ var controller = new AbortController();
2385
+ var minWidth = 40;
2386
+ 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;
2387
+ var _this_transformOperation_getOrigin = this.transformOperation.getOrigin(), xOrigin = _this_transformOperation_getOrigin.x, yOrigin = _this_transformOperation_getOrigin.y;
2388
+ var initAngle = initAngleDegree * Math.PI / 180;
2389
+ var topLeftResizer = [
2390
+ initX,
2391
+ initY,
2392
+ 1
2393
+ ];
2394
+ var topRightResizer = [
2395
+ initX + initW,
2396
+ initY,
2397
+ 1
2398
+ ];
2399
+ var bottomLeftResizer = [
2400
+ initX,
2401
+ initY + initH,
2402
+ 1
2403
+ ];
2404
+ var bottomRightResizer = [
2405
+ initX + initW,
2406
+ initY + initH,
2407
+ 1
2408
+ ];
2409
+ var p, q;
2410
+ if (topLeft) {
2411
+ q = topLeftResizer;
2412
+ p = bottomRightResizer;
2413
+ } else if (topRight) {
2414
+ q = topRightResizer;
2415
+ p = bottomLeftResizer;
2416
+ } else if (bottomLeft) {
2417
+ q = bottomLeftResizer, p = topRightResizer;
2418
+ } else if (bottomRight) {
2419
+ q = bottomRightResizer, p = topLeftResizer;
2473
2420
  } else {
2474
- ctx.fillStyle = color;
2475
- ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
2476
- var srcEncoded1 = ctx.canvas.toDataURL().split(",")[1];
2477
- return [
2478
- ctx,
2479
- srcEncoded1
2480
- ];
2421
+ return;
2481
2422
  }
2423
+ var rotated_p = LinearAlgebra_default.NicolasMattia(p, LinearAlgebra_default.getMiddleVectorFrom(q, p), initAngle);
2424
+ var rotated_q = LinearAlgebra_default.NicolasMattia(q, LinearAlgebra_default.getMiddleVectorFrom(p, q), initAngle);
2425
+ var rotated_diagonal = LinearAlgebra_default.plusVectors(rotated_q, LinearAlgebra_default.getOppositeVector(rotated_p));
2426
+ var rotated_diagonal_magnitude = LinearAlgebra_default.getVectorMagnitude(rotated_diagonal);
2427
+ var onMouseMove = function(event) {
2428
+ var cursor = [
2429
+ event.clientX - xOrigin,
2430
+ event.clientY - yOrigin,
2431
+ 1
2432
+ ];
2433
+ var moved = LinearAlgebra_default.plusVectors(cursor, LinearAlgebra_default.getOppositeVector(rotated_q));
2434
+ var moved_projection_coefficient = LinearAlgebra_default.dotProduct(rotated_diagonal, moved) / (rotated_diagonal_magnitude * rotated_diagonal_magnitude);
2435
+ var moved_projection = LinearAlgebra_default.setCoefficient(moved_projection_coefficient, rotated_diagonal);
2436
+ var moved_q = LinearAlgebra_default.plusVectors(rotated_q, moved_projection);
2437
+ var newP = LinearAlgebra_default.NicolasMattia(rotated_p, LinearAlgebra_default.getMiddleVectorFrom(moved_q, rotated_p), -initAngle);
2438
+ var newQ = LinearAlgebra_default.NicolasMattia(moved_q, LinearAlgebra_default.getMiddleVectorFrom(moved_q, rotated_p), -initAngle);
2439
+ var newWH = LinearAlgebra_default.plusVectors(newQ, LinearAlgebra_default.getOppositeVector(newP));
2440
+ var newW = Math.abs(newWH[0]);
2441
+ if (newW <= minWidth) {
2442
+ newW = minWidth;
2443
+ return;
2444
+ }
2445
+ if (topLeft) {
2446
+ _this.transformOperation.setDimension({
2447
+ x: newP[0] - newW,
2448
+ y: newP[1] - newW / ratio,
2449
+ width: newW,
2450
+ height: newW / ratio
2451
+ });
2452
+ } else if (topRight) {
2453
+ _this.transformOperation.setDimension({
2454
+ x: newP[0],
2455
+ y: newP[1] - newW / ratio,
2456
+ width: newW,
2457
+ height: newW / ratio
2458
+ });
2459
+ } else if (bottomLeft) {
2460
+ _this.transformOperation.setDimension({
2461
+ x: newP[0] - newW,
2462
+ y: newP[1],
2463
+ width: newW,
2464
+ height: newW / ratio
2465
+ });
2466
+ } else if (bottomRight) {
2467
+ _this.transformOperation.setDimension({
2468
+ x: newP[0],
2469
+ y: newP[1],
2470
+ width: newW,
2471
+ height: newW / ratio
2472
+ });
2473
+ } else {
2474
+ return;
2475
+ }
2476
+ };
2477
+ var onMouseUp = function() {
2478
+ controller.abort();
2479
+ };
2480
+ window.addEventListener("mousemove", onMouseMove, {
2481
+ signal: controller.signal
2482
+ });
2483
+ window.addEventListener("mouseup", onMouseUp, {
2484
+ signal: controller.signal
2485
+ });
2482
2486
  }
2483
2487
  }
2484
2488
  ]);
2485
- return Canvas;
2489
+ return WMouseEvent;
2486
2490
  }();
2487
- // src/utilities/canvas/Image.ts
2488
- var Image2 = {
2489
- /**
2490
- * Convert file (blob) to base64 string format
2491
- * @param file
2492
- * @returns
2493
- */ FromFileToImageSrc: function FromFileToImageSrc(file) {
2494
- return new Promise(function(resolve, reject) {
2495
- if (!file) return resolve(null);
2496
- var reader = new FileReader();
2497
- reader.readAsDataURL(file);
2498
- reader.onload = function(readerEvent) {
2499
- var _readerEvent_target;
2500
- if ((_readerEvent_target = readerEvent.target) === null || _readerEvent_target === void 0 ? void 0 : _readerEvent_target.result) {
2501
- var _readerEvent_target1;
2502
- return resolve((_readerEvent_target1 = readerEvent.target) === null || _readerEvent_target1 === void 0 ? void 0 : _readerEvent_target1.result);
2503
- }
2504
- reject("Error getting the image source");
2505
- };
2506
- reader.onerror = function() {
2507
- reject("Error getting the image source");
2508
- };
2509
- });
2510
- },
2511
- FromStringToImageSrc: /**
2512
- * Convert urlst
2513
- * @param url
2491
+ // src/utilities/Transform/Events/TouchEvents.ts
2492
+ var WTouchEvent = /*#__PURE__*/ function() {
2493
+ function WTouchEvent(transformOperation2) {
2494
+ _class_call_check(this, WTouchEvent);
2495
+ this.transformOperation = transformOperation2;
2496
+ }
2497
+ _create_class(WTouchEvent, [
2498
+ {
2499
+ key: "drag",
2500
+ value: function drag(e) {
2501
+ var _this = this;
2502
+ e.stopPropagation();
2503
+ var controller = new AbortController();
2504
+ var _this_transformOperation_getDimension = this.transformOperation.getDimension(), initX = _this_transformOperation_getDimension.x, initY = _this_transformOperation_getDimension.y;
2505
+ var mousePressX = e.touches[0].clientX;
2506
+ var mousePressY = e.touches[0].clientY;
2507
+ var onTouchMove = function(event) {
2508
+ var x = event.touches[0].clientX;
2509
+ var y = event.touches[0].clientY;
2510
+ var posX = initX + (x - mousePressX);
2511
+ var posY = initY + (y - mousePressY);
2512
+ _this.transformOperation.setDimension({
2513
+ x: posX,
2514
+ y: posY
2515
+ });
2516
+ };
2517
+ var onTouchEnd = function() {
2518
+ controller.abort();
2519
+ };
2520
+ window.addEventListener("touchmove", onTouchMove, {
2521
+ signal: controller.signal,
2522
+ passive: true
2523
+ });
2524
+ window.addEventListener("touchend", onTouchEnd, {
2525
+ signal: controller.signal
2526
+ });
2527
+ }
2528
+ },
2529
+ {
2530
+ key: "rotate",
2531
+ value: function rotate(e) {
2532
+ var _this = this;
2533
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
2534
+ top: false,
2535
+ bottom: false
2536
+ };
2537
+ e.stopPropagation();
2538
+ var controller = new AbortController();
2539
+ 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;
2540
+ var centerX = x + width / 2;
2541
+ var centerY = y + height / 2;
2542
+ var _this_transformOperation_getOrigin = this.transformOperation.getOrigin(), xOrigin = _this_transformOperation_getOrigin.x, yOrigin = _this_transformOperation_getOrigin.y;
2543
+ var compensation = options.top ? 0 : 180;
2544
+ compensation = options.bottom ? 180 : 0;
2545
+ var onTouchMove = function(event) {
2546
+ var x2 = event.touches[0].clientX - xOrigin;
2547
+ var y2 = event.touches[0].clientY - yOrigin;
2548
+ var angle = Math.atan2(y2 - centerY, x2 - centerX) + Math.PI / 2;
2549
+ angle *= 180 / Math.PI;
2550
+ angle += compensation;
2551
+ _this.transformOperation.setDimension({
2552
+ angle: angle
2553
+ });
2554
+ };
2555
+ var onTouchEnd = function() {
2556
+ controller.abort();
2557
+ };
2558
+ window.addEventListener("touchmove", onTouchMove, {
2559
+ signal: controller.signal,
2560
+ passive: true
2561
+ });
2562
+ window.addEventListener("touchend", onTouchEnd, {
2563
+ signal: controller.signal
2564
+ });
2565
+ }
2566
+ },
2567
+ {
2568
+ key: "resize",
2569
+ value: function resize(e, param) {
2570
+ var _this = this;
2571
+ 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;
2572
+ e.stopPropagation();
2573
+ var controller = new AbortController();
2574
+ var minWidth = 40;
2575
+ 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;
2576
+ var _this_transformOperation_getOrigin = this.transformOperation.getOrigin(), xOrigin = _this_transformOperation_getOrigin.x, yOrigin = _this_transformOperation_getOrigin.y;
2577
+ var initAngle = initAngleDegree * Math.PI / 180;
2578
+ var topLeftResizer = [
2579
+ initX,
2580
+ initY,
2581
+ 1
2582
+ ];
2583
+ var topRightResizer = [
2584
+ initX + initW,
2585
+ initY,
2586
+ 1
2587
+ ];
2588
+ var bottomLeftResizer = [
2589
+ initX,
2590
+ initY + initH,
2591
+ 1
2592
+ ];
2593
+ var bottomRightResizer = [
2594
+ initX + initW,
2595
+ initY + initH,
2596
+ 1
2597
+ ];
2598
+ var p, q;
2599
+ if (topLeft) {
2600
+ q = topLeftResizer;
2601
+ p = bottomRightResizer;
2602
+ } else if (topRight) {
2603
+ q = topRightResizer;
2604
+ p = bottomLeftResizer;
2605
+ } else if (bottomLeft) {
2606
+ q = bottomLeftResizer, p = topRightResizer;
2607
+ } else if (bottomRight) {
2608
+ q = bottomRightResizer, p = topLeftResizer;
2609
+ } else {
2610
+ return;
2611
+ }
2612
+ var rotated_p = LinearAlgebra_default.NicolasMattia(p, LinearAlgebra_default.getMiddleVectorFrom(q, p), initAngle);
2613
+ var rotated_q = LinearAlgebra_default.NicolasMattia(q, LinearAlgebra_default.getMiddleVectorFrom(p, q), initAngle);
2614
+ var rotated_diagonal = LinearAlgebra_default.plusVectors(rotated_q, LinearAlgebra_default.getOppositeVector(rotated_p));
2615
+ var rotated_diagonal_magnitude = LinearAlgebra_default.getVectorMagnitude(rotated_diagonal);
2616
+ var onTouchMove = function(event) {
2617
+ var cursor = [
2618
+ event.touches[0].clientX - xOrigin,
2619
+ event.touches[0].clientY - yOrigin,
2620
+ 1
2621
+ ];
2622
+ var moved = LinearAlgebra_default.plusVectors(cursor, LinearAlgebra_default.getOppositeVector(rotated_q));
2623
+ var moved_projection_coefficient = LinearAlgebra_default.dotProduct(rotated_diagonal, moved) / (rotated_diagonal_magnitude * rotated_diagonal_magnitude);
2624
+ var moved_projection = LinearAlgebra_default.setCoefficient(moved_projection_coefficient, rotated_diagonal);
2625
+ var moved_q = LinearAlgebra_default.plusVectors(rotated_q, moved_projection);
2626
+ var newP = LinearAlgebra_default.NicolasMattia(rotated_p, LinearAlgebra_default.getMiddleVectorFrom(moved_q, rotated_p), -initAngle);
2627
+ var newQ = LinearAlgebra_default.NicolasMattia(moved_q, LinearAlgebra_default.getMiddleVectorFrom(moved_q, rotated_p), -initAngle);
2628
+ var newWH = LinearAlgebra_default.plusVectors(newQ, LinearAlgebra_default.getOppositeVector(newP));
2629
+ var newW = Math.abs(newWH[0]);
2630
+ if (newW <= minWidth) {
2631
+ newW = minWidth;
2632
+ return;
2633
+ }
2634
+ if (topLeft) {
2635
+ _this.transformOperation.setDimension({
2636
+ x: newP[0] - newW,
2637
+ y: newP[1] - newW / ratio,
2638
+ width: newW,
2639
+ height: newW / ratio
2640
+ });
2641
+ } else if (topRight) {
2642
+ _this.transformOperation.setDimension({
2643
+ x: newP[0],
2644
+ y: newP[1] - newW / ratio,
2645
+ width: newW,
2646
+ height: newW / ratio
2647
+ });
2648
+ } else if (bottomLeft) {
2649
+ _this.transformOperation.setDimension({
2650
+ x: newP[0] - newW,
2651
+ y: newP[1],
2652
+ width: newW,
2653
+ height: newW / ratio
2654
+ });
2655
+ } else if (bottomRight) {
2656
+ _this.transformOperation.setDimension({
2657
+ x: newP[0],
2658
+ y: newP[1],
2659
+ width: newW,
2660
+ height: newW / ratio
2661
+ });
2662
+ } else {
2663
+ return;
2664
+ }
2665
+ };
2666
+ var onTouchEnd = function() {
2667
+ controller.abort();
2668
+ };
2669
+ window.addEventListener("touchmove", onTouchMove, {
2670
+ signal: controller.signal,
2671
+ passive: true
2672
+ });
2673
+ window.addEventListener("touchend", onTouchEnd, {
2674
+ signal: controller.signal
2675
+ });
2676
+ }
2677
+ }
2678
+ ]);
2679
+ return WTouchEvent;
2680
+ }();
2681
+ // src/components/Image/ImageEditor/MainElements/MainElements.tsx
2682
+ var import_react16 = require("react");
2683
+ // src/components/Image/ImageEditor/context.ts
2684
+ var import_react14 = require("react");
2685
+ var MyContext3 = (0, import_react14.createContext)(void 0);
2686
+ function useMyContext3() {
2687
+ var data = (0, import_react14.useContext)(MyContext3);
2688
+ if (data === void 0) throw new Error("Context is undefined");
2689
+ return data;
2690
+ }
2691
+ // src/components/Image/ImageEditor/MainElements/MainElements.styles.ts
2692
+ var resize = {
2693
+ position: "absolute",
2694
+ backgroundColor: "white",
2695
+ width: "20px",
2696
+ height: "20px",
2697
+ borderRadius: "50%",
2698
+ boxShadow: "rgba(0, 0, 0, 0.35) 0px 5px 15px",
2699
+ transition: "all .1s linear",
2700
+ cursor: "pointer"
2701
+ };
2702
+ var background = {
2703
+ visibility: "hidden",
2704
+ position: "absolute",
2705
+ top: "50%",
2706
+ left: "50%",
2707
+ transform: "translate(-50%, -50%)",
2708
+ width: "60px",
2709
+ height: "60px",
2710
+ borderRadius: "50%",
2711
+ boxShadow: "rgba(0, 0, 0, 0.35) 0px 5px 15px",
2712
+ zIndex: -1,
2713
+ transition: "all .1s linear"
2714
+ };
2715
+ var MainElementStyles = {
2716
+ container: {
2717
+ position: "relative",
2718
+ border: "solid 4px #000",
2719
+ borderStyle: "dashed",
2720
+ borderRadius: "50%",
2721
+ width: "100%",
2722
+ maxWidth: "508px",
2723
+ aspectRatio: 1,
2724
+ display: "flex",
2725
+ justifyContent: "center",
2726
+ alignItems: "center",
2727
+ boxSizing: "border-box"
2728
+ },
2729
+ frame: {
2730
+ borderRadius: "50%",
2731
+ boxSizing: "border-box",
2732
+ padding: "50px",
2733
+ backgroundColor: "white",
2734
+ overflow: "hidden",
2735
+ maxWidth: "500px",
2736
+ width: "100%",
2737
+ maxHeight: "500px",
2738
+ aspectRatio: 1 / 1,
2739
+ position: "relative"
2740
+ },
2741
+ img: {
2742
+ objectFit: "contain",
2743
+ position: "absolute",
2744
+ userSelect: "none",
2745
+ top: 0,
2746
+ left: 0,
2747
+ display: "block",
2748
+ zIndex: 0
2749
+ },
2750
+ controller: {
2751
+ position: "absolute",
2752
+ userSelect: "none",
2753
+ border: "solid 3px #6924d5",
2754
+ top: 0,
2755
+ left: 0
2756
+ },
2757
+ resizeDown: {
2758
+ color: "white",
2759
+ backgroundColor: "#6924d5"
2760
+ },
2761
+ topLeft: _object_spread_props(_object_spread({}, resize), {
2762
+ top: "-10px",
2763
+ left: "-10px"
2764
+ }),
2765
+ topRight: _object_spread_props(_object_spread({}, resize), {
2766
+ top: "-10px",
2767
+ right: "-10px"
2768
+ }),
2769
+ bottomLeft: _object_spread_props(_object_spread({}, resize), {
2770
+ bottom: "-10px",
2771
+ left: "-10px"
2772
+ }),
2773
+ bottomRight: _object_spread_props(_object_spread({}, resize), {
2774
+ bottom: "-10px",
2775
+ right: "-10px"
2776
+ }),
2777
+ buttonBackground: _object_spread({}, background),
2778
+ buttonBackgroundDown: _object_spread_props(_object_spread({}, background), {
2779
+ visibility: "visible"
2780
+ }),
2781
+ rotate: _object_spread_props(_object_spread({}, resize), {
2782
+ top: "-50px",
2783
+ width: "30px",
2784
+ height: "30px",
2785
+ left: "50%",
2786
+ transform: "translate(-50%, 0%)",
2787
+ display: "flex",
2788
+ justifyContent: "center",
2789
+ alignItems: "center",
2790
+ cursor: "alias"
2791
+ }),
2792
+ rotateBottom: _object_spread_props(_object_spread({}, resize), {
2793
+ display: "none",
2794
+ bottom: "-50px",
2795
+ width: "30px",
2796
+ height: "30px",
2797
+ left: "50%",
2798
+ transform: "translate(-50%, 0%)",
2799
+ justifyContent: "center",
2800
+ alignItems: "center",
2801
+ cursor: "alias"
2802
+ }),
2803
+ label: {
2804
+ position: "absolute",
2805
+ top: "-100px",
2806
+ left: "50%",
2807
+ transformOrigin: "left",
2808
+ transform: "translate(-50%, 0)",
2809
+ margin: 0,
2810
+ color: "black",
2811
+ width: "max-content"
2812
+ }
2813
+ };
2814
+ var MainElements_styles_default = MainElementStyles;
2815
+ // src/components/Image/ImageEditor/MainElements/Rotate.tsx
2816
+ var import_react15 = require("react");
2817
+ var import_fa62 = require("react-icons/fa6");
2818
+ var import_jsx_runtime19 = require("react/jsx-runtime");
2819
+ var Rotate = function() {
2820
+ var _ref = _sliced_to_array((0, import_react15.useState)(false), 2), rotate = _ref[0], setRotate = _ref[1];
2821
+ var _useMyContext3 = useMyContext3(), transformOperation2 = _useMyContext3.transformOperation, refs = _useMyContext3.refs;
2822
+ var mouseEvent = new WMouseEvent(transformOperation2);
2823
+ var touchEvent = new WTouchEvent(transformOperation2);
2824
+ var angle = transformOperation2.getDimension().angle;
2825
+ var handleBackground = function(value) {
2826
+ return value ? MainElements_styles_default.buttonBackgroundDown : MainElements_styles_default.buttonBackground;
2827
+ };
2828
+ (0, import_react15.useEffect)(function() {
2829
+ var controller = new AbortController();
2830
+ var handler = function() {
2831
+ setRotate(false);
2832
+ };
2833
+ window.addEventListener("mouseup", function() {
2834
+ handler();
2835
+ }, {
2836
+ signal: controller.signal
2837
+ });
2838
+ window.addEventListener("touchend", function() {
2839
+ handler();
2840
+ }, {
2841
+ signal: controller.signal
2842
+ });
2843
+ return function() {
2844
+ controller.abort();
2845
+ };
2846
+ }, []);
2847
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, {
2848
+ children: [
2849
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", {
2850
+ ref: refs.rotate,
2851
+ style: rotate ? _object_spread({}, MainElements_styles_default.rotate, MainElements_styles_default.resizeDown) : MainElements_styles_default.rotate,
2852
+ onMouseDown: function(e) {
2853
+ setRotate(true);
2854
+ mouseEvent.rotate(e, {
2855
+ top: true
2856
+ });
2857
+ },
2858
+ onTouchStart: function(e) {
2859
+ setRotate(true);
2860
+ touchEvent.rotate(e, {
2861
+ top: true
2862
+ });
2863
+ },
2864
+ children: [
2865
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", {
2866
+ style: handleBackground(rotate)
2867
+ }),
2868
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_fa62.FaArrowRotateLeft, {
2869
+ size: "15"
2870
+ }),
2871
+ rotate && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("p", {
2872
+ style: _object_spread_props(_object_spread({}, MainElements_styles_default.label), {
2873
+ rotate: "".concat(-angle.toFixed(0), "deg")
2874
+ }),
2875
+ children: [
2876
+ angle.toFixed(0),
2877
+ "\xB0"
2878
+ ]
2879
+ })
2880
+ ]
2881
+ }),
2882
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", {
2883
+ ref: refs.rotateBottom,
2884
+ style: rotate ? _object_spread({}, MainElements_styles_default.rotateBottom, MainElements_styles_default.resizeDown) : _object_spread({}, MainElements_styles_default.rotateBottom),
2885
+ onMouseDown: function(e) {
2886
+ setRotate(true);
2887
+ mouseEvent.rotate(e, {
2888
+ bottom: true
2889
+ });
2890
+ },
2891
+ onTouchStart: function(e) {
2892
+ setRotate(true);
2893
+ touchEvent.rotate(e, {
2894
+ bottom: true
2895
+ });
2896
+ },
2897
+ children: [
2898
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", {
2899
+ style: handleBackground(rotate)
2900
+ }),
2901
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_fa62.FaArrowRotateLeft, {
2902
+ size: "15"
2903
+ }),
2904
+ rotate && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("p", {
2905
+ style: _object_spread_props(_object_spread({}, MainElements_styles_default.label), {
2906
+ top: "auto",
2907
+ bottom: "-100px",
2908
+ rotate: "".concat(-angle.toFixed(0), "deg")
2909
+ }),
2910
+ children: [
2911
+ angle.toFixed(0),
2912
+ "\xB0"
2913
+ ]
2914
+ })
2915
+ ]
2916
+ })
2917
+ ]
2918
+ });
2919
+ };
2920
+ var Rotate_default = Rotate;
2921
+ // src/components/Image/ImageEditor/MainElements/MainElements.tsx
2922
+ var import_jsx_runtime20 = require("react/jsx-runtime");
2923
+ var MainElements = function() {
2924
+ var _useMyContext3 = useMyContext3(), refs = _useMyContext3.refs, imgRefs = _useMyContext3.imgRefs, originalSrc = _useMyContext3.src, transformOperation2 = _useMyContext3.transformOperation;
2925
+ var mouseEvent = new WMouseEvent(transformOperation2);
2926
+ var touchEvent = new WTouchEvent(transformOperation2);
2927
+ var _ref = _sliced_to_array((0, import_react16.useState)(false), 2), topLeft = _ref[0], settopLeft = _ref[1];
2928
+ var _ref1 = _sliced_to_array((0, import_react16.useState)(false), 2), topRight = _ref1[0], settopRight = _ref1[1];
2929
+ var _ref2 = _sliced_to_array((0, import_react16.useState)(false), 2), bottomLeft = _ref2[0], setbottomLeft = _ref2[1];
2930
+ var _ref3 = _sliced_to_array((0, import_react16.useState)(false), 2), bottomRight = _ref3[0], setbottomRight = _ref3[1];
2931
+ var _ref4 = _sliced_to_array((0, import_react16.useState)(false), 2), reRender = _ref4[0], triggierReRender = _ref4[1];
2932
+ var _transformOperation2_getDimension = transformOperation2.getDimension(), angle = _transformOperation2_getDimension.angle, width = _transformOperation2_getDimension.width, height = _transformOperation2_getDimension.height;
2933
+ var handleBackground = function(value) {
2934
+ return value ? MainElements_styles_default.buttonBackgroundDown : MainElements_styles_default.buttonBackground;
2935
+ };
2936
+ (0, import_react16.useEffect)(function() {
2937
+ var controller = new AbortController();
2938
+ var handler = function() {
2939
+ settopLeft(false);
2940
+ settopRight(false);
2941
+ setbottomLeft(false);
2942
+ setbottomRight(false);
2943
+ };
2944
+ window.addEventListener("mousemove", function() {
2945
+ triggierReRender(function(prev) {
2946
+ return !prev;
2947
+ });
2948
+ }, {
2949
+ signal: controller.signal
2950
+ });
2951
+ window.addEventListener("touchmove", function() {
2952
+ triggierReRender(function(prev) {
2953
+ return !prev;
2954
+ });
2955
+ }, {
2956
+ signal: controller.signal
2957
+ });
2958
+ window.addEventListener("mouseup", function() {
2959
+ handler();
2960
+ }, {
2961
+ signal: controller.signal
2962
+ });
2963
+ window.addEventListener("touchend", function() {
2964
+ handler();
2965
+ }, {
2966
+ signal: controller.signal
2967
+ });
2968
+ return function() {
2969
+ controller.abort();
2970
+ };
2971
+ }, [
2972
+ reRender
2973
+ ]);
2974
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", {
2975
+ ref: refs.container,
2976
+ style: MainElements_styles_default.container,
2977
+ children: [
2978
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
2979
+ ref: refs.frame,
2980
+ style: MainElements_styles_default.frame,
2981
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("img", {
2982
+ src: originalSrc,
2983
+ style: MainElements_styles_default.img,
2984
+ ref: imgRefs.img
2985
+ })
2986
+ }),
2987
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", {
2988
+ style: MainElements_styles_default.controller,
2989
+ ref: refs.controller,
2990
+ onMouseDown: function(e) {
2991
+ return mouseEvent.drag(e);
2992
+ },
2993
+ onTouchStart: function(e) {
2994
+ return touchEvent.drag(e);
2995
+ },
2996
+ children: [
2997
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
2998
+ ref: refs.topLeft,
2999
+ style: topLeft ? _object_spread({}, MainElements_styles_default.topLeft, MainElements_styles_default.resizeDown) : MainElements_styles_default.topLeft,
3000
+ onMouseDown: function(e) {
3001
+ settopLeft(true);
3002
+ mouseEvent.resize(e, {
3003
+ topLeft: true
3004
+ });
3005
+ },
3006
+ onTouchStart: function(e) {
3007
+ settopLeft(true);
3008
+ touchEvent.resize(e, {
3009
+ topLeft: true
3010
+ });
3011
+ },
3012
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
3013
+ style: handleBackground(topLeft)
3014
+ })
3015
+ }),
3016
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
3017
+ ref: refs.topRight,
3018
+ style: topRight ? _object_spread({}, MainElements_styles_default.topRight, MainElements_styles_default.resizeDown) : MainElements_styles_default.topRight,
3019
+ onMouseDown: function(e) {
3020
+ settopRight(true);
3021
+ mouseEvent.resize(e, {
3022
+ topRight: true
3023
+ });
3024
+ },
3025
+ onTouchStart: function(e) {
3026
+ settopRight(true);
3027
+ touchEvent.resize(e, {
3028
+ topRight: true
3029
+ });
3030
+ },
3031
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
3032
+ style: handleBackground(topRight)
3033
+ })
3034
+ }),
3035
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
3036
+ ref: refs.bottomLeft,
3037
+ style: bottomLeft ? _object_spread({}, MainElements_styles_default.bottomLeft, MainElements_styles_default.resizeDown) : MainElements_styles_default.bottomLeft,
3038
+ onMouseDown: function(e) {
3039
+ setbottomLeft(true);
3040
+ mouseEvent.resize(e, {
3041
+ bottomLeft: true
3042
+ });
3043
+ },
3044
+ onTouchStart: function(e) {
3045
+ setbottomLeft(true);
3046
+ touchEvent.resize(e, {
3047
+ bottomLeft: true
3048
+ });
3049
+ },
3050
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
3051
+ style: handleBackground(bottomLeft)
3052
+ })
3053
+ }),
3054
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
3055
+ ref: refs.bottomRight,
3056
+ style: bottomRight ? _object_spread({}, MainElements_styles_default.bottomRight, MainElements_styles_default.resizeDown) : MainElements_styles_default.bottomRight,
3057
+ onMouseDown: function(e) {
3058
+ setbottomRight(true);
3059
+ mouseEvent.resize(e, {
3060
+ bottomRight: true
3061
+ });
3062
+ },
3063
+ onTouchStart: function(e) {
3064
+ setbottomRight(true);
3065
+ touchEvent.resize(e, {
3066
+ bottomRight: true
3067
+ });
3068
+ },
3069
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", {
3070
+ style: handleBackground(bottomRight)
3071
+ })
3072
+ }),
3073
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Rotate_default, {}),
3074
+ (topLeft || topRight || bottomLeft || bottomRight) && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("p", {
3075
+ style: _object_spread_props(_object_spread({}, MainElements_styles_default.label), {
3076
+ rotate: "".concat(-angle.toFixed(0), "deg")
3077
+ }),
3078
+ children: [
3079
+ "w: ",
3080
+ width.toFixed(0),
3081
+ "px, h: ",
3082
+ height.toFixed(0),
3083
+ "px"
3084
+ ]
3085
+ })
3086
+ ]
3087
+ })
3088
+ ]
3089
+ });
3090
+ };
3091
+ var MainElements_default = MainElements;
3092
+ // src/components/Image/ImageEditor/Instruction.tsx
3093
+ var import_jsx_runtime21 = require("react/jsx-runtime");
3094
+ var Instruction = function() {
3095
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("p", {
3096
+ style: ImageEditor_styles_default.instruction,
3097
+ children: "Drag, Zoom, or Rotate image"
3098
+ });
3099
+ };
3100
+ var Instruction_default = Instruction;
3101
+ // src/utilities/Transform/TransformOperationExtension.ts
3102
+ var TransformOperationExtension = /*#__PURE__*/ function() {
3103
+ function TransformOperationExtension() {
3104
+ _class_call_check(this, TransformOperationExtension);
3105
+ this.xOrigin = 0;
3106
+ this.yOrigin = 0;
3107
+ this.wOrigin = 0;
3108
+ this.hOrigin = 0;
3109
+ this.isSideEffect = false;
3110
+ this.sideEffectList = [];
3111
+ }
3112
+ _create_class(TransformOperationExtension, [
3113
+ {
3114
+ key: "subscribeSideEffect",
3115
+ value: function subscribeSideEffect(element) {
3116
+ this.sideEffectList.push(element);
3117
+ }
3118
+ },
3119
+ {
3120
+ key: "runSideEffectHandler",
3121
+ value: function runSideEffectHandler() {
3122
+ this.sideEffectList.forEach(function(element) {
3123
+ element.runSideEffectHandler();
3124
+ });
3125
+ }
3126
+ },
3127
+ {
3128
+ key: "setSideEffectState",
3129
+ value: function setSideEffectState() {
3130
+ var value = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
3131
+ this.isSideEffect = value;
3132
+ }
3133
+ },
3134
+ {
3135
+ key: "getSideEffectState",
3136
+ value: function getSideEffectState() {
3137
+ return this.isSideEffect;
3138
+ }
3139
+ },
3140
+ {
3141
+ key: "setOrigin",
3142
+ value: function setOrigin(param) {
3143
+ var x = param.x, y = param.y, width = param.width, height = param.height;
3144
+ this.xOrigin = x;
3145
+ this.yOrigin = y;
3146
+ this.wOrigin = width;
3147
+ this.hOrigin = height;
3148
+ }
3149
+ },
3150
+ {
3151
+ key: "getOrigin",
3152
+ value: function getOrigin() {
3153
+ return {
3154
+ x: this.xOrigin,
3155
+ y: this.yOrigin,
3156
+ width: this.wOrigin,
3157
+ height: this.hOrigin
3158
+ };
3159
+ }
3160
+ }
3161
+ ]);
3162
+ return TransformOperationExtension;
3163
+ }();
3164
+ // src/utilities/Transform/TransformOperation.ts
3165
+ var TransformOperation = /*#__PURE__*/ function(TransformOperationExtension) {
3166
+ _inherits(TransformOperation, TransformOperationExtension);
3167
+ function TransformOperation() {
3168
+ _class_call_check(this, TransformOperation);
3169
+ var _this;
3170
+ _this = _call_super(this, TransformOperation, arguments);
3171
+ _this.list = [];
3172
+ _this.x = 0;
3173
+ _this.y = 0;
3174
+ _this.angle = 0;
3175
+ _this.width = 0;
3176
+ _this.height = 0;
3177
+ return _this;
3178
+ }
3179
+ _create_class(TransformOperation, [
3180
+ {
3181
+ key: "setPosition",
3182
+ value: function setPosition(position) {
3183
+ this.list.forEach(function(element) {
3184
+ element.setPosition(position);
3185
+ });
3186
+ }
3187
+ },
3188
+ {
3189
+ key: "addEventListener",
3190
+ value: function addEventListener(type, listener, options) {
3191
+ this.list[0].addEventListener(type, listener, options);
3192
+ }
3193
+ },
3194
+ {
3195
+ key: "setDimension",
3196
+ value: function setDimension(param) {
3197
+ var x = param.x, y = param.y, angle = param.angle, width = param.width, height = param.height;
3198
+ this.x = x !== void 0 ? x : this.x;
3199
+ this.y = y !== void 0 ? y : this.y;
3200
+ this.angle = angle !== void 0 ? angle : this.angle;
3201
+ this.width = width !== void 0 ? width : this.width;
3202
+ this.height = height !== void 0 ? height : this.height;
3203
+ this.drag(x, y);
3204
+ this.rotate(angle);
3205
+ this.resize(width, height);
3206
+ }
3207
+ },
3208
+ {
3209
+ key: "getDimension",
3210
+ value: function getDimension() {
3211
+ return {
3212
+ x: this.x,
3213
+ y: this.y,
3214
+ angle: this.angle,
3215
+ width: this.width,
3216
+ height: this.height,
3217
+ ratio: this.width / this.height
3218
+ };
3219
+ }
3220
+ },
3221
+ {
3222
+ /**
3223
+ * Register an HTML Element to the TransformOperation
3224
+ * @param element
3225
+ */ key: "subscribe",
3226
+ value: function subscribe(element) {
3227
+ this.list.push(element);
3228
+ }
3229
+ },
3230
+ {
3231
+ key: "drag",
3232
+ value: function drag(x, y) {
3233
+ this.list.forEach(function(element) {
3234
+ element.drag(x, y);
3235
+ });
3236
+ }
3237
+ },
3238
+ {
3239
+ key: "rotate",
3240
+ value: function rotate(angle) {
3241
+ this.list.forEach(function(element) {
3242
+ element.rotate(angle);
3243
+ });
3244
+ }
3245
+ },
3246
+ {
3247
+ key: "resize",
3248
+ value: function resize(width, height) {
3249
+ this.list.forEach(function(element) {
3250
+ element.resize(width, height);
3251
+ });
3252
+ }
3253
+ }
3254
+ ]);
3255
+ return TransformOperation;
3256
+ }(TransformOperationExtension);
3257
+ var TransformOperation_default = TransformOperation;
3258
+ // src/components/Image/ImageEditor/ImageEditor.tsx
3259
+ var import_jsx_runtime22 = require("react/jsx-runtime");
3260
+ var transformOperation = new TransformOperation_default();
3261
+ var ImageEditor = function(param) {
3262
+ 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;
3263
+ var createTransform = function createTransform() {
3264
+ if (!frame.current || !img.current) return;
3265
+ var transform2 = new Transform({
3266
+ container: container.current,
3267
+ frame: frame.current,
3268
+ img: img.current,
3269
+ controller: controller.current,
3270
+ topLeft: topLeft.current,
3271
+ topRight: topRight.current,
3272
+ bottomLeft: bottomLeft.current,
3273
+ bottomRight: bottomRight.current,
3274
+ rotate: rotate.current,
3275
+ transformOperation: transformOperation
3276
+ });
3277
+ transform2.initialize();
3278
+ if (transformState.current) {
3279
+ transform2.setState(transformState.current);
3280
+ } else {
3281
+ transform2.reset();
3282
+ }
3283
+ setTransform(transform2);
3284
+ };
3285
+ var handleCanvasToSrc = function handleCanvasToSrc() {
3286
+ if (!frame.current || !img.current || !transform) return;
3287
+ var canvas = new Canvas(700, 700);
3288
+ 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;
3289
+ var _transformOperation_getOrigin = transformOperation.getOrigin(), containerWidth = _transformOperation_getOrigin.width, containerHeight = _transformOperation_getOrigin.height;
3290
+ transformState.current = transform.getState();
3291
+ canvas.drawImage({
3292
+ e: img.current,
3293
+ x: x,
3294
+ y: y,
3295
+ angle: angle,
3296
+ width: width,
3297
+ height: height,
3298
+ containerHeight: containerHeight,
3299
+ containerWidth: containerWidth
3300
+ });
3301
+ var _canvas_get = canvas.get(), src2 = _canvas_get.src;
3302
+ return src2;
3303
+ };
3304
+ var handleAccept = function handleAccept() {
3305
+ setSrc(handleCanvasToSrc());
3306
+ setOpen(false);
3307
+ };
3308
+ var handleCancel = function handleCancel() {
3309
+ setOpen(false);
3310
+ };
3311
+ var handleReset = function handleReset() {
3312
+ if (!transform) return;
3313
+ transform.reset();
3314
+ };
3315
+ var handleWindowScroll = function handleWindowScroll(isOpen2) {
3316
+ document.body.style.overflow = isOpen2 ? "hidden" : "auto";
3317
+ };
3318
+ var container = (0, import_react17.useRef)(null);
3319
+ var frame = (0, import_react17.useRef)(null);
3320
+ var img = (0, import_react17.useRef)(null);
3321
+ var controller = (0, import_react17.useRef)(null);
3322
+ var topLeft = (0, import_react17.useRef)(null);
3323
+ var topRight = (0, import_react17.useRef)(null);
3324
+ var bottomLeft = (0, import_react17.useRef)(null);
3325
+ var bottomRight = (0, import_react17.useRef)(null);
3326
+ var rotate = (0, import_react17.useRef)(null);
3327
+ var rotateBottom = (0, import_react17.useRef)(null);
3328
+ var _ref = _sliced_to_array((0, import_react17.useState)(void 0), 2), transform = _ref[0], setTransform = _ref[1];
3329
+ var transformState = (0, import_react17.useRef)(void 0);
3330
+ var originalSrc = (0, import_react17.useMemo)(function() {
3331
+ transformState.current = void 0;
3332
+ return src;
3333
+ }, [
3334
+ isNew
3335
+ ]);
3336
+ (0, import_react17.useEffect)(function() {
3337
+ isOpen ? createTransform() : setTransform(void 0);
3338
+ handleWindowScroll(isOpen);
3339
+ return function() {
3340
+ setTransform(void 0);
3341
+ };
3342
+ }, [
3343
+ isOpen
3344
+ ]);
3345
+ if (!isOpen) return;
3346
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(MyContext3.Provider, {
3347
+ value: {
3348
+ refs: {
3349
+ container: container,
3350
+ frame: frame,
3351
+ controller: controller,
3352
+ topLeft: topLeft,
3353
+ topRight: topRight,
3354
+ bottomLeft: bottomLeft,
3355
+ bottomRight: bottomRight,
3356
+ rotate: rotate,
3357
+ rotateBottom: rotateBottom
3358
+ },
3359
+ imgRefs: {
3360
+ img: img
3361
+ },
3362
+ src: originalSrc,
3363
+ transformOperation: transformOperation
3364
+ },
3365
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", {
3366
+ style: ImageEditor_styles_default.imageEditor,
3367
+ children: [
3368
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Instruction_default, {}),
3369
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(MainElements_default, {}),
3370
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", {
3371
+ style: ImageEditor_styles_default.buttons,
3372
+ children: [
3373
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Button_default, {
3374
+ buttonType: "solid",
3375
+ content: "Accept",
3376
+ onClick: handleAccept
3377
+ }),
3378
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Button_default, {
3379
+ buttonType: "solid",
3380
+ content: "Cancel",
3381
+ onClick: handleCancel
3382
+ }),
3383
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Button_default, {
3384
+ buttonType: "solid",
3385
+ content: "Reset",
3386
+ onClick: handleReset
3387
+ })
3388
+ ]
3389
+ })
3390
+ ]
3391
+ })
3392
+ });
3393
+ };
3394
+ var ImageEditor_default = ImageEditor;
3395
+ // src/utilities/canvas/Canvas.ts
3396
+ var Canvas = /*#__PURE__*/ function() {
3397
+ function Canvas(width, height) {
3398
+ _class_call_check(this, Canvas);
3399
+ this.canvas = document.createElement("canvas");
3400
+ this.canvas.width = width;
3401
+ this.canvas.height = height;
3402
+ this.canvas2DContext = this.canvas.getContext("2d");
3403
+ }
3404
+ _create_class(Canvas, [
3405
+ {
3406
+ key: "get",
3407
+ value: function get() {
3408
+ return {
3409
+ canvas: this.canvas,
3410
+ context: this.canvas2DContext,
3411
+ src: this.src
3412
+ };
3413
+ }
3414
+ },
3415
+ {
3416
+ key: "drawImage",
3417
+ value: function drawImage(param) {
3418
+ 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;
3419
+ var ratioX = this.canvas.width / containerWidth;
3420
+ var ratioY = this.canvas.height / containerHeight;
3421
+ var finalX = x * ratioX;
3422
+ var finalY = y * ratioY;
3423
+ var finalWidth = width * ratioX;
3424
+ var finalHeight = height * ratioY;
3425
+ var angleRadians = angle * Math.PI / 180;
3426
+ var reverse_p = LinearAlgebra_default.rotateVector([
3427
+ finalX,
3428
+ finalY,
3429
+ 1
3430
+ ], -angleRadians);
3431
+ var reverse_q = LinearAlgebra_default.rotateVector([
3432
+ finalX + finalWidth,
3433
+ finalY + finalHeight,
3434
+ 1
3435
+ ], -angleRadians);
3436
+ var reverse_p_prime = LinearAlgebra_default.NicolasMattia(reverse_p, LinearAlgebra_default.getMiddleVectorFrom(reverse_p, reverse_q), angleRadians);
3437
+ this.canvas2DContext.save();
3438
+ this.canvas2DContext.rotate(angleRadians);
3439
+ this.canvas2DContext.drawImage(e, reverse_p_prime[0], reverse_p_prime[1], finalWidth, finalHeight);
3440
+ this.src = this.canvas2DContext.canvas.toDataURL();
3441
+ this.canvas2DContext.restore();
3442
+ }
3443
+ },
3444
+ {
3445
+ key: "drawColor",
3446
+ value: function drawColor(type, color, width, ratio) {
3447
+ if (type === "") color = "#ffffff";
3448
+ if (type === "gradient") {
3449
+ var breakdownArr = color.split(",");
3450
+ var _ref = [
3451
+ Number(breakdownArr[0]),
3452
+ breakdownArr[1],
3453
+ Number(breakdownArr[2]),
3454
+ breakdownArr[3],
3455
+ Number(breakdownArr[4])
3456
+ ], angle = _ref[0], color1 = _ref[1], percent1 = _ref[2], color2 = _ref[3], percent2 = _ref[4];
3457
+ var radians = (angle - 180) * Math.PI / 180;
3458
+ var x0 = width / 2 + width / 2 * Math.cos(radians - Math.PI / 2);
3459
+ var y0 = width * ratio / 2 + width * ratio / 2 * Math.sin(radians - Math.PI / 2);
3460
+ var x1 = width / 2 - width / 2 * Math.cos(radians - Math.PI / 2);
3461
+ var y1 = width * ratio / 2 - width * ratio / 2 * Math.sin(radians - Math.PI / 2);
3462
+ var gradient = this.canvas2DContext.createLinearGradient(x0, y0, x1, y1);
3463
+ gradient.addColorStop(percent1 / 100, color1);
3464
+ gradient.addColorStop(percent2 / 100, color2);
3465
+ this.canvas2DContext.fillStyle = gradient;
3466
+ this.canvas2DContext.fillRect(0, 0, width, width * ratio);
3467
+ this.src = this.canvas2DContext.canvas.toDataURL();
3468
+ } else {
3469
+ this.canvas2DContext.fillStyle = color;
3470
+ this.canvas2DContext.fillRect(0, 0, this.canvas2DContext.canvas.width, this.canvas2DContext.canvas.height);
3471
+ this.src = this.canvas2DContext.canvas.toDataURL();
3472
+ }
3473
+ }
3474
+ }
3475
+ ]);
3476
+ return Canvas;
3477
+ }();
3478
+ // src/utilities/canvas/Image.ts
3479
+ var Image2 = {
3480
+ /**
3481
+ * Convert file (blob) to base64 string format
3482
+ * @param file
3483
+ * @returns
3484
+ */ FromFileToImageSrc: function FromFileToImageSrc(file) {
3485
+ return new Promise(function(resolve, reject) {
3486
+ if (!file) return resolve(null);
3487
+ var reader = new FileReader();
3488
+ reader.readAsDataURL(file);
3489
+ reader.onload = function(readerEvent) {
3490
+ var _readerEvent_target;
3491
+ if ((_readerEvent_target = readerEvent.target) === null || _readerEvent_target === void 0 ? void 0 : _readerEvent_target.result) {
3492
+ var _readerEvent_target1;
3493
+ return resolve((_readerEvent_target1 = readerEvent.target) === null || _readerEvent_target1 === void 0 ? void 0 : _readerEvent_target1.result);
3494
+ }
3495
+ reject("Error getting the image source");
3496
+ };
3497
+ reader.onerror = function() {
3498
+ reject("Error getting the image source");
3499
+ };
3500
+ });
3501
+ },
3502
+ FromStringToImageSrc: /**
3503
+ * Take a url, look for the corresponding image file, and convert it to base64 format
3504
+ * @param url
2514
3505
  * @returns
2515
3506
  */ function FromStringToImageSrc(url) {
2516
3507
  return _async_to_generator(function() {
@@ -2561,464 +3552,185 @@ var Image2 = {
2561
3552
  }
2562
3553
  };
2563
3554
  var Image_default2 = Image2;
2564
- // src/utilities/Transform/Transform.ts
2565
- var import_jquery2 = __toESM(require("jquery"));
2566
- // src/utilities/Transform/TransformController.ts
2567
- var import_jquery = __toESM(require("jquery"));
2568
- var import_fontawesome_svg_core = require("@fortawesome/fontawesome-svg-core");
2569
- var import_free_solid_svg_icons = require("@fortawesome/free-solid-svg-icons");
2570
- var TransformController = /*#__PURE__*/ function() {
2571
- function TransformController(wrapper, frame, controller) {
2572
- _class_call_check(this, TransformController);
2573
- this.wrapper = wrapper;
2574
- this.frame = frame;
2575
- this.controller = controller;
3555
+ // src/utilities/Transform/WElement.ts
3556
+ var WElement = /*#__PURE__*/ function() {
3557
+ function WElement(element, sideEffectCallback) {
3558
+ _class_call_check(this, WElement);
3559
+ this.element = element;
3560
+ this.sideEffectCallback = sideEffectCallback;
2576
3561
  }
2577
- _create_class(TransformController, [
3562
+ _create_class(WElement, [
2578
3563
  {
2579
- key: "addController",
2580
- value: function addController() {
2581
- var _this = this;
2582
- return new Promise(function(res) {
2583
- var styleElement = document.createElement("style");
2584
- styleElement.textContent = _this.css();
2585
- document.head.appendChild(styleElement);
2586
- (0, import_jquery.default)("." + _this.frame).after(_this.controllerTemplate());
2587
- res();
2588
- });
3564
+ key: "runSideEffectHandler",
3565
+ value: function runSideEffectHandler() {
3566
+ if (!this.sideEffectCallback) return;
3567
+ this.sideEffectCallback(this.element);
2589
3568
  }
2590
3569
  },
2591
3570
  {
2592
- key: "css",
2593
- value: function css() {
2594
- 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 ");
3571
+ key: "addEventListener",
3572
+ value: function addEventListener(type, listener, options) {
3573
+ this.element.addEventListener(type, listener, options);
2595
3574
  }
2596
3575
  },
2597
3576
  {
2598
- key: "controllerTemplate",
2599
- value: function controllerTemplate() {
2600
- 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((0, import_fontawesome_svg_core.icon)(import_free_solid_svg_icons.faRotate).html[0], '</div>\n <div class="dot rotate shadow" style="visibility: hidden;">').concat((0, import_fontawesome_svg_core.icon)(import_free_solid_svg_icons.faRotate).html[0], '</div>\n <div class="dot delete">').concat((0, import_fontawesome_svg_core.icon)(import_free_solid_svg_icons.faTrash).html[0], '</div>\n <div class="dot delete shadow" style="visibility: hidden;">').concat((0, import_fontawesome_svg_core.icon)(import_free_solid_svg_icons.faTrash).html[0], "</div>\n </div>\n </div>\n ");
3577
+ key: "drag",
3578
+ value: function drag(x, y) {
3579
+ this.element.style.left = x !== void 0 ? (x - this.element.clientLeft).toString() + "px" : this.element.style.left;
3580
+ this.element.style.top = y !== void 0 ? (y - this.element.clientTop).toString() + "px" : this.element.style.top;
2601
3581
  }
2602
- }
2603
- ]);
2604
- return TransformController;
2605
- }();
2606
- // src/utilities/Transform/Transform.ts
2607
- var Transform = /*#__PURE__*/ function() {
2608
- function Transform(ele1, ele2, ele3) {
2609
- _class_call_check(this, Transform);
2610
- this.ele1 = ele1;
2611
- this.ele2 = ele2;
2612
- this.x = 0;
2613
- this.y = 0;
2614
- this.angle = 90;
2615
- this.w = 0;
2616
- this.h = 0;
2617
- if (this.ele1 === null) {
2618
- throw new Error("wrapper elemenet is not defined or not rendered yet");
2619
- }
2620
- this.wrapperClass = "_" + (Date.now() + 5e3).toString();
2621
- (0, import_jquery2.default)(this.ele1).addClass(this.wrapperClass);
2622
- this.imgFrame = this.ele2;
2623
- if (this.imgFrame === null) {
2624
- throw new Error("frame element is not defined or not rendered yet");
2625
- }
2626
- this.frameClass = "_" + (Date.now() - 5e3).toString();
2627
- (0, import_jquery2.default)(this.ele2).addClass(this.frameClass);
2628
- this.img = this.ele1.querySelector("img");
2629
- if (this.img === null) {
2630
- throw new Error("image element is not defined or not rendered yet");
2631
- }
2632
- this.ratio = this.img.clientWidth / this.img.clientHeight;
2633
- this.controllerClassName = "_" + Date.now().toString();
2634
- this.isRotateOffScreen = false;
2635
- }
2636
- _create_class(Transform, [
3582
+ },
2637
3583
  {
2638
- key: "initialize",
2639
- value: function initialize() {
2640
- return _async_to_generator(function() {
2641
- var transformController;
2642
- return _ts_generator(this, function(_state) {
2643
- switch(_state.label){
2644
- case 0:
2645
- transformController = new TransformController(this.wrapperClass, this.frameClass, this.controllerClassName);
2646
- return [
2647
- 4,
2648
- transformController.addController()
2649
- ];
2650
- case 1:
2651
- _state.sent();
2652
- this.controllerContainer = document.querySelector("." + this.controllerClassName + "--container");
2653
- this.controller = document.querySelector("." + this.controllerClassName);
2654
- this.handleElementGoOffScreen("." + this.controllerClassName + " .rotate", "." + this.controllerClassName + " .rotate.shadow", "rotate").handleElementGoOffScreen("." + this.controllerClassName + " .delete", "." + this.controllerClassName + " .delete.shadow", "delete").transform();
2655
- return [
2656
- 2
2657
- ];
2658
- }
2659
- });
2660
- }).call(this);
3584
+ key: "rotate",
3585
+ value: function rotate(angle) {
3586
+ this.element.style.rotate = angle !== void 0 ? angle + "deg" : this.element.style.rotate;
2661
3587
  }
2662
3588
  },
2663
3589
  {
2664
- key: "reset",
2665
- value: function reset() {
2666
- this.setState({
2667
- x: 0,
2668
- y: this.imgFrame.clientHeight / 2 - this.img.height / 2,
2669
- angle: 0,
2670
- w: this.imgFrame.clientWidth
2671
- });
3590
+ key: "resize",
3591
+ value: function resize(width, height) {
3592
+ this.element.style.width = width !== void 0 ? width + "px" : this.element.style.width;
3593
+ this.element.style.height = height !== void 0 ? height + "px" : this.element.style.height;
2672
3594
  }
2673
3595
  },
2674
3596
  {
2675
- key: "setState",
2676
- value: function setState(param) {
2677
- var x = param.x, y = param.y, angle = param.angle, w = param.w;
2678
- this.repositionElement(x + this.imgFrame.clientWidth / 2, y + this.img.height / 2);
2679
- this.rotateBox(angle);
2680
- this.resize(w, w / this.ratio);
2681
- this.setValue(x, y, angle, w, w / this.ratio);
3597
+ key: "setPosition",
3598
+ value: function setPosition(position) {
3599
+ this.element.style.setProperty("position", position, "important");
2682
3600
  }
2683
3601
  },
2684
3602
  {
2685
- key: "setValue",
2686
- value: function setValue(x, y, angle, w, h) {
2687
- this.x = x !== void 0 ? x : this.x;
2688
- this.y = y !== void 0 ? y : this.y;
2689
- this.angle = angle !== void 0 ? angle : this.angle;
2690
- this.w = w !== void 0 ? w : this.w;
2691
- this.h = h !== void 0 ? h : this.h;
3603
+ key: "setDimension",
3604
+ value: function setDimension(param) {
3605
+ var x = param.x, y = param.y, angle = param.angle, width = param.width, height = param.height;
3606
+ this.drag(x, y);
3607
+ this.rotate(angle);
3608
+ this.resize(width, height);
2692
3609
  }
2693
3610
  },
2694
3611
  {
2695
- key: "exportData",
2696
- value: function exportData() {
3612
+ key: "getDimension",
3613
+ value: function getDimension() {
2697
3614
  return {
2698
- x: this.x,
2699
- y: this.y,
2700
- angle: this.angle,
2701
- w: this.w,
2702
- h: this.h
3615
+ x: this.element.offsetLeft,
3616
+ y: this.element.offsetTop,
3617
+ angle: this.getCurrentRotation(),
3618
+ width: this.element.clientWidth,
3619
+ height: this.element.clientHeight,
3620
+ ratio: this.element.clientWidth / this.element.clientHeight
2703
3621
  };
2704
3622
  }
2705
3623
  },
2706
3624
  {
2707
- key: "repositionElement",
2708
- value: function repositionElement(x, y) {
2709
- var controllerWrapper = this.controllerContainer;
2710
- var boxWrapper = this.ele1;
2711
- boxWrapper.style.left = x + "px";
2712
- boxWrapper.style.top = y + "px";
2713
- controllerWrapper.style.left = x + this.imgFrame.offsetLeft + 3 + "px";
2714
- controllerWrapper.style.top = y + this.imgFrame.offsetTop + 3 + "px";
3625
+ /**
3626
+ * Get current angle of current element in degrees
3627
+ * @returns angle in degrees
3628
+ */ key: "getCurrentRotation",
3629
+ value: function getCurrentRotation() {
3630
+ if (!this.element) return 0;
3631
+ var st = window.getComputedStyle(this.element, null);
3632
+ var tm = st.getPropertyValue("-webkit-transform") || st.getPropertyValue("-moz-transform") || st.getPropertyValue("-ms-transform") || st.getPropertyValue("-o-transform") || st.getPropertyValue("transform");
3633
+ "none";
3634
+ if (tm != "none") {
3635
+ var values = tm.split("(")[1].split(")")[0].split(",");
3636
+ var angle = Math.round(Math.atan2(Number(values[1]), Number(values[0])) * (180 / Math.PI));
3637
+ return angle < 0 ? angle + 360 : angle;
3638
+ }
3639
+ return 0;
2715
3640
  }
2716
- },
3641
+ }
3642
+ ]);
3643
+ return WElement;
3644
+ }();
3645
+ var WElement_default = WElement;
3646
+ // src/utilities/Transform/Transform.ts
3647
+ var Transform = /*#__PURE__*/ function() {
3648
+ function Transform(param) {
3649
+ 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;
3650
+ _class_call_check(this, Transform);
3651
+ this.frame = new WElement_default(frame);
3652
+ this.img = new WElement_default(img);
3653
+ this.container = new WElement_default(container);
3654
+ this.controller = new WElement_default(controller);
3655
+ this.topLeft = new WElement_default(topLeft);
3656
+ this.topRight = new WElement_default(topRight);
3657
+ this.bottomLeft = new WElement_default(bottomLeft);
3658
+ this.bottomRight = new WElement_default(bottomRight);
3659
+ this.rotate = new WElement_default(rotate, function(element) {
3660
+ var rotateBottom = element.nextElementSibling;
3661
+ var callback = function(entries) {
3662
+ entries.forEach(function(entry) {
3663
+ if (!entry.isIntersecting) {
3664
+ element.style.visibility = "hidden";
3665
+ rotateBottom.style.display = "flex";
3666
+ } else {
3667
+ element.style.visibility = "visible";
3668
+ rotateBottom.style.display = "none";
3669
+ }
3670
+ });
3671
+ };
3672
+ var observer = new IntersectionObserver(callback, {
3673
+ root: null,
3674
+ rootMargin: "0px",
3675
+ threshold: 0.1
3676
+ });
3677
+ observer.observe(element);
3678
+ });
3679
+ this.transformOperation = transformOperation2;
3680
+ }
3681
+ _create_class(Transform, [
2717
3682
  {
2718
- key: "resize",
2719
- value: function resize(w, h) {
2720
- var controller = this.controller;
2721
- var img = this.img;
2722
- var wrapper = this.ele1;
2723
- controller.style.width = w + "px";
2724
- controller.style.height = h + "px";
2725
- img.style.width = w + "px";
2726
- wrapper.style.width = w + "px";
3683
+ key: "initialize",
3684
+ value: function initialize() {
3685
+ this.container.setPosition("relative");
3686
+ this.controller.setPosition("absolute");
3687
+ this.frame.setPosition("relative");
3688
+ this.img.setPosition("absolute");
3689
+ 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;
3690
+ this.transformOperation.setOrigin({
3691
+ x: x,
3692
+ y: y,
3693
+ width: width,
3694
+ height: height
3695
+ });
3696
+ this.transformOperation.subscribe(this.controller);
3697
+ this.transformOperation.subscribe(this.img);
3698
+ this.transformOperation.subscribeSideEffect(this.rotate);
3699
+ this.transformOperation.runSideEffectHandler();
3700
+ return this;
2727
3701
  }
2728
3702
  },
2729
3703
  {
2730
- key: "rotateBox",
2731
- value: function rotateBox(deg) {
2732
- var controllerWrapper = this.controllerContainer;
2733
- var boxWrapper = this.ele1;
2734
- boxWrapper.style.transform = "rotate(".concat(deg, "deg)");
2735
- controllerWrapper.style.rotate = "".concat(deg, "deg");
3704
+ key: "setState",
3705
+ value: function setState(param) {
3706
+ var x = param.x, y = param.y, angle = param.angle, width = param.width, height = param.height;
3707
+ this.transformOperation.setDimension({
3708
+ x: x,
3709
+ y: y,
3710
+ angle: angle,
3711
+ width: width,
3712
+ height: height
3713
+ });
2736
3714
  }
2737
3715
  },
2738
3716
  {
2739
- key: "handleElementGoOffScreen",
2740
- value: function handleElementGoOffScreen(main, shadow, type) {
2741
- var _this = this;
2742
- var mainEle = document.querySelector(main);
2743
- var shadowEle = document.querySelector(shadow);
2744
- var options = {
2745
- root: null,
2746
- rootMargin: "0px",
2747
- threshold: 0.1
2748
- };
2749
- var callback = function(entries) {
2750
- entries.forEach(function(entry) {
2751
- switch(type){
2752
- case "rotate":
2753
- if (!entry.isIntersecting) {
2754
- mainEle.style.top = "auto";
2755
- mainEle.style.bottom = "-50px";
2756
- _this.isRotateOffScreen = true;
2757
- } else {
2758
- mainEle.style.bottom = "auto";
2759
- mainEle.style.top = "-50px";
2760
- _this.isRotateOffScreen = false;
2761
- }
2762
- break;
2763
- case "delete":
2764
- if (!entry.isIntersecting) {
2765
- mainEle.style.bottom = "auto";
2766
- mainEle.style.top = "-50px";
2767
- } else {
2768
- mainEle.style.top = "auto";
2769
- mainEle.style.bottom = "-50px";
2770
- }
2771
- break;
2772
- }
2773
- });
2774
- };
2775
- var observer = new IntersectionObserver(callback, options);
2776
- observer.observe(shadowEle);
2777
- return this;
3717
+ key: "getState",
3718
+ value: function getState() {
3719
+ return this.transformOperation.getDimension();
2778
3720
  }
2779
3721
  },
2780
3722
  {
2781
- key: "transform",
2782
- value: function transform() {
2783
- var _this = this;
2784
- var _this1 = this;
2785
- var controllerWrapper = this.controllerContainer;
2786
- var boxWrapper = this.ele1;
2787
- var minWidth = 40;
2788
- var minHeight = 40;
2789
- var initX, initY, mousePressX, mousePressY, initW, initH, initRotate;
2790
- function getCurrentRotation(el) {
2791
- var st = window.getComputedStyle(el, null);
2792
- var tm = st.getPropertyValue("-webkit-transform") || st.getPropertyValue("-moz-transform") || st.getPropertyValue("-ms-transform") || st.getPropertyValue("-o-transform") || st.getPropertyValue("transform");
2793
- "none";
2794
- if (tm != "none") {
2795
- var values = tm.split("(")[1].split(")")[0].split(",");
2796
- var angle = Math.round(Math.atan2(Number(values[1]), Number(values[0])) * (180 / Math.PI));
2797
- return angle < 0 ? angle + 360 : angle;
2798
- }
2799
- return 0;
2800
- }
2801
- function mousedownCb(event) {
2802
- event.target.classList.add("show");
2803
- event.target.querySelector(".circle").classList.add("show");
2804
- }
2805
- function mouseupCb(event) {
2806
- event.target.classList.remove("show");
2807
- event.target.querySelector(".circle").classList.remove("show");
2808
- }
2809
- var handleDrag = function(event, type) {
2810
- event.stopPropagation();
2811
- var initX2 = boxWrapper.offsetLeft;
2812
- var initY2 = boxWrapper.offsetTop;
2813
- var mousePressX2 = type === "desk" ? event.clientX : event.touches[0].clientX;
2814
- var mousePressY2 = type === "desk" ? event.clientY : event.touches[0].clientY;
2815
- var _this_exportData = _this.exportData(), w = _this_exportData.w, h = _this_exportData.h;
2816
- var eventMoveHandler = function(event2) {
2817
- var x = type === "desk" ? event2.clientX : event2.touches[0].clientX;
2818
- var y = type === "desk" ? event2.clientY : event2.touches[0].clientY;
2819
- var posX = initX2 + (x - mousePressX2);
2820
- var posY = initY2 + (y - mousePressY2);
2821
- _this.repositionElement(posX, posY);
2822
- _this.setValue(posX - w / 2, posY - h / 2, void 0, void 0, void 0);
2823
- };
2824
- if (type === "desk") {
2825
- controllerWrapper.addEventListener("mousemove", eventMoveHandler, false);
2826
- window.addEventListener("mouseup", function eventEndHandler() {
2827
- controllerWrapper.removeEventListener("mousemove", eventMoveHandler, false);
2828
- window.removeEventListener("mouseup", eventEndHandler);
2829
- }, false);
2830
- } else {
2831
- controllerWrapper.addEventListener("touchmove", eventMoveHandler, {
2832
- passive: true
2833
- });
2834
- window.addEventListener("touchend", function eventEndHandler() {
2835
- controllerWrapper.removeEventListener("touchmove", eventMoveHandler);
2836
- window.removeEventListener("touchend", eventEndHandler);
2837
- }, false);
2838
- }
2839
- };
2840
- controllerWrapper.addEventListener("mousedown", function(e) {
2841
- return handleDrag(e, "desk");
2842
- }, false);
2843
- controllerWrapper.addEventListener("touchstart", function(e) {
2844
- return handleDrag(e, "touch");
2845
- }, {
2846
- passive: true
2847
- });
2848
- var leftTop = document.querySelector("." + this.controllerClassName + " .resize-topleft");
2849
- var rightTop = document.querySelector("." + this.controllerClassName + " .resize-topright");
2850
- var rightBottom = document.querySelector("." + this.controllerClassName + " .resize-bottomright");
2851
- var leftBottom = document.querySelector("." + this.controllerClassName + " .resize-bottomleft");
2852
- var resizeHandler = function(event) {
2853
- 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;
2854
- event.stopPropagation();
2855
- initX = boxWrapper.offsetLeft;
2856
- initY = boxWrapper.offsetTop;
2857
- mousePressX = type === "desk" ? event.clientX : event.touches[0].clientX;
2858
- mousePressY = type === "desk" ? event.clientY : event.touches[0].clientY;
2859
- initW = _this1.img.offsetWidth;
2860
- initH = _this1.img.offsetHeight;
2861
- initRotate = getCurrentRotation(boxWrapper);
2862
- var initRadians = initRotate * Math.PI / 180;
2863
- var cosFraction = Math.cos(initRadians);
2864
- var sinFraction = Math.sin(initRadians);
2865
- mousedownCb(event);
2866
- var vectorC = [
2867
- mousePressX - initX - _this1.imgFrame.offsetLeft,
2868
- mousePressY - initY - _this1.imgFrame.offsetTop
2869
- ];
2870
- var eventMoveHandler = function(event2) {
2871
- var x = type === "desk" ? event2.clientX : event2.touches[0].clientX;
2872
- var y = type === "desk" ? event2.clientY : event2.touches[0].clientY;
2873
- var wDiff = x - mousePressX;
2874
- var hDiff = y - mousePressY;
2875
- var vectorD = [
2876
- wDiff,
2877
- hDiff
2878
- ];
2879
- var c = (vectorC[0] * vectorD[0] + vectorC[1] * vectorD[1]) / (vectorC[0] * vectorC[0] + vectorC[1] * vectorC[1]);
2880
- var vectorH = [
2881
- c * vectorC[0],
2882
- c * vectorC[1]
2883
- ];
2884
- var rotatedWDiff = cosFraction * vectorH[0] + sinFraction * vectorH[1];
2885
- var rotatedHDiff = cosFraction * vectorH[1] - sinFraction * vectorH[0];
2886
- rotatedHDiff = rotatedHDiff * rotatedWDiff > 0 ? rotatedWDiff / _this1.ratio : -rotatedWDiff / _this1.ratio;
2887
- var newW = initW, newH = initH, newX = initX, newY = initY;
2888
- if (xResize) {
2889
- if (left) {
2890
- newW = initW - rotatedWDiff;
2891
- if (newW < minWidth) {
2892
- newW = minWidth;
2893
- rotatedWDiff = initW - minWidth;
2894
- }
2895
- } else {
2896
- newW = initW + rotatedWDiff;
2897
- if (newW < minWidth) {
2898
- newW = minWidth;
2899
- rotatedWDiff = minWidth - initW;
2900
- }
2901
- }
2902
- newX += 0.5 * rotatedWDiff * cosFraction;
2903
- newY += 0.5 * rotatedWDiff * sinFraction;
2904
- }
2905
- if (yResize) {
2906
- if (top) {
2907
- newH = initH - rotatedHDiff;
2908
- if (newH < minHeight) {
2909
- newH = minHeight;
2910
- rotatedHDiff = initH - minHeight;
2911
- }
2912
- } else {
2913
- newH = initH + rotatedHDiff;
2914
- if (newH < minHeight) {
2915
- newH = minHeight;
2916
- rotatedHDiff = minHeight - initH;
2917
- }
2918
- }
2919
- newX -= 0.5 * rotatedHDiff * sinFraction;
2920
- newY += 0.5 * rotatedHDiff * cosFraction;
2921
- }
2922
- _this1.resize(newW, newH);
2923
- _this1.repositionElement(newX, newY);
2924
- _this1.setValue(newX - newW / 2, newY - newH / 2, void 0, newW, newH);
2925
- };
2926
- if (type === "desk") {
2927
- window.addEventListener("mousemove", eventMoveHandler, false);
2928
- window.addEventListener("mouseup", function eventEndHandler() {
2929
- mouseupCb(event);
2930
- window.removeEventListener("mousemove", eventMoveHandler, false);
2931
- window.removeEventListener("mouseup", eventEndHandler);
2932
- }, false);
2933
- } else {
2934
- window.addEventListener("touchmove", eventMoveHandler, {
2935
- passive: true
2936
- });
2937
- window.addEventListener("touchend", function eventEndHandler() {
2938
- mouseupCb(event);
2939
- window.removeEventListener("touchmove", eventMoveHandler, false);
2940
- window.removeEventListener("touchend", eventEndHandler);
2941
- }, false);
2942
- }
2943
- };
2944
- leftTop.addEventListener("mousedown", function(e) {
2945
- return resizeHandler(e, true, true, true, true, "desk");
2946
- });
2947
- rightTop.addEventListener("mousedown", function(e) {
2948
- return resizeHandler(e, false, true, true, true, "desk");
2949
- });
2950
- rightBottom.addEventListener("mousedown", function(e) {
2951
- return resizeHandler(e, false, false, true, true, "desk");
2952
- });
2953
- leftBottom.addEventListener("mousedown", function(e) {
2954
- return resizeHandler(e, true, false, true, true, "desk");
2955
- });
2956
- leftTop.addEventListener("touchstart", function(e) {
2957
- return resizeHandler(e, true, true, true, true, "touch");
2958
- }, {
2959
- passive: true
2960
- });
2961
- rightTop.addEventListener("touchstart", function(e) {
2962
- return resizeHandler(e, false, true, true, true, "touch");
2963
- }, {
2964
- passive: true
2965
- });
2966
- rightBottom.addEventListener("touchstart", function(e) {
2967
- return resizeHandler(e, false, false, true, true, "touch");
2968
- }, {
2969
- passive: true
2970
- });
2971
- leftBottom.addEventListener("touchstart", function(e) {
2972
- return resizeHandler(e, true, false, true, true, "touch");
2973
- }, {
2974
- passive: true
2975
- });
2976
- var rotate = document.querySelector("." + this.controllerClassName + " .rotate");
2977
- var handleRotate = function(event, type) {
2978
- event.stopPropagation();
2979
- initX = event.target.offsetLeft;
2980
- initY = event.target.offsetTop;
2981
- mousePressX = type === "desk" ? event.clientX : event.touches[0].clientX;
2982
- mousePressY = type === "desk" ? event.clientY : event.touches[0].clientY;
2983
- var arrow = _this.controller;
2984
- var arrowRects = arrow.getBoundingClientRect();
2985
- var arrowX = arrowRects.left + arrowRects.width / 2;
2986
- var arrowY = arrowRects.top + arrowRects.height / 2;
2987
- var compensation = _this.isRotateOffScreen ? 180 : 0;
2988
- var eventMoveHandler = function(event2) {
2989
- var x = type === "desk" ? event2.clientX : event2.touches[0].clientX;
2990
- var y = type === "desk" ? event2.clientY : event2.touches[0].clientY;
2991
- var angle = Math.atan2(y - arrowY, x - arrowX) + Math.PI / 2;
2992
- angle *= 180 / Math.PI;
2993
- angle += compensation;
2994
- _this.rotateBox(angle);
2995
- _this.setValue(void 0, void 0, angle, void 0, void 0);
2996
- };
2997
- if (type === "desk") {
2998
- window.addEventListener("mousemove", eventMoveHandler, false);
2999
- window.addEventListener("mouseup", function eventEndHandler() {
3000
- window.removeEventListener("mousemove", eventMoveHandler, false);
3001
- window.removeEventListener("mouseup", eventEndHandler);
3002
- }, false);
3003
- } else {
3004
- window.addEventListener("touchmove", eventMoveHandler, {
3005
- passive: true
3006
- });
3007
- window.addEventListener("touchend", function eventEndHandler() {
3008
- window.removeEventListener("touchmove", eventMoveHandler, false);
3009
- window.removeEventListener("touchend", eventEndHandler);
3010
- }, false);
3011
- }
3012
- };
3013
- rotate.addEventListener("mousedown", function(e) {
3014
- return handleRotate(e, "desk");
3015
- }, false);
3016
- rotate.addEventListener("touchstart", function(e) {
3017
- return handleRotate(e, "touch");
3018
- }, {
3019
- passive: true
3723
+ key: "reset",
3724
+ value: function reset() {
3725
+ var width = this.frame.getDimension().width;
3726
+ var ratio = this.img.getDimension().ratio;
3727
+ this.transformOperation.setDimension({
3728
+ x: 0,
3729
+ y: width / 2 - width / ratio / 2,
3730
+ angle: 0,
3731
+ width: width,
3732
+ height: width / ratio
3020
3733
  });
3021
- this.reset();
3022
3734
  return this;
3023
3735
  }
3024
3736
  }
@@ -3075,29 +3787,29 @@ var tools = {
3075
3787
  };
3076
3788
  var tools_default = tools;
3077
3789
  // src/auth/react/context.tsx
3078
- var import_react15 = require("react");
3079
- var SessionContext = (0, import_react15.createContext)(void 0);
3790
+ var import_react18 = require("react");
3791
+ var SessionContext = (0, import_react18.createContext)(void 0);
3080
3792
  function useSession() {
3081
- var data = (0, import_react15.useContext)(SessionContext);
3793
+ var data = (0, import_react18.useContext)(SessionContext);
3082
3794
  if (data === void 0) throw new Error("Session context is undefined");
3083
3795
  return data;
3084
3796
  }
3085
3797
  // src/auth/react/SessionProvider.tsx
3086
- var import_jsx_runtime20 = require("react/jsx-runtime");
3798
+ var import_jsx_runtime23 = require("react/jsx-runtime");
3087
3799
  var SessionProvider = function(param) {
3088
3800
  var value = param.value, children = param.children;
3089
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SessionContext.Provider, {
3801
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(SessionContext.Provider, {
3090
3802
  value: value,
3091
3803
  children: children
3092
3804
  });
3093
3805
  };
3094
3806
  var SessionProvider_default = SessionProvider;
3095
3807
  // src/auth/react/useAuthClient.ts
3096
- var import_react16 = require("react");
3808
+ var import_react19 = require("react");
3097
3809
  var useAuthClient = function(auth) {
3098
- var _ref = _sliced_to_array((0, import_react16.useState)(false), 2), isLoading = _ref[0], setLoading = _ref[1];
3099
- var sessionRef = (0, import_react16.useRef)(void 0);
3100
- (0, import_react16.useEffect)(function() {
3810
+ var _ref = _sliced_to_array((0, import_react19.useState)(false), 2), isLoading = _ref[0], setLoading = _ref[1];
3811
+ var sessionRef = (0, import_react19.useRef)(void 0);
3812
+ (0, import_react19.useEffect)(function() {
3101
3813
  var is = true;
3102
3814
  var getSession = function() {
3103
3815
  return _async_to_generator(function() {
@@ -3138,6 +3850,129 @@ var useAuthClient = function(auth) {
3138
3850
  };
3139
3851
  };
3140
3852
  var useAuthClient_default = useAuthClient;
3853
+ // src/utilities/math/LinearAlgebra.ts
3854
+ var LinearAlgebra = {
3855
+ /**
3856
+ * Translate a point by a vector
3857
+ * @param vector coordinates of a point
3858
+ * @param translateVector vector for translation
3859
+ * @throws Exception if the vector is not in 3 dimension
3860
+ */ translateVector: function translateVector(vector, translateVector) {
3861
+ if (vector.length !== 3) {
3862
+ throw new Error("Vector must be 3 dimension");
3863
+ }
3864
+ return [
3865
+ vector[0] + translateVector[0],
3866
+ vector[1] + translateVector[1],
3867
+ 1
3868
+ ];
3869
+ },
3870
+ /**
3871
+ * Rotate a vector by an angle in radian
3872
+ * @param vector
3873
+ * @param angle
3874
+ * @throws Exception if the vector is not in 3 dimension
3875
+ */ rotateVector: function rotateVector(vector, angle) {
3876
+ if (vector.length !== 3) {
3877
+ throw new Error("Vector must be 3 dimension");
3878
+ }
3879
+ return [
3880
+ vector[0] * Math.cos(angle) - vector[1] * Math.sin(angle),
3881
+ vector[0] * Math.sin(angle) + vector[1] * Math.cos(angle),
3882
+ 1
3883
+ ];
3884
+ },
3885
+ /**
3886
+ * Get opposite vector
3887
+ * @param vector
3888
+ */ getOppositeVector: function getOppositeVector(vector) {
3889
+ return [
3890
+ -1 * vector[0],
3891
+ -1 * vector[1],
3892
+ 1
3893
+ ];
3894
+ },
3895
+ /**
3896
+ * Nicolas Mattia formula
3897
+ * @param vector
3898
+ * @param translate
3899
+ * @param angle
3900
+ * @throws Exception if the vector is not in 3 dimension
3901
+ *
3902
+ * @link https://nmattia.com/posts/2020-03-03-drag-resize-rotate/
3903
+ */ NicolasMattia: function NicolasMattia(vector, translate, angle) {
3904
+ if (vector.length !== 3) {
3905
+ throw new Error("Vector must be 3 dimension");
3906
+ }
3907
+ var c = LinearAlgebra.translateVector(vector, LinearAlgebra.getOppositeVector(translate));
3908
+ var r = LinearAlgebra.rotateVector(c, angle);
3909
+ return LinearAlgebra.translateVector(r, translate);
3910
+ },
3911
+ /**
3912
+ * Set coofficient for a vector
3913
+ * @param coefficient
3914
+ * @param vector
3915
+ * @throws Exception if the vector is not in 3 dimension
3916
+ */ setCoefficient: function setCoefficient(coefficient, vector) {
3917
+ if (vector.length !== 3) {
3918
+ throw new Error("Vector must be 3 dimension");
3919
+ }
3920
+ return [
3921
+ coefficient * vector[0],
3922
+ coefficient * vector[1],
3923
+ 1
3924
+ ];
3925
+ },
3926
+ /**
3927
+ * Plus 2 vectors
3928
+ * @param vector1
3929
+ * @param vector2
3930
+ * @throws Exception if the vector is not in 3 dimension
3931
+ */ plusVectors: function plusVectors(vector1, vector2) {
3932
+ if (vector1.length !== 3 || vector2.length !== 3) {
3933
+ throw new Error("Vector must be 3 dimension");
3934
+ }
3935
+ return [
3936
+ vector1[0] + vector2[0],
3937
+ vector1[1] + vector2[1],
3938
+ 1
3939
+ ];
3940
+ },
3941
+ /**
3942
+ * Get middle vector from 2 vectors
3943
+ * @param vector1
3944
+ * @param vector2
3945
+ * @throws Exception if the vector is not in 3 dimension
3946
+ */ getMiddleVectorFrom: function getMiddleVectorFrom(vector1, vector2) {
3947
+ if (vector1.length !== 3 || vector2.length !== 3) {
3948
+ throw new Error("Vector must be 3 dimension");
3949
+ }
3950
+ return LinearAlgebra.plusVectors(LinearAlgebra.setCoefficient(0.5, vector1), LinearAlgebra.setCoefficient(0.5, vector2));
3951
+ },
3952
+ /**
3953
+ * Compute dot products between two vectors
3954
+ * @param vector1
3955
+ * @param vector2
3956
+ * @throws Exception if the vector is not in 3 dimension
3957
+ */ dotProduct: function dotProduct(vector1, vector2) {
3958
+ if (vector1.length !== 3 || vector2.length !== 3) {
3959
+ throw new Error("Vector must be 3 dimension");
3960
+ }
3961
+ return vector1[0] * vector2[0] + vector1[1] * vector2[1];
3962
+ },
3963
+ /**
3964
+ * Get vector magnitude
3965
+ * - formula : if vector = [x,y] => magnitude = square root of x^2 + y^2
3966
+ * @param vector
3967
+ * @throws Exception if the vector is not in 3 dimension
3968
+ */ getVectorMagnitude: function getVectorMagnitude(vector) {
3969
+ if (vector.length !== 3) {
3970
+ throw new Error("Vector must be 3 dimension");
3971
+ }
3972
+ return Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1]);
3973
+ }
3974
+ };
3975
+ var LinearAlgebra_default = LinearAlgebra;
3141
3976
  // Annotate the CommonJS export names for ESM import in node:
3142
3977
  0 && (module.exports = {
3143
3978
  Avatar: Avatar,
@@ -3150,6 +3985,7 @@ var useAuthClient_default = useAuthClient;
3150
3985
  ImageUtilities: ImageUtilities,
3151
3986
  InputFile: InputFile,
3152
3987
  InputGoogle: InputGoogle,
3988
+ LinearAlgebra: LinearAlgebra,
3153
3989
  MultiSelect: MultiSelect,
3154
3990
  OptionSlider: OptionSlider,
3155
3991
  RangeSlider: RangeSlider,