@yorab/react-paint 0.7.5 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/components/App.d.ts +20 -0
  2. package/dist/components/Canvas.d.ts +38 -0
  3. package/dist/components/common/Button.d.ts +16 -0
  4. package/dist/components/common/Loading.d.ts +7 -0
  5. package/dist/components/common/Modal.d.ts +10 -0
  6. package/dist/components/common/Panel.d.ts +13 -0
  7. package/dist/components/common/Snackbar.d.ts +8 -0
  8. package/dist/components/settings/ColorField.d.ts +15 -0
  9. package/dist/components/settings/DeleteButton.d.ts +9 -0
  10. package/dist/components/settings/FontFamilyField.d.ts +12 -0
  11. package/dist/components/settings/LayoutButton.d.ts +8 -0
  12. package/dist/components/settings/Layouts.d.ts +19 -0
  13. package/dist/components/settings/LineArrowField.d.ts +12 -0
  14. package/dist/components/settings/LineTypeField.d.ts +16 -0
  15. package/dist/components/settings/PointsNumberField.d.ts +13 -0
  16. package/dist/components/settings/RangeField.d.ts +18 -0
  17. package/dist/components/settings/SelectField.d.ts +18 -0
  18. package/dist/components/settings/SettingsBar.d.ts +19 -0
  19. package/dist/components/settings/ToggleField.d.ts +12 -0
  20. package/dist/components/toolbox/EditTextBox.d.ts +14 -0
  21. package/dist/components/toolbox/LoadFileTool.d.ts +12 -0
  22. package/dist/components/toolbox/MenuGroup.d.ts +35 -0
  23. package/dist/components/toolbox/PictureUrlInput.d.ts +8 -0
  24. package/dist/components/toolbox/Tool.d.ts +12 -0
  25. package/dist/components/toolbox/Toolbar.d.ts +27 -0
  26. package/dist/components/toolbox/ToolbarGroup.d.ts +18 -0
  27. package/dist/constants/app.d.ts +41 -0
  28. package/dist/constants/icons.d.ts +41 -0
  29. package/dist/constants/loading.d.ts +1 -0
  30. package/dist/constants/picture.d.ts +1 -0
  31. package/dist/constants/shapes.d.ts +8 -0
  32. package/dist/constants/snackbar.d.ts +7 -0
  33. package/dist/constants/style.d.ts +17 -0
  34. package/dist/constants/tools.d.ts +32 -0
  35. package/dist/hooks/useComponent.d.ts +9 -0
  36. package/dist/hooks/useDoubleClick.d.ts +5 -0
  37. package/dist/hooks/useDrag.d.ts +15 -0
  38. package/dist/hooks/useDrawableCanvas.d.ts +37 -0
  39. package/dist/hooks/useKeyboard.d.ts +18 -0
  40. package/dist/hooks/useResizeObserver.d.ts +7 -0
  41. package/dist/hooks/useShapes.d.ts +22 -0
  42. package/dist/hooks/useSnackbar.d.ts +10 -0
  43. package/dist/react-paint.css +1 -0
  44. package/dist/react-paint.js +9109 -0
  45. package/dist/react-paint.umd.cjs +53 -0
  46. package/dist/types/Mode.d.ts +43 -0
  47. package/dist/types/Shapes.d.ts +112 -0
  48. package/dist/types/snackbar.d.ts +7 -0
  49. package/dist/types/tools.d.ts +124 -0
  50. package/dist/types/utils.d.ts +3 -0
  51. package/dist/utils/canvas.d.ts +10 -0
  52. package/dist/utils/data.d.ts +225 -0
  53. package/dist/utils/dom.d.ts +1 -0
  54. package/dist/utils/file.d.ts +10 -0
  55. package/dist/utils/intersect.d.ts +6 -0
  56. package/dist/utils/migration.d.ts +165 -0
  57. package/dist/utils/selection.d.ts +7 -0
  58. package/dist/utils/shapes/brush.d.ts +55 -0
  59. package/dist/utils/shapes/circle.d.ts +13 -0
  60. package/dist/utils/shapes/curve.d.ts +11 -0
  61. package/dist/utils/shapes/default.d.ts +10 -0
  62. package/dist/utils/shapes/ellipse.d.ts +13 -0
  63. package/dist/utils/shapes/grid.d.ts +3 -0
  64. package/dist/utils/shapes/index.d.ts +245 -0
  65. package/dist/utils/shapes/line.d.ts +23 -0
  66. package/dist/utils/shapes/picture.d.ts +6 -0
  67. package/dist/utils/shapes/polygon.d.ts +11 -0
  68. package/dist/utils/shapes/rectangle.d.ts +26 -0
  69. package/dist/utils/shapes/text.d.ts +48 -0
  70. package/dist/utils/shapes/triangle.d.ts +2 -0
  71. package/dist/utils/string.d.ts +3 -0
  72. package/dist/utils/style.d.ts +2 -0
  73. package/dist/utils/toolbar.d.ts +13 -0
  74. package/dist/utils/transform.d.ts +8 -0
  75. package/dist/utils/trigo.d.ts +10 -0
  76. package/package.json +51 -56
  77. package/dist/components/App.js +0 -496
  78. package/dist/components/Canvas.js +0 -194
  79. package/dist/components/common/Button.js +0 -88
  80. package/dist/components/common/Loading.js +0 -57
  81. package/dist/components/common/Modal.js +0 -46
  82. package/dist/components/common/Panel.js +0 -43
  83. package/dist/components/common/Snackbar.js +0 -68
  84. package/dist/components/settings/ColorField.js +0 -125
  85. package/dist/components/settings/DeleteButton.js +0 -37
  86. package/dist/components/settings/FontFamilyField.js +0 -67
  87. package/dist/components/settings/LayoutButton.js +0 -39
  88. package/dist/components/settings/Layouts.js +0 -214
  89. package/dist/components/settings/LineArrowField.js +0 -67
  90. package/dist/components/settings/LineTypeField.js +0 -65
  91. package/dist/components/settings/PointsNumberField.js +0 -45
  92. package/dist/components/settings/RangeField.js +0 -82
  93. package/dist/components/settings/SelectField.js +0 -81
  94. package/dist/components/settings/SettingsBar.js +0 -383
  95. package/dist/components/settings/ToggleField.js +0 -49
  96. package/dist/components/toolbox/EditTextBox.js +0 -138
  97. package/dist/components/toolbox/LoadFileTool.js +0 -58
  98. package/dist/components/toolbox/MenuGroup.js +0 -173
  99. package/dist/components/toolbox/PictureUrlInput.js +0 -68
  100. package/dist/components/toolbox/Tool.js +0 -41
  101. package/dist/components/toolbox/Toolbar.js +0 -203
  102. package/dist/components/toolbox/ToolbarGroup.js +0 -134
  103. package/dist/constants/app.js +0 -51
  104. package/dist/constants/icons.js +0 -88
  105. package/dist/constants/loading.js +0 -8
  106. package/dist/constants/picture.js +0 -8
  107. package/dist/constants/shapes.js +0 -20
  108. package/dist/constants/snackbar.js +0 -15
  109. package/dist/constants/style.js +0 -35
  110. package/dist/constants/tools.js +0 -424
  111. package/dist/hooks/useComponent.js +0 -47
  112. package/dist/hooks/useDoubleClick.js +0 -46
  113. package/dist/hooks/useDrag.js +0 -92
  114. package/dist/hooks/useDrawableCanvas.js +0 -230
  115. package/dist/hooks/useKeyboard.js +0 -142
  116. package/dist/hooks/useResizeObserver.js +0 -42
  117. package/dist/hooks/useShapes.js +0 -184
  118. package/dist/hooks/useSnackbar.js +0 -56
  119. package/dist/styles.css +0 -91
  120. package/dist/types/Mode.js +0 -5
  121. package/dist/types/Shapes.js +0 -5
  122. package/dist/types/snackbar.js +0 -5
  123. package/dist/types/tools.js +0 -5
  124. package/dist/types/utils.js +0 -5
  125. package/dist/utils/canvas.js +0 -49
  126. package/dist/utils/data.js +0 -49
  127. package/dist/utils/dom.js +0 -12
  128. package/dist/utils/file.js +0 -171
  129. package/dist/utils/intersect.js +0 -122
  130. package/dist/utils/migration.js +0 -59
  131. package/dist/utils/selection.js +0 -86
  132. package/dist/utils/shapes/brush.js +0 -135
  133. package/dist/utils/shapes/circle.js +0 -93
  134. package/dist/utils/shapes/curve.js +0 -55
  135. package/dist/utils/shapes/default.js +0 -73
  136. package/dist/utils/shapes/ellipse.js +0 -101
  137. package/dist/utils/shapes/grid.js +0 -36
  138. package/dist/utils/shapes/index.js +0 -341
  139. package/dist/utils/shapes/line.js +0 -179
  140. package/dist/utils/shapes/picture.js +0 -103
  141. package/dist/utils/shapes/polygon.js +0 -69
  142. package/dist/utils/shapes/rectangle.js +0 -100
  143. package/dist/utils/shapes/text.js +0 -128
  144. package/dist/utils/shapes/triangle.js +0 -24
  145. package/dist/utils/string.js +0 -36
  146. package/dist/utils/style.js +0 -46
  147. package/dist/utils/toolbar.js +0 -78
  148. package/dist/utils/transform.js +0 -109
  149. package/dist/utils/trigo.js +0 -42
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.resizePicture = exports.getPictureBorder = exports.drawPicture = exports.createPicture = void 0;
9
-
10
- var _fp = _interopRequireDefault(require("lodash/fp"));
11
-
12
- var _transform = require("../transform");
13
-
14
- var _file = require("../file");
15
-
16
- var _tools = require("../../constants/tools");
17
-
18
- var _canvas = require("../canvas");
19
-
20
- var _rectangle = require("./rectangle");
21
-
22
- const createPictureShape = (img, storedSrc, maxPictureWidth, maxPictureHeight) => {
23
- const [width, height] = (0, _transform.fitContentInsideContainer)(img.width, img.height, maxPictureWidth, maxPictureHeight, true);
24
- return {
25
- toolId: _tools.DEFAULT_SHAPE_PICTURE.id,
26
- type: 'picture',
27
- id: _fp.default.uniqueId('picture'.concat("_")),
28
- x: (maxPictureWidth - width) / 2,
29
- y: (maxPictureHeight - height) / 2,
30
- width,
31
- height,
32
- src: storedSrc,
33
- img,
34
- rotation: 0
35
- };
36
- };
37
-
38
- const createFilePicture = (img, resolve, file, maxPictureWidth, maxPictureHeight) => {
39
- img.onload = async () => {
40
- if ((0, _file.isSvg)(file) && !img.width && !img.height) {
41
- const svgFileContent = await file.text();
42
- const svgFile = (0, _file.addSizeAndConvertSvgToBase64)(svgFileContent);
43
- if (svgFile === img.src) return; // prevent infinite loop
44
-
45
- img.src = svgFile;
46
- return;
47
- }
48
-
49
- const pictureShape = createPictureShape(img, img.src, maxPictureWidth, maxPictureHeight);
50
- resolve(pictureShape);
51
- };
52
-
53
- img.src = URL.createObjectURL(file);
54
- };
55
-
56
- const createUrlPicture = (img, resolve, url, maxPictureWidth, maxPictureHeight) => {
57
- img.onload = () => {
58
- const pictureShape = createPictureShape(img, url, maxPictureWidth, maxPictureHeight);
59
- resolve(pictureShape);
60
- };
61
-
62
- (0, _file.fetchAndStringify)(url).then(picData => {
63
- img.src = picData;
64
- }).catch(() => {
65
- img.src = ''; // trigger onerror
66
- });
67
- };
68
-
69
- const createPicture = (fileOrUrl, maxPictureWidth, maxPictureHeight) => {
70
- return new Promise((resolve, reject) => {
71
- const img = new Image();
72
-
73
- img.onerror = () => {
74
- reject(new Error('Some images could not be loaded'));
75
- };
76
-
77
- setTimeout(() => {
78
- reject(new Error('Timeout while loading images'));
79
- }, 4000);
80
- fileOrUrl instanceof File ? createFilePicture(img, resolve, fileOrUrl, maxPictureWidth, maxPictureHeight) : createUrlPicture(img, resolve, fileOrUrl, maxPictureWidth, maxPictureHeight);
81
- });
82
- };
83
-
84
- exports.createPicture = createPicture;
85
-
86
- const drawPicture = (ctx, picture) => {
87
- (0, _canvas.updateCanvasContext)(ctx, picture.style);
88
- if (ctx.globalAlpha === 0) return;
89
- ctx.beginPath();
90
- ctx.drawImage(picture.img, picture.x, picture.y, picture.width, picture.height);
91
- };
92
-
93
- exports.drawPicture = drawPicture;
94
-
95
- const getPictureBorder = (picture, selectionPadding) => (0, _rectangle.getRectBorder)(picture, selectionPadding);
96
-
97
- exports.getPictureBorder = getPictureBorder;
98
-
99
- const resizePicture = (cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, keepRatio) => {
100
- return (0, _rectangle.resizeRect)(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, keepRatio);
101
- };
102
-
103
- exports.resizePicture = resizePicture;
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.getPolygonBorder = exports.drawPolygon = exports.createPolygon = void 0;
9
-
10
- var _fp = _interopRequireDefault(require("lodash/fp"));
11
-
12
- var _canvas = require("../canvas");
13
-
14
- const createPolygon = (shape, cursorPosition) => {
15
- return {
16
- toolId: shape.id,
17
- type: shape.type,
18
- id: _fp.default.uniqueId("".concat(shape.type, "_")),
19
- points: _fp.default.flow(_fp.default.range(0), _fp.default.map(() => cursorPosition))(shape.settings.pointsCount.default),
20
- rotation: 0,
21
- style: {
22
- globalAlpha: shape.settings.opacity.default,
23
- fillColor: shape.settings.fillColor.default,
24
- strokeColor: shape.settings.strokeColor.default,
25
- lineWidth: shape.settings.lineWidth.default,
26
- lineDash: shape.settings.lineDash.default,
27
- pointsCount: shape.settings.pointsCount.default
28
- }
29
- };
30
- };
31
-
32
- exports.createPolygon = createPolygon;
33
-
34
- const drawPolygon = (ctx, polygon) => {
35
- var _polygon$style, _polygon$style2;
36
-
37
- if (polygon.points.length < 1) return;
38
- (0, _canvas.updateCanvasContext)(ctx, polygon.style);
39
- if (ctx.globalAlpha === 0) return;
40
- ctx.beginPath();
41
- ctx.moveTo(...polygon.points[0]);
42
- polygon.points.slice(1).forEach(point => {
43
- ctx.lineTo(...point);
44
- });
45
- ctx.lineTo(...polygon.points[0]);
46
- ((_polygon$style = polygon.style) === null || _polygon$style === void 0 ? void 0 : _polygon$style.fillColor) !== 'transparent' && ctx.fill();
47
- ((_polygon$style2 = polygon.style) === null || _polygon$style2 === void 0 ? void 0 : _polygon$style2.strokeColor) !== 'transparent' && ctx.stroke();
48
- };
49
-
50
- exports.drawPolygon = drawPolygon;
51
-
52
- const getPolygonBorder = (polygon, selectionPadding) => {
53
- const minX = _fp.default.flow(_fp.default.map(point => point[0]), _fp.default.min, _fp.default.add(-selectionPadding))(polygon.points);
54
-
55
- const maxX = _fp.default.flow(_fp.default.map(point => point[0]), _fp.default.max, _fp.default.add(selectionPadding))(polygon.points);
56
-
57
- const minY = _fp.default.flow(_fp.default.map(point => point[1]), _fp.default.min, _fp.default.add(-selectionPadding))(polygon.points);
58
-
59
- const maxY = _fp.default.flow(_fp.default.map(point => point[1]), _fp.default.max, _fp.default.add(selectionPadding))(polygon.points);
60
-
61
- return {
62
- x: minX,
63
- width: maxX - minX,
64
- y: minY,
65
- height: maxY - minY
66
- };
67
- };
68
-
69
- exports.getPolygonBorder = getPolygonBorder;
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.resizeRect = exports.getRectOppositeAnchorAbsolutePosition = exports.getRectBorder = exports.drawRect = exports.createRectangle = void 0;
9
-
10
- var _fp = _interopRequireDefault(require("lodash/fp"));
11
-
12
- var _canvas = require("../canvas");
13
-
14
- var _intersect = require("../intersect");
15
-
16
- var _transform = require("../transform");
17
-
18
- var _2 = require(".");
19
-
20
- const createRectangle = (shape, cursorPosition) => {
21
- return {
22
- toolId: shape.id,
23
- type: shape.type,
24
- id: _fp.default.uniqueId("".concat(shape.type, "_")),
25
- x: cursorPosition[0],
26
- y: cursorPosition[1],
27
- width: 1,
28
- height: 1,
29
- rotation: 0,
30
- style: {
31
- globalAlpha: shape.settings.opacity.default,
32
- fillColor: shape.settings.fillColor.default,
33
- strokeColor: shape.settings.strokeColor.default,
34
- lineWidth: shape.settings.lineWidth.default,
35
- lineDash: shape.settings.lineDash.default
36
- }
37
- };
38
- };
39
-
40
- exports.createRectangle = createRectangle;
41
-
42
- const drawRect = (ctx, rect) => {
43
- var _rect$style, _rect$style2;
44
-
45
- (0, _canvas.updateCanvasContext)(ctx, rect.style);
46
- if (ctx.globalAlpha === 0) return;
47
- ctx.beginPath();
48
- ctx.rect(rect.x, rect.y, rect.width, rect.height);
49
- ((_rect$style = rect.style) === null || _rect$style === void 0 ? void 0 : _rect$style.fillColor) !== 'transparent' && ctx.fill();
50
- ((_rect$style2 = rect.style) === null || _rect$style2 === void 0 ? void 0 : _rect$style2.strokeColor) !== 'transparent' && ctx.stroke();
51
- };
52
-
53
- exports.drawRect = drawRect;
54
-
55
- const getRectBorder = (rect, selectionPadding) => {
56
- return {
57
- x: rect.x - selectionPadding,
58
- width: rect.width + selectionPadding * 2,
59
- y: rect.y - selectionPadding,
60
- height: rect.height + selectionPadding * 2
61
- };
62
- };
63
-
64
- exports.getRectBorder = getRectBorder;
65
-
66
- const getRectOppositeAnchorAbsolutePosition = function (anchor, center, shape, canvasOffset) {
67
- let [negW, negH] = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [false, false];
68
- const oppositeX = anchor[0] === 0.5 ? shape.x + shape.width / 2 : anchor[0] === 0 ? shape.x + (negW ? 0 : shape.width) : shape.x + (negW ? shape.width : 0);
69
- const oppositeY = anchor[1] === 0.5 ? shape.y + shape.height / 2 : anchor[1] === 0 ? shape.y + (negH ? 0 : shape.height) : shape.y + (negH ? shape.height : 0);
70
- return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.rotation, center, canvasOffset);
71
- };
72
-
73
- exports.getRectOppositeAnchorAbsolutePosition = getRectOppositeAnchorAbsolutePosition;
74
-
75
- const resizeRect = function (cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
76
- let keepRatio = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
77
- const {
78
- center,
79
- borders
80
- } = (0, _2.getShapeInfos)(originalShape, selectionPadding);
81
- const cusroPositionAfterShapeTransormation = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, originalShape.rotation, center, canvasOffset);
82
- const scaledWidth = selectionMode.anchor[0] === 0.5 ? originalShape.width : selectionMode.anchor[0] === 0 ? borders.x + borders.width - cusroPositionAfterShapeTransormation[0] + selectionPadding * -2 : cusroPositionAfterShapeTransormation[0] - borders.x - selectionPadding * 2;
83
- const scaledHeight = selectionMode.anchor[1] === 0.5 ? originalShape.height : selectionMode.anchor[1] === 0 ? borders.y + borders.height - cusroPositionAfterShapeTransormation[1] + selectionPadding * -2 : cusroPositionAfterShapeTransormation[1] - borders.y - selectionPadding * 2;
84
- const [widthWithRatio, heightWithRatio] = keepRatio ? (0, _transform.getNormalizedSize)(originalShape.width, originalShape.height, scaledWidth, scaledHeight) : [scaledWidth, scaledHeight];
85
- const shapeWithNewDimensions = { ...originalShape,
86
- width: Math.abs(widthWithRatio),
87
- height: Math.abs(heightWithRatio)
88
- };
89
- const {
90
- center: shapeWithNewDimensionsCenter
91
- } = (0, _2.getShapeInfos)(shapeWithNewDimensions, selectionPadding);
92
- const [oppTrueX, oppTrueY] = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape, canvasOffset);
93
- const [newOppTrueX, newOppTrueY] = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, shapeWithNewDimensions, canvasOffset, [widthWithRatio < 0, heightWithRatio < 0]);
94
- return { ...shapeWithNewDimensions,
95
- x: shapeWithNewDimensions.x - (newOppTrueX - oppTrueX),
96
- y: shapeWithNewDimensions.y - (newOppTrueY - oppTrueY)
97
- };
98
- };
99
-
100
- exports.resizeRect = resizeRect;
@@ -1,128 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.resizeTextShapeWithNewContent = exports.resizeText = exports.getTextBorder = exports.drawText = exports.createText = exports.calculateTextFontSize = void 0;
9
-
10
- var _fp = _interopRequireDefault(require("lodash/fp"));
11
-
12
- var _canvas = require("../canvas");
13
-
14
- var _style = require("../../constants/style");
15
-
16
- var _rectangle = require("./rectangle");
17
-
18
- var _2 = require(".");
19
-
20
- const calculateTextFontSize = function (ctx, text, maxWidth, fontBold, fontItalic) {
21
- var _$flow;
22
-
23
- let fontFamily = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : _style.STYLE_FONT_DEFAULT;
24
- ctx.font = "".concat(fontItalic ? 'italic' : '', " ").concat(fontBold ? 'bold' : '', " 1px ").concat(fontFamily);
25
- return (_$flow = _fp.default.flow(_fp.default.map(value => maxWidth / ctx.measureText(value).width), _fp.default.min)(text)) !== null && _$flow !== void 0 ? _$flow : _style.STYLE_FONT_SIZE_DEFAULT;
26
- };
27
-
28
- exports.calculateTextFontSize = calculateTextFontSize;
29
-
30
- const createText = (ctx, shape, cursorPosition) => {
31
- var _shape$settings$fontB, _shape$settings, _shape$settings$fontI, _shape$settings2;
32
-
33
- const defaultValue = ['Texte'];
34
- const fontSize = calculateTextFontSize(ctx, defaultValue, 50, (_shape$settings$fontB = (_shape$settings = shape.settings) === null || _shape$settings === void 0 ? void 0 : _shape$settings.fontBold.default) !== null && _shape$settings$fontB !== void 0 ? _shape$settings$fontB : false, (_shape$settings$fontI = (_shape$settings2 = shape.settings) === null || _shape$settings2 === void 0 ? void 0 : _shape$settings2.fontItalic.default) !== null && _shape$settings$fontI !== void 0 ? _shape$settings$fontI : false, shape.settings.fontFamily.default);
35
- return {
36
- toolId: shape.id,
37
- type: shape.type,
38
- id: _fp.default.uniqueId("".concat(shape.type, "_")),
39
- x: cursorPosition[0],
40
- y: cursorPosition[1],
41
- value: defaultValue,
42
- fontSize,
43
- width: 50,
44
- height: fontSize * (defaultValue.length || 1),
45
- rotation: 0,
46
- style: {
47
- globalAlpha: shape.settings.opacity.default,
48
- strokeColor: shape.settings.strokeColor.default,
49
- fontFamily: shape.settings.fontFamily.default
50
- }
51
- };
52
- };
53
-
54
- exports.createText = createText;
55
-
56
- const drawText = (ctx, text) => {
57
- var _text$style, _text$style2, _text$style3, _text$style$fontFamil, _text$style4;
58
-
59
- (0, _canvas.updateCanvasContext)(ctx, text.style);
60
- if (ctx.globalAlpha === 0 || !((_text$style = text.style) !== null && _text$style !== void 0 && _text$style.strokeColor) || text.style.strokeColor === 'transparent') return;
61
- ctx.font = "".concat((_text$style2 = text.style) !== null && _text$style2 !== void 0 && _text$style2.fontItalic ? 'italic' : '', " ").concat((_text$style3 = text.style) !== null && _text$style3 !== void 0 && _text$style3.fontBold ? 'bold' : '', " ").concat(text.fontSize, "px ").concat((_text$style$fontFamil = (_text$style4 = text.style) === null || _text$style4 === void 0 ? void 0 : _text$style4.fontFamily) !== null && _text$style$fontFamil !== void 0 ? _text$style$fontFamil : _style.STYLE_FONT_DEFAULT);
62
- ctx.textBaseline = 'top';
63
- ctx.fillStyle = text.style.strokeColor;
64
-
65
- for (let i = 0; i < text.value.length; i++) {
66
- ctx.fillText(text.value[i], text.x, text.y + i * text.fontSize, text.width);
67
- }
68
- };
69
-
70
- exports.drawText = drawText;
71
-
72
- const getTextBorder = (text, selectionPadding) => {
73
- return {
74
- x: text.x - selectionPadding,
75
- width: text.width + selectionPadding * 2,
76
- y: text.y - selectionPadding,
77
- height: text.height + selectionPadding * 2
78
- };
79
- };
80
-
81
- exports.getTextBorder = getTextBorder;
82
-
83
- const resizeText = (ctx, cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) => {
84
- var _newRect$style$fontBo, _newRect$style, _newRect$style$fontIt, _newRect$style2, _newRect$style3;
85
-
86
- const newRect = (0, _rectangle.resizeRect)(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, true);
87
- return { ...newRect,
88
- fontSize: calculateTextFontSize(ctx, newRect.value, newRect.width, (_newRect$style$fontBo = (_newRect$style = newRect.style) === null || _newRect$style === void 0 ? void 0 : _newRect$style.fontBold) !== null && _newRect$style$fontBo !== void 0 ? _newRect$style$fontBo : false, (_newRect$style$fontIt = (_newRect$style2 = newRect.style) === null || _newRect$style2 === void 0 ? void 0 : _newRect$style2.fontItalic) !== null && _newRect$style$fontIt !== void 0 ? _newRect$style$fontIt : false, (_newRect$style3 = newRect.style) === null || _newRect$style3 === void 0 ? void 0 : _newRect$style3.fontFamily)
89
- };
90
- };
91
-
92
- exports.resizeText = resizeText;
93
-
94
- const calculateTextWidth = function (ctx, text, fontSize, fontBold, fontItalic) {
95
- var _$flow2;
96
-
97
- let fontFamily = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : _style.STYLE_FONT_DEFAULT;
98
- ctx.font = "".concat(fontItalic ? 'italic' : '', " ").concat(fontBold ? 'bold' : '', " ").concat(fontSize, "px ").concat(fontFamily);
99
- return (_$flow2 = _fp.default.flow(_fp.default.map(value => ctx.measureText(value).width), _fp.default.max)(text)) !== null && _$flow2 !== void 0 ? _$flow2 : 20;
100
- };
101
-
102
- const resizeTextShapeWithNewContent = (ctx, shape, newValue, canvasOffset) => {
103
- var _newShape$style$fontB, _newShape$style, _newShape$style$fontI, _newShape$style2, _newShape$style3;
104
-
105
- const newShape = _fp.default.set('value', newValue, shape);
106
-
107
- const newWidth = calculateTextWidth(ctx, newShape.value, newShape.fontSize, (_newShape$style$fontB = (_newShape$style = newShape.style) === null || _newShape$style === void 0 ? void 0 : _newShape$style.fontBold) !== null && _newShape$style$fontB !== void 0 ? _newShape$style$fontB : false, (_newShape$style$fontI = (_newShape$style2 = newShape.style) === null || _newShape$style2 === void 0 ? void 0 : _newShape$style2.fontItalic) !== null && _newShape$style$fontI !== void 0 ? _newShape$style$fontI : false, (_newShape$style3 = newShape.style) === null || _newShape$style3 === void 0 ? void 0 : _newShape$style3.fontFamily);
108
- const newHeight = newShape.fontSize * newShape.value.length;
109
- const resizedShape = { ...newShape,
110
- width: newWidth,
111
- height: newHeight
112
- };
113
- const selectionPadding = 0;
114
- const {
115
- center
116
- } = (0, _2.getShapeInfos)(shape, selectionPadding);
117
- const {
118
- center: shapeWithNewDimensionsCenter
119
- } = (0, _2.getShapeInfos)(resizedShape, selectionPadding);
120
- const [oppTrueX, oppTrueY] = (0, _rectangle.getRectOppositeAnchorAbsolutePosition)([1, 0.5], center, shape, canvasOffset);
121
- const [newOppTrueX, newOppTrueY] = (0, _rectangle.getRectOppositeAnchorAbsolutePosition)([1, 0.5], shapeWithNewDimensionsCenter, resizedShape, canvasOffset, [false, false]);
122
- return { ...resizedShape,
123
- x: resizedShape.x - (newOppTrueX - oppTrueX),
124
- y: resizedShape.y - (newOppTrueY - oppTrueY)
125
- };
126
- };
127
-
128
- exports.resizeTextShapeWithNewContent = resizeTextShapeWithNewContent;
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.drawTriangle = void 0;
7
-
8
- var _canvas = require("../canvas");
9
-
10
- const drawTriangle = (ctx, triangle) => {
11
- var _triangle$style, _triangle$style2;
12
-
13
- (0, _canvas.updateCanvasContext)(ctx, triangle.style);
14
- if (ctx.globalAlpha === 0) return;
15
- ctx.beginPath();
16
- ctx.moveTo(...triangle.points[0]);
17
- ctx.lineTo(...triangle.points[1]);
18
- ctx.lineTo(...triangle.points[2]);
19
- ctx.lineTo(...triangle.points[0]);
20
- ((_triangle$style = triangle.style) === null || _triangle$style === void 0 ? void 0 : _triangle$style.fillColor) !== 'transparent' && ctx.fill();
21
- ((_triangle$style2 = triangle.style) === null || _triangle$style2 === void 0 ? void 0 : _triangle$style2.strokeColor) !== 'transparent' && ctx.stroke();
22
- };
23
-
24
- exports.drawTriangle = drawTriangle;
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.decodeHtmlEntities = exports.convertStringArrayToDivContent = exports.convertDivContentToStringArray = void 0;
9
-
10
- var _fp = _interopRequireDefault(require("lodash/fp"));
11
-
12
- const stripAllTagsRegexp = /(<([^>]+)>)/gi;
13
- const stripDivRegexp = /<(\/)?div(\/?\s?)>/gi;
14
-
15
- const convertStringArrayToDivContent = toConvert => {
16
- return toConvert.map(val => "<div>".concat(val === '' ? '<br/>' : val, "</div>")).join('');
17
- };
18
-
19
- exports.convertStringArrayToDivContent = convertStringArrayToDivContent;
20
-
21
- const decodeHtmlEntities = html => {
22
- const textareaElement = document.createElement('textarea');
23
- textareaElement.innerHTML = html;
24
- return textareaElement.value;
25
- };
26
-
27
- exports.decodeHtmlEntities = decodeHtmlEntities;
28
-
29
- const convertDivContentToStringArray = toConvert => {
30
- return _fp.default.flow(divContent => decodeHtmlEntities(divContent), divContent => divContent.split('<div>'), _fp.default.flatMap(val => {
31
- const newVal = val.replaceAll(stripDivRegexp, '');
32
- return newVal === '' ? undefined : newVal.replaceAll(stripAllTagsRegexp, '');
33
- }), _fp.default.reject(_fp.default.isUndefined))(toConvert);
34
- };
35
-
36
- exports.convertDivContentToStringArray = convertDivContentToStringArray;
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getShapePicture = void 0;
7
-
8
- var _icons = require("../constants/icons");
9
-
10
- const getShapePicture = shape => {
11
- switch (shape) {
12
- case 'brush':
13
- return _icons.brushIcon;
14
-
15
- case 'line':
16
- return _icons.arrowIcon;
17
-
18
- case 'polygon':
19
- return _icons.polygonIcon;
20
-
21
- case 'curve':
22
- return _icons.curveIcon;
23
-
24
- case 'rect':
25
- return _icons.squareIcon;
26
- // temporary
27
-
28
- case 'square':
29
- return _icons.squareIcon;
30
-
31
- case 'circle':
32
- return _icons.circleIcon;
33
-
34
- case 'ellipse':
35
- return _icons.circleIcon;
36
- // temporary
37
-
38
- case 'text':
39
- return _icons.textIcon;
40
-
41
- case 'picture':
42
- return _icons.pictureIcon;
43
- }
44
- };
45
-
46
- exports.getShapePicture = getShapePicture;
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.sanitizeTools = exports.getCurrentStructure = void 0;
9
-
10
- var _fp = _interopRequireDefault(require("lodash/fp"));
11
-
12
- var _tools = require("../constants/tools");
13
-
14
- const getCurrentStructure = (availableTools, defaultStructure) => {
15
- return _fp.default.flow(_fp.default.flatMap(group => {
16
- if (!_fp.default.isObject(group)) {
17
- return _fp.default.filter({
18
- type: group
19
- }, availableTools);
20
- }
21
-
22
- const toolsType = _fp.default.filter(tool => _fp.default.includes(tool.type, group.toolsType), availableTools);
23
-
24
- if (!toolsType) return null;
25
- return { ...group,
26
- toolsType
27
- };
28
- }), _fp.default.compact)(defaultStructure);
29
- };
30
-
31
- exports.getCurrentStructure = getCurrentStructure;
32
-
33
- const sanitizeTools = function (tools) {
34
- let withPicture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
35
-
36
- const customizer = (objValue, srcValue) => {
37
- if (_fp.default.isArray(objValue)) {
38
- return srcValue;
39
- }
40
- };
41
-
42
- return _fp.default.flow(_fp.default.map(tool => {
43
- if (!_fp.default.isObject(tool)) return null;
44
-
45
- switch (_fp.default.get('type', tool)) {
46
- case 'brush':
47
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_BRUSH, tool);
48
-
49
- case 'circle':
50
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_CIRCLE, tool);
51
-
52
- case 'curve':
53
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_CURVE, tool);
54
-
55
- case 'ellipse':
56
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_ELLIPSE, tool);
57
-
58
- case 'line':
59
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_LINE, tool);
60
-
61
- case 'polygon':
62
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_POLYGON, tool);
63
-
64
- case 'rect':
65
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_RECT, tool);
66
-
67
- case 'square':
68
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_SQUARE, tool);
69
-
70
- case 'text':
71
- return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_TEXT, tool);
72
- }
73
-
74
- return null;
75
- }), tools => withPicture ? [...tools, _tools.DEFAULT_SHAPE_PICTURE] : tools, _fp.default.compact)(tools);
76
- };
77
-
78
- exports.sanitizeTools = sanitizeTools;