@yorab/react-paint 0.13.1 → 0.15.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 (63) hide show
  1. package/README.md +46 -283
  2. package/dist/canvas/components/Canvas.d.ts +15 -7
  3. package/dist/canvas/components/EditTextBox.d.ts +2 -2
  4. package/dist/canvas/constants/app.d.ts +2 -0
  5. package/dist/canvas/constants/keyboard.d.ts +24 -0
  6. package/dist/canvas/constants/shapes.d.ts +1 -1
  7. package/dist/canvas/hooks/useComponent.d.ts +3 -1
  8. package/dist/canvas/hooks/useDebounce.d.ts +2 -0
  9. package/dist/canvas/hooks/useDrawableCanvas.d.ts +12 -7
  10. package/dist/canvas/hooks/useKeyboard.d.ts +15 -8
  11. package/dist/canvas/hooks/useReactPaint.d.ts +1874 -25
  12. package/dist/canvas/hooks/useShapes.d.ts +1393 -13
  13. package/dist/canvas/hooks/useZoom.d.ts +1 -0
  14. package/dist/canvas/index.d.ts +3 -3
  15. package/dist/canvas/utils/canvas.d.ts +2 -0
  16. package/dist/canvas/utils/data.d.ts +2 -2
  17. package/dist/canvas/utils/file.d.ts +233 -4
  18. package/dist/canvas/utils/intersect.d.ts +6 -6
  19. package/dist/canvas/utils/selection/groupSelection.d.ts +3 -0
  20. package/dist/canvas/utils/selection/lineSelection.d.ts +9 -3
  21. package/dist/canvas/utils/selection/rectSelection.d.ts +10 -5
  22. package/dist/canvas/utils/selection.d.ts +11 -4
  23. package/dist/canvas/utils/shapes/brush.d.ts +14 -11
  24. package/dist/canvas/utils/shapes/circle.d.ts +13 -9
  25. package/dist/canvas/utils/shapes/curve.d.ts +15 -10
  26. package/dist/canvas/utils/shapes/ellipse.d.ts +13 -9
  27. package/dist/canvas/utils/shapes/index.d.ts +30 -16
  28. package/dist/canvas/utils/shapes/line.d.ts +13 -8
  29. package/dist/canvas/utils/shapes/path.d.ts +19 -3
  30. package/dist/canvas/utils/shapes/picture.d.ts +13 -9
  31. package/dist/canvas/utils/shapes/polygon.d.ts +15 -9
  32. package/dist/canvas/utils/shapes/rectangle.d.ts +56 -11
  33. package/dist/canvas/utils/shapes/text.d.ts +13 -8
  34. package/dist/canvas/utils/shapes/triangle.d.ts +4 -3
  35. package/dist/canvas/utils/transform.d.ts +4 -4
  36. package/dist/canvas/utils/trigo.d.ts +1 -1
  37. package/dist/common/types/Mode.d.ts +5 -4
  38. package/dist/common/types/Shapes.d.ts +70 -28
  39. package/dist/common/types/tools.d.ts +5 -1
  40. package/dist/common/types/utils.d.ts +1 -1
  41. package/dist/editor/components/common/Button.d.ts +6 -6
  42. package/dist/editor/components/common/FileInput.d.ts +13 -0
  43. package/dist/editor/components/common/Panel.d.ts +1 -1
  44. package/dist/editor/components/settings/ClosedPointsField.d.ts +1 -1
  45. package/dist/editor/components/settings/ColorField.d.ts +1 -1
  46. package/dist/editor/components/settings/DeleteButton.d.ts +3 -3
  47. package/dist/editor/components/settings/FontFamilyField.d.ts +1 -1
  48. package/dist/editor/components/settings/Layouts.d.ts +7 -7
  49. package/dist/editor/components/settings/LineArrowField.d.ts +1 -1
  50. package/dist/editor/components/settings/LineTypeField.d.ts +1 -1
  51. package/dist/editor/components/settings/RangeField.d.ts +1 -1
  52. package/dist/editor/components/settings/SettingsBar.d.ts +4 -4
  53. package/dist/editor/components/settings/ToggleField.d.ts +2 -2
  54. package/dist/editor/components/settings/ZoomButton.d.ts +2 -2
  55. package/dist/editor/constants/icons.d.ts +1 -0
  56. package/dist/editor/constants/tools.d.ts +2 -2
  57. package/dist/editor/hooks/useDrag.d.ts +1 -1
  58. package/dist/editor/index.d.ts +11 -11
  59. package/dist/editor/utils/style.d.ts +1 -1
  60. package/dist/react-paint.css +1 -1
  61. package/dist/react-paint.js +1361 -1188
  62. package/dist/react-paint.umd.cjs +1 -1
  63. package/package.json +19 -15
@@ -1,17 +1,22 @@
1
1
  import type { UtilsSettings } from './../../../canvas/constants/app';
2
2
  import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Line, Point, Rect, ShapeEntity, StyleShape, Triangle } from './../../../common/types/Shapes';
3
+ import type { DrawableShape, Point, Rect, ShapeEntity, StyleShape, Triangle } from './../../../common/types/Shapes';
4
4
  import type { ToolsSettingsType } from './../../../common/types/tools';
5
- export declare const refreshLine: <T extends DrawableShape<"line">>(line: T, settings: UtilsSettings) => T;
5
+ export declare const getComputedLine: (line: DrawableShape<"line">, settings: UtilsSettings) => {
6
+ borders: Rect;
7
+ outerBorders: Rect;
8
+ center: Point;
9
+ boundingBox: Rect;
10
+ };
11
+ export declare const refreshLine: <T extends DrawableShape<"line">>(line: T & {
12
+ id: string;
13
+ }, settings: UtilsSettings) => ShapeEntity<"line">;
6
14
  export declare const createLine: (shape: {
7
15
  id: string;
8
16
  type: "line";
9
17
  settings: ToolsSettingsType<"line">;
10
18
  }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"line">;
11
19
  export declare const buildTriangleOnLine: (center: Point, rotation: number, lineStyle: StyleShape) => Triangle;
12
- export declare const drawLine: (ctx: CanvasRenderingContext2D, shape: DrawableShape<"line">) => void;
13
- export declare const getLineBorder: (line: Line, settings: UtilsSettings) => Rect;
14
- export declare const translateLine: <U extends DrawableShape<"line">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => U & {
15
- points: [Point, Point];
16
- };
17
- export declare const resizeLine: <U extends DrawableShape<"line">>(cursorPosition: Point, originalShape: U, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => U;
20
+ export declare const drawLine: (ctx: CanvasRenderingContext2D, shape: ShapeEntity<"line">) => void;
21
+ export declare const translateLine: (cursorPosition: Point, originalShape: ShapeEntity<"line">, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => ShapeEntity<"line">;
22
+ export declare const resizeLine: (cursorPosition: Point, originalShape: ShapeEntity<"line">, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => ShapeEntity<"line">;
@@ -1,12 +1,28 @@
1
1
  import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { Circle, DrawableShape, Line, Point, Rect } from './../../../common/types/Shapes';
2
+ import type { Circle, DrawableShape, Line, Point, Rect, StyleShape } from './../../../common/types/Shapes';
3
3
  export declare const createRecPath: (rect: Rect) => Path2D;
4
4
  export declare const createCirclePath: (shape: Circle) => Path2D;
5
5
  export declare const createEllipsePath: (ellipse: DrawableShape<"ellipse">) => Path2D;
6
6
  export declare const createLinePath: (line: Line) => Path2D;
7
7
  export declare const createBrushPath: (brush: DrawableShape<"brush">, { brushAlgo }: UtilsSettings) => Path2D | undefined;
8
- export declare const getCatmullRomPoints: (curve: DrawableShape<"curve">, points: Point[]) => [number, number][];
9
- export declare const catmullRomToBezier: (path: Path2D, p0: Point, p1: Point, p2: Point, p3: Point) => void;
8
+ /** Bounding box of a cubic Bezier segment B(t) = (1-t)³P0 + 3(1-t)²t P1 + 3(1-t)t² P2 + t³ P3 */
9
+ export declare const getCubicBezierBounds: (p0: Point, p1: Point, p2: Point, p3: Point) => {
10
+ minX: number;
11
+ maxX: number;
12
+ minY: number;
13
+ maxY: number;
14
+ };
15
+ export declare const getCatmullRomPoints: (curve: DrawableShape<"curve">, points: Point[]) => Point[];
16
+ export declare const catmullRomToBezier: (p0: Point, p1: Point, p2: Point, p3: Point) => {
17
+ cp1: Point;
18
+ cp2: Point;
19
+ };
10
20
  export declare const createCurvePath: (curve: DrawableShape<"curve">) => Path2D | undefined;
11
21
  export declare const createPolygonPath: (polygon: DrawableShape<"polygon"> | DrawableShape<"curve">) => Path2D | undefined;
12
22
  export declare const createTrianglePath: (triangle: DrawableShape<"triangle">) => Path2D;
23
+ export declare const getComputedShapeInfos: <T extends DrawableShape, U extends Pick<UtilsSettings, "selectionPadding">>(shape: T, getBorder: (shape: T, settings: U) => Rect, settings: U, getOuterBorder?: (border: Rect, style: StyleShape | undefined) => Rect) => {
24
+ borders: Rect;
25
+ outerBorders: Rect;
26
+ center: Point;
27
+ boundingBox: Rect;
28
+ };
@@ -1,12 +1,16 @@
1
1
  import type { UtilsSettings } from './../../../canvas/constants/app';
2
2
  import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Picture, Point, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
- export declare const refreshPicture: <T extends DrawableShape<"picture">>(shape: T, settings: UtilsSettings) => T;
5
- export declare const createPicture: (fileOrUrl: File | string, maxPictureWidth: number, maxPictureHeight: number, settings: UtilsSettings) => Promise<ShapeEntity<"picture">>;
6
- export declare const drawPicture: (ctx: CanvasRenderingContext2D, picture: DrawableShape<"picture">) => void;
7
- export declare const getPictureBorder: (picture: Picture, settings: UtilsSettings) => Rect;
8
- export declare const translatePicture: <U extends DrawableShape<"picture">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => U & {
9
- x: number;
10
- y: number;
3
+ import type { DrawableShape, Point, ShapeEntity } from './../../../common/types/Shapes';
4
+ export declare const getComputedPicture: (picture: DrawableShape<"picture">, settings: UtilsSettings) => {
5
+ borders: import("./../../../common/types/Shapes").Rect;
6
+ outerBorders: import("./../../../common/types/Shapes").Rect;
7
+ center: Point;
8
+ boundingBox: import("./../../../common/types/Shapes").Rect;
11
9
  };
12
- export declare const resizePicture: (cursorPosition: Point, originalShape: DrawableShape<"picture">, selectionMode: SelectionModeResize, settings: UtilsSettings, resizeFromCenter: boolean) => DrawableShape<"picture">;
10
+ export declare const refreshPicture: <T extends DrawableShape<"picture">>(shape: T & {
11
+ id: string;
12
+ }, settings: UtilsSettings) => ShapeEntity<"picture">;
13
+ export declare const createPicture: (fileOrUrl: File | string, maxPictureWidth: number, maxPictureHeight: number, settings: UtilsSettings) => Promise<ShapeEntity<"picture">>;
14
+ export declare const drawPicture: (ctx: CanvasRenderingContext2D, picture: ShapeEntity<"picture">) => void;
15
+ export declare const translatePicture: (cursorPosition: Point, originalShape: ShapeEntity<"picture">, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => ShapeEntity<"picture">;
16
+ export declare const resizePicture: (cursorPosition: Point, originalShape: ShapeEntity<"picture">, selectionMode: SelectionModeResize, settings: UtilsSettings, resizeFromCenter: boolean) => ShapeEntity<"picture">;
@@ -2,17 +2,23 @@ import type { UtilsSettings } from './../../../canvas/constants/app';
2
2
  import type { SelectionModeResize } from './../../../common/types/Mode';
3
3
  import type { DrawableShape, Point, Polygon, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
4
  import type { ToolsSettingsType } from './../../../common/types/tools';
5
- export declare const refreshPolygon: <T extends DrawableShape<"polygon">>(shape: T, settings: UtilsSettings) => T;
5
+ export declare const getComputedPolygon: (polygon: DrawableShape<"polygon">, settings: UtilsSettings) => {
6
+ borders: Rect;
7
+ outerBorders: Rect;
8
+ center: Point;
9
+ boundingBox: Rect;
10
+ };
11
+ export declare const refreshPolygon: <T extends DrawableShape<"polygon">>(shape: T & {
12
+ id: string;
13
+ }, settings: UtilsSettings) => ShapeEntity<"polygon">;
6
14
  export declare const createPolygon: (shape: {
7
15
  id: string;
8
16
  type: "polygon";
9
17
  settings: ToolsSettingsType<"polygon">;
10
18
  }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"polygon">;
11
- export declare const drawPolygon: (ctx: CanvasRenderingContext2D, polygon: DrawableShape<"polygon">) => void;
12
- export declare const getPolygonBorder: (polygon: Polygon, settings: UtilsSettings) => Rect;
13
- export declare const translatePolygon: <U extends DrawableShape<"polygon">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => U & {
14
- points: [number, number][];
15
- };
16
- export declare const resizePolygon: (cursorPosition: Point, originalShape: DrawableShape<"polygon">, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => DrawableShape<"polygon">;
17
- export declare const addPolygonLine: <T extends DrawableShape<"polygon">>(shape: T, lineIndex: number, cursorPosition: Point, settings: UtilsSettings) => T;
18
- export declare const addPolygonPoint: <T extends DrawableShape<"polygon">>(shape: T, cursorPosition: Point, settings: UtilsSettings, temporary?: boolean) => T;
19
+ export declare const drawPolygon: (ctx: CanvasRenderingContext2D, polygon: ShapeEntity<"polygon">) => void;
20
+ export declare const getPolygonBorder: (polygon: Polygon, settings: Pick<UtilsSettings, "selectionPadding">) => Rect;
21
+ export declare const translatePolygon: (cursorPosition: Point, originalShape: ShapeEntity<"polygon">, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => ShapeEntity<"polygon">;
22
+ export declare const resizePolygon: (cursorPosition: Point, originalShape: ShapeEntity<"polygon">, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => ShapeEntity<"polygon">;
23
+ export declare const addPolygonLine: (shape: ShapeEntity<"polygon">, lineIndex: number, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"polygon">;
24
+ export declare const addPolygonPoint: (shape: ShapeEntity<"polygon">, cursorPosition: Point, settings: UtilsSettings, temporary?: boolean) => ShapeEntity<"polygon">;
@@ -2,19 +2,64 @@ import type { UtilsSettings } from './../../../canvas/constants/app';
2
2
  import type { SelectionModeResize } from './../../../common/types/Mode';
3
3
  import type { DrawableShape, Point, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
4
  import type { ToolsSettingsType } from './../../../common/types/tools';
5
- type rectish = 'text' | 'rect' | 'square' | 'picture';
6
- export declare const refreshRect: <T extends DrawableShape<rectish>>(rect: T, settings: UtilsSettings) => T;
7
- export declare const createRectangle: <T extends "rect" | "square">(shape: {
5
+ type rectish = 'rect' | 'square';
6
+ export declare const getComputedRect: (rect: DrawableShape<rectish>, settings: UtilsSettings) => {
7
+ borders: Rect;
8
+ outerBorders: Rect;
9
+ center: Point;
10
+ boundingBox: Rect;
11
+ };
12
+ export declare const refreshRect: <T extends rectish>(rect: DrawableShape<T> & {
13
+ id: string;
14
+ }, settings: UtilsSettings, isGroup?: boolean) => ShapeEntity<T>;
15
+ export declare const createRectangle: <T extends rectish>(shape: {
8
16
  id: string;
9
17
  type: T;
10
18
  settings: ToolsSettingsType<T>;
11
- }, cursorPosition: Point, settings: UtilsSettings, width?: number, height?: number) => ShapeEntity<T>;
12
- export declare const drawRect: (ctx: CanvasRenderingContext2D, shape: DrawableShape<"rect" | "square">) => void;
13
- export declare const getRectBorder: (rect: Rect, settings: UtilsSettings) => Rect;
19
+ }, cursorPosition: Point, settings: UtilsSettings, isGroup?: boolean, width?: number, height?: number) => ShapeEntity<T>;
20
+ export declare const drawRect: (ctx: CanvasRenderingContext2D, shape: ShapeEntity<rectish>) => void;
21
+ export declare const getRectBorder: (rect: Rect, settings: Pick<UtilsSettings, "selectionPadding">) => Rect;
14
22
  export declare const getRectOppositeAnchorAbsolutePosition: <T extends DrawableShape & Rect>(anchor: Point, center: Point, shape: T, [negW, negH]?: [boolean, boolean]) => Point;
15
- export declare const translateRect: <T extends "rect" | "square", U extends DrawableShape<T>>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => U & {
16
- x: number;
17
- y: number;
18
- };
19
- export declare const resizeRect: <T extends rectish>(cursorPosition: Point, originalShape: DrawableShape<T>, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio?: boolean, resizeFromCenter?: boolean) => DrawableShape<T>;
23
+ export declare const translateRect: <T extends rectish>(cursorPosition: Point, originalShape: ShapeEntity<T>, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => ({
24
+ id: string;
25
+ computed: {
26
+ borders: Rect;
27
+ outerBorders: Rect;
28
+ center: Point;
29
+ boundingBox: Rect;
30
+ };
31
+ } & {
32
+ rotation?: number;
33
+ toolId?: string;
34
+ visible?: boolean;
35
+ locked?: boolean;
36
+ style?: import("./../../../common/types/Shapes").StyleShape | undefined;
37
+ } & Rect & {
38
+ type: "rect";
39
+ } & {
40
+ selection?: import("./../../../common/types/Shapes").SelectionDefaultType | undefined;
41
+ path?: Path2D | undefined;
42
+ type: "rect";
43
+ }) | ({
44
+ id: string;
45
+ computed: {
46
+ borders: Rect;
47
+ outerBorders: Rect;
48
+ center: Point;
49
+ boundingBox: Rect;
50
+ };
51
+ } & {
52
+ rotation?: number;
53
+ toolId?: string;
54
+ visible?: boolean;
55
+ locked?: boolean;
56
+ style?: import("./../../../common/types/Shapes").StyleShape | undefined;
57
+ } & Rect & {
58
+ type: "square";
59
+ } & {
60
+ selection?: import("./../../../common/types/Shapes").SelectionDefaultType | undefined;
61
+ path?: Path2D | undefined;
62
+ type: "square";
63
+ });
64
+ export declare const resizeRect: <T extends rectish>(cursorPosition: Point, originalShape: ShapeEntity<T>, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio?: boolean, resizeFromCenter?: boolean) => ShapeEntity<T>;
20
65
  export {};
@@ -2,7 +2,15 @@ import type { UtilsSettings } from './../../../canvas/constants/app';
2
2
  import type { SelectionModeResize } from './../../../common/types/Mode';
3
3
  import type { DrawableShape, Point, Rect, ShapeEntity, Text } from './../../../common/types/Shapes';
4
4
  import type { ToolsSettingsType } from './../../../common/types/tools';
5
- export declare const refreshText: <T extends DrawableShape<"text">>(shape: T, settings: UtilsSettings) => T;
5
+ export declare const getComputedText: (text: DrawableShape<"text">, settings: UtilsSettings) => {
6
+ borders: Rect;
7
+ outerBorders: Rect;
8
+ center: Point;
9
+ boundingBox: Rect;
10
+ };
11
+ export declare const refreshText: <T extends DrawableShape<"text">>(shape: T & {
12
+ id: string;
13
+ }, settings: UtilsSettings) => ShapeEntity<"text">;
6
14
  export declare const calculateTextFontSize: (ctx: CanvasRenderingContext2D, text: string[], maxWidth: number, fontBold: boolean, fontItalic: boolean, fontFamily?: string | undefined) => number;
7
15
  export declare const createText: (ctx: CanvasRenderingContext2D, shape: {
8
16
  id: string;
@@ -10,10 +18,7 @@ export declare const createText: (ctx: CanvasRenderingContext2D, shape: {
10
18
  settings: ToolsSettingsType<"text">;
11
19
  }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"text">;
12
20
  export declare const drawText: (ctx: CanvasRenderingContext2D, text: DrawableShape<"text">) => void;
13
- export declare const getTextBorder: (text: Text, settings: UtilsSettings) => Rect;
14
- export declare const translateText: <U extends DrawableShape<"text">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => U & {
15
- x: number;
16
- y: number;
17
- };
18
- export declare const resizeText: (ctx: CanvasRenderingContext2D, cursorPosition: Point, originalShape: DrawableShape<"text">, selectionMode: SelectionModeResize, settings: UtilsSettings, resizeFromCenter: boolean) => DrawableShape<"text">;
19
- export declare const resizeTextShapeWithNewContent: <U extends DrawableShape<"text">>(ctx: CanvasRenderingContext2D, shape: U, newValue: string[], settings: UtilsSettings) => U;
21
+ export declare const getTextBorder: (text: Text, settings: Pick<UtilsSettings, "selectionPadding">) => Rect;
22
+ export declare const translateText: (cursorPosition: Point, originalShape: ShapeEntity<"text">, originalCursorPosition: Point, settings: UtilsSettings, singleAxis: boolean) => ShapeEntity<"text">;
23
+ export declare const resizeText: (ctx: CanvasRenderingContext2D, cursorPosition: Point, originalShape: ShapeEntity<"text">, selectionMode: SelectionModeResize, settings: UtilsSettings, resizeFromCenter: boolean) => ShapeEntity<"text">;
24
+ export declare const resizeTextShapeWithNewContent: (ctx: CanvasRenderingContext2D, shape: ShapeEntity<"text">, newValue: string[], settings: UtilsSettings) => ShapeEntity<"text">;
@@ -1,3 +1,4 @@
1
- import type { DrawableShape, Triangle } from './../../../common/types/Shapes';
2
- export declare const createTriangle: (triangle: Triangle) => DrawableShape<"triangle">;
3
- export declare const drawTriangle: (ctx: CanvasRenderingContext2D, triangle: DrawableShape<"triangle">) => void;
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { Triangle, TriangleEntity } from './../../../common/types/Shapes';
3
+ export declare const createTriangle: (triangle: Triangle, settings: UtilsSettings) => TriangleEntity;
4
+ export declare const drawTriangle: (ctx: CanvasRenderingContext2D, triangle: TriangleEntity) => void;
@@ -1,14 +1,14 @@
1
1
  import type { UtilsSettings } from './../../canvas/constants/app';
2
2
  import type { SelectionModeData } from './../../common/types/Mode';
3
- import type { DrawableShape, Line, Point, ShapeEntity } from './../../common/types/Shapes';
3
+ import type { DrawableShape, Line, Point, SelectionType } from './../../common/types/Shapes';
4
4
  export declare const getNormalizedSize: (originalWidth: number, originalHeight: number, width: number, height: number) => number[];
5
5
  export declare const roundValues: (prop: number, precision?: number) => number;
6
6
  export declare const scalePoint: (point: Point, minX: number, minY: number, scaleX?: number, scaleY?: number) => Point;
7
7
  export declare const roundForGrid: (value: number, settings: UtilsSettings, gridOffset?: number) => number;
8
8
  export declare const roundRotationForGrid: (rotation: number, settings: UtilsSettings, isShiftPressed: boolean) => number;
9
- export declare const boundVectorToSingleAxis: (vector: Point, isShiftPressed: boolean) => number[];
10
- export declare const transformShape: (ctx: CanvasRenderingContext2D, shape: ShapeEntity, cursorPosition: Point, selectionMode: SelectionModeData<Point | number>, settings: UtilsSettings, isShiftPressed: boolean, isAltPressed: boolean) => ShapeEntity;
11
- export declare const fitContentInsideContainer: (contentWidth: number, contentHeight: number, containerWidth: number, containerHeight: number, shouldFillContainer?: boolean) => number[];
9
+ export declare const boundVectorToSingleAxis: (vector: Point, isShiftPressed: boolean) => Point;
10
+ export declare const transformShape: (ctx: CanvasRenderingContext2D, selectedShape: SelectionType, cursorPosition: Point, selectionMode: SelectionModeData<Point | number>, settings: UtilsSettings, isShiftPressed: boolean, isAltPressed: boolean) => SelectionType;
11
+ export declare const fitContentInsideContainer: (contentWidth: number, contentHeight: number, containerWidth: number, containerHeight: number, shouldFillContainer?: boolean) => Point;
12
12
  export declare const shortenLine: ({ line, size, direction }: {
13
13
  line: DrawableShape<"line">;
14
14
  size: number;
@@ -7,7 +7,7 @@ export declare const isCircleIntersectRect: (rect: Rect, circle: Circle) => bool
7
7
  export declare const rotatePoint: ({ origin, point, rotation }: {
8
8
  origin?: Point;
9
9
  point: Point;
10
- rotation: number;
10
+ rotation?: number | undefined;
11
11
  }) => Point;
12
12
  export declare const getAngleFromVector: ({ targetVector: [point1, point2], radian, originVector }: {
13
13
  targetVector: Vector;
@@ -1,4 +1,4 @@
1
- import type { Point, ShapeEntity } from './Shapes';
1
+ import type { Point, SelectionType } from './Shapes';
2
2
  export type SelectionModeDefault = {
3
3
  mode: 'default';
4
4
  };
@@ -18,19 +18,20 @@ export type SelectionModeEditText = {
18
18
  export type SelectionModeResize<AnchorType extends Point | number = Point> = {
19
19
  mode: 'resize';
20
20
  cursorStartPosition: Point;
21
- originalShape: ShapeEntity;
21
+ originalShape: SelectionType;
22
22
  anchor: AnchorType;
23
23
  };
24
24
  export type SelectionModeRotate = {
25
25
  mode: 'rotate';
26
26
  cursorStartPosition: Point;
27
- originalShape: ShapeEntity;
27
+ originalShape: SelectionType;
28
28
  center: Point;
29
29
  };
30
30
  export type SelectionModeTranslate = {
31
31
  mode: 'translate';
32
32
  cursorStartPosition: Point;
33
- originalShape: ShapeEntity;
33
+ originalShape: SelectionType;
34
+ dateStart: number;
34
35
  };
35
36
  export type SelectionModeData<AnchorType extends Point | number> = SelectionModeDefault | SelectionModeSelectionFrame | SelectionModeBrush | SelectionModeResize<AnchorType> | SelectionModeRotate | SelectionModeTranslate | SelectionModeEditText | SelectionModePreview;
36
37
  export type HoverModeData = {
@@ -22,11 +22,11 @@ export type Triangle = {
22
22
  };
23
23
  export type Polygon = {
24
24
  points: Point[];
25
- tempPoint?: Point;
25
+ tempPoint?: Point | undefined;
26
26
  };
27
27
  export type Curve = {
28
28
  points: Point[];
29
- tempPoint?: Point;
29
+ tempPoint?: Point | undefined;
30
30
  };
31
31
  export type Brush = {
32
32
  points: Point[][];
@@ -56,7 +56,7 @@ export type StyleShape = {
56
56
  };
57
57
  export type SelectionDefaultType = {
58
58
  border: Path2D;
59
- line: Path2D;
59
+ line: Path2D | undefined;
60
60
  shapePath: Path2D | undefined;
61
61
  anchors: Path2D[];
62
62
  };
@@ -66,62 +66,103 @@ export type SelectionLinesType = {
66
66
  anchors: Path2D[];
67
67
  };
68
68
  export type DrawableShape<T extends ShapeType = ShapeType> = {
69
+ rotation?: number;
69
70
  toolId?: string;
70
71
  visible?: boolean;
71
72
  locked?: boolean;
72
- rotation: number;
73
- style?: StyleShape;
73
+ style?: StyleShape | undefined;
74
74
  } & (T extends 'line' ? Line & {
75
75
  type: 'line';
76
- selection?: SelectionLinesType;
77
- path?: Path2D;
78
- arrows?: DrawableShape<'triangle'>[];
79
76
  } : T extends 'picture' ? Picture & {
80
- type: 'picture';
81
77
  img: HTMLImageElement;
82
- selection?: SelectionDefaultType;
78
+ type: 'picture';
83
79
  } : T extends 'text' ? Text & {
84
80
  type: 'text';
85
- selection?: SelectionDefaultType;
86
81
  } : T extends 'rect' ? Rect & {
87
82
  type: 'rect';
88
- selection?: SelectionDefaultType;
89
- path?: Path2D;
90
83
  } : T extends 'square' ? Rect & {
91
84
  type: 'square';
92
- selection?: SelectionDefaultType;
93
- path?: Path2D;
94
85
  } : T extends 'circle' ? Circle & {
95
86
  type: 'circle';
96
- selection?: SelectionDefaultType;
97
- path?: Path2D;
98
87
  } : T extends 'ellipse' ? Ellipse & {
99
88
  type: 'ellipse';
100
- selection?: SelectionDefaultType;
101
- path?: Path2D;
102
89
  } : T extends 'triangle' ? Triangle & {
103
90
  type: 'triangle';
104
- path?: Path2D;
105
91
  } : T extends 'polygon' ? Polygon & {
106
92
  type: 'polygon';
107
- selection?: SelectionLinesType;
108
- path?: Path2D;
109
93
  } : T extends 'curve' ? Curve & {
110
94
  type: 'curve';
111
- selection?: SelectionLinesType;
112
- path?: Path2D;
113
95
  } : T extends 'brush' ? Brush & {
114
96
  type: 'brush';
115
- selection?: SelectionDefaultType;
116
- path?: Path2D;
117
97
  scaleX?: number;
118
98
  scaleY?: number;
99
+ } : T extends 'group' ? Rect & {
100
+ shapes: ShapeEntity[];
101
+ type: 'group';
119
102
  } : never);
120
103
  export type ExportedDrawableShape<T extends ShapeType = ShapeType> = T extends 'picture' ? Omit<DrawableShape<'picture'>, 'img'> : DrawableShape<T>;
104
+ export type TriangleEntity = DrawableShape<'triangle'> & {
105
+ path: Path2D;
106
+ computed: {
107
+ borders: Rect;
108
+ outerBorders: Rect;
109
+ center: Point;
110
+ boundingBox: Rect;
111
+ };
112
+ };
121
113
  export type ShapeEntity<T extends Exclude<ShapeType, 'triangle'> = Exclude<ShapeType, 'triangle'>> = {
122
114
  id: string;
123
- toolId?: string;
124
- } & DrawableShape<T>;
115
+ computed: {
116
+ borders: Rect;
117
+ outerBorders: Rect;
118
+ center: Point;
119
+ boundingBox: Rect;
120
+ };
121
+ } & DrawableShape<T> & (T extends 'line' ? {
122
+ selection?: SelectionLinesType | undefined;
123
+ path?: Path2D | undefined;
124
+ arrows?: TriangleEntity[];
125
+ type: 'line';
126
+ } : T extends 'picture' ? {
127
+ img: HTMLImageElement;
128
+ selection?: SelectionDefaultType | undefined;
129
+ type: 'picture';
130
+ } : T extends 'text' ? {
131
+ selection?: SelectionDefaultType | undefined;
132
+ type: 'text';
133
+ } : T extends 'rect' ? {
134
+ selection?: SelectionDefaultType | undefined;
135
+ path?: Path2D | undefined;
136
+ type: 'rect';
137
+ } : T extends 'square' ? {
138
+ selection?: SelectionDefaultType | undefined;
139
+ path?: Path2D | undefined;
140
+ type: 'square';
141
+ } : T extends 'circle' ? {
142
+ selection?: SelectionDefaultType | undefined;
143
+ path?: Path2D | undefined;
144
+ type: 'circle';
145
+ } : T extends 'ellipse' ? {
146
+ selection?: SelectionDefaultType | undefined;
147
+ path?: Path2D | undefined;
148
+ type: 'ellipse';
149
+ } : T extends 'polygon' ? {
150
+ selection?: SelectionLinesType | undefined;
151
+ path?: Path2D | undefined;
152
+ type: 'polygon';
153
+ } : T extends 'curve' ? {
154
+ selection?: SelectionLinesType | undefined;
155
+ path?: Path2D | undefined;
156
+ type: 'curve';
157
+ } : T extends 'brush' ? {
158
+ selection?: SelectionDefaultType | undefined;
159
+ path?: Path2D | undefined;
160
+ type: 'brush';
161
+ } : T extends 'group' ? {
162
+ selection?: SelectionDefaultType | undefined;
163
+ path?: Path2D | undefined;
164
+ type: 'group';
165
+ } : never);
125
166
  export type StateData = {
126
167
  shapes?: DrawableShape[];
127
168
  config?: {
@@ -129,3 +170,4 @@ export type StateData = {
129
170
  height: number;
130
171
  };
131
172
  };
173
+ export type SelectionType = ShapeEntity;
@@ -68,6 +68,9 @@ export type CustomTool = {
68
68
  } | {
69
69
  type: 'picture';
70
70
  settings: ToolsSettingsType<'picture'>;
71
+ } | {
72
+ type: 'group';
73
+ settings: ToolsSettingsType<'group'>;
71
74
  });
72
75
  export type SettingsOpacity = {
73
76
  opacity: {
@@ -149,7 +152,8 @@ export type ToolsPolygonSettings = SettingsOpacity & SettingsStrokeColor & Setti
149
152
  export type ToolsCurveSettings = SettingsOpacity & SettingsStrokeColor & SettingsFillColor & SettingsLineWidth & SettingsLineDash & SettingsClosedPoints;
150
153
  export type ToolsTriangleSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash;
151
154
  export type ToolsPictureSettings = SettingsOpacity;
152
- export type ToolsSettingsType<T extends ShapeType> = T extends 'rect' ? ToolsRectSettings : T extends 'square' ? ToolsSquareSettings : T extends 'circle' ? ToolsCircleSettings : T extends 'ellipse' ? ToolsEllipseSettings : T extends 'text' ? ToolsTextSettings : T extends 'line' ? ToolsLineSettings : T extends 'brush' ? ToolsBrushSettings : T extends 'polygon' ? ToolsPolygonSettings : T extends 'curve' ? ToolsCurveSettings : T extends 'triangle' ? ToolsTriangleSettings : T extends 'picture' ? ToolsPictureSettings : never;
155
+ export type ToolsGroupSettings = Partial<SettingsOpacity & SettingsStrokeColor & SettingsFillColor & SettingsLineWidth & SettingsLineDash & SettingsLineArrow>;
156
+ export type ToolsSettingsType<T extends ShapeType> = T extends 'rect' ? ToolsRectSettings : T extends 'square' ? ToolsSquareSettings : T extends 'circle' ? ToolsCircleSettings : T extends 'ellipse' ? ToolsEllipseSettings : T extends 'text' ? ToolsTextSettings : T extends 'line' ? ToolsLineSettings : T extends 'brush' ? ToolsBrushSettings : T extends 'polygon' ? ToolsPolygonSettings : T extends 'curve' ? ToolsCurveSettings : T extends 'triangle' ? ToolsTriangleSettings : T extends 'picture' ? ToolsPictureSettings : T extends 'group' ? ToolsGroupSettings : never;
153
157
  export type ActionsType = 'selection' | 'undo' | 'redo' | 'clear' | 'export' | 'loadfile' | 'savefile' | 'move' | 'uploadpicture' | 'addurlpicture';
154
158
  export type ActionsTool = {
155
159
  id: string;
@@ -1,4 +1,4 @@
1
1
  export type RecursivePartial<T> = {
2
- [P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P];
2
+ [P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P] | undefined;
3
3
  };
4
4
  export type ValueOf<T> = T[keyof T];
@@ -1,16 +1,16 @@
1
1
  import React from 'react';
2
2
  import './Button.css';
3
3
  type CommonType = {
4
- hidden?: boolean;
5
- disabled?: boolean;
6
- selected?: boolean;
7
- icon?: string;
4
+ hidden?: boolean | undefined;
5
+ disabled?: boolean | undefined;
6
+ selected?: boolean | undefined;
7
+ icon?: string | undefined;
8
8
  };
9
9
  type ButtonType = CommonType & React.ButtonHTMLAttributes<HTMLButtonElement>;
10
- type FileInputType = CommonType & {
10
+ export type FileInputType = CommonType & {
11
11
  type: 'file' | 'color';
12
12
  accept?: string;
13
13
  onClick?: React.MouseEventHandler<HTMLElement>;
14
14
  } & React.InputHTMLAttributes<HTMLInputElement | HTMLButtonElement>;
15
- declare const Button: React.ForwardRefExoticComponent<(ButtonType | FileInputType) & React.RefAttributes<HTMLButtonElement | HTMLInputElement>>;
15
+ declare const Button: React.ForwardRefExoticComponent<(FileInputType | ButtonType) & React.RefAttributes<HTMLButtonElement | HTMLInputElement>>;
16
16
  export default Button;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import './Button.css';
3
+ declare const FileInput: React.ForwardRefExoticComponent<{
4
+ hidden?: boolean | undefined;
5
+ disabled?: boolean | undefined;
6
+ selected?: boolean | undefined;
7
+ icon?: string | undefined;
8
+ } & {
9
+ type: "file" | "color";
10
+ accept?: string;
11
+ onClick?: React.MouseEventHandler<HTMLElement>;
12
+ } & React.InputHTMLAttributes<HTMLButtonElement | HTMLInputElement> & React.RefAttributes<HTMLButtonElement | HTMLInputElement>>;
13
+ export default FileInput;
@@ -9,7 +9,7 @@ type PanelType = {
9
9
  className?: string;
10
10
  fitContainer?: boolean;
11
11
  position?: 'bottom' | 'top';
12
- alignment?: 'left' | 'right' | 'center';
12
+ alignment?: 'left' | 'right' | 'center' | undefined;
13
13
  };
14
14
  declare const Panel: ({ children, title, className, position, fitContainer, alignment, style, ...props }: PanelType) => import("react/jsx-runtime").JSX.Element;
15
15
  export default Panel;
@@ -2,7 +2,7 @@ import type React from 'react';
2
2
  type ClosedPointsType = {
3
3
  selectedSettings: string | undefined;
4
4
  setSelectedSettings: React.Dispatch<React.SetStateAction<string | undefined>>;
5
- disabled?: boolean;
5
+ disabled?: boolean | undefined;
6
6
  defaultValue?: number | undefined;
7
7
  valueChanged: (field: string, value: string | number) => void;
8
8
  };
@@ -4,7 +4,7 @@ type ShapeStyleColorType = {
4
4
  selectedSettings: string | undefined;
5
5
  setSelectedSettings: React.Dispatch<React.SetStateAction<string | undefined>>;
6
6
  title?: string;
7
- disabled?: boolean;
7
+ disabled?: boolean | undefined;
8
8
  field: string;
9
9
  mode?: 'fill' | 'stroke';
10
10
  value?: string | undefined;
@@ -1,8 +1,8 @@
1
- import type { ShapeEntity } from './../../../common/types/Shapes';
1
+ import type { SelectionType, ShapeEntity } from './../../../common/types/Shapes';
2
2
  type DeleteShapeButtonType = {
3
3
  disabled?: boolean;
4
- selectedShape: ShapeEntity;
5
- removeShape: (shape: ShapeEntity) => void;
4
+ selectedShape: SelectionType;
5
+ removeShape: (shape: ShapeEntity[]) => void;
6
6
  };
7
7
  declare const DeleteButton: ({ disabled, selectedShape, removeShape }: DeleteShapeButtonType) => import("react/jsx-runtime").JSX.Element;
8
8
  export default DeleteButton;
@@ -3,7 +3,7 @@ import './FontFamilyField.css';
3
3
  type FontFamilyFieldType = {
4
4
  selectedSettings: string | undefined;
5
5
  setSelectedSettings: React.Dispatch<React.SetStateAction<string | undefined>>;
6
- disabled?: boolean;
6
+ disabled?: boolean | undefined;
7
7
  values: string[];
8
8
  defaultValue?: number | string | undefined;
9
9
  valueChanged: (field: string, value: string | number) => void;
@@ -1,4 +1,4 @@
1
- import type { ShapeEntity } from './../../../common/types/Shapes';
1
+ import type { SelectionType, ShapeEntity } from './../../../common/types/Shapes';
2
2
  import type { GridLabelType } from './../../../editor/constants/grid';
3
3
  import './Layouts.css';
4
4
  import type { UtilsSettings } from './../../../canvas/constants/app';
@@ -7,13 +7,13 @@ type LayoutsType = {
7
7
  setGridFormat: (value: GridLabelType) => void;
8
8
  settings: UtilsSettings;
9
9
  shapes: ShapeEntity[];
10
- removeShape: (shape: ShapeEntity) => void;
11
- toggleShapeVisibility: (shape: ShapeEntity) => void;
12
- toggleShapeLock: (shape: ShapeEntity) => void;
13
- selectedShape: ShapeEntity | undefined;
14
- selectShape: (shape: ShapeEntity) => void;
10
+ removeShape: (shape: ShapeEntity[]) => void;
11
+ toggleShapeVisibility: (shape: ShapeEntity[]) => void;
12
+ toggleShapeLock: (shape: ShapeEntity[]) => void;
13
+ selectedShapes: SelectionType | undefined;
14
+ selectShapes: (shapes: ShapeEntity[]) => void;
15
15
  moveShapes: (firstShapeId: string, lastShapeId: string) => void;
16
16
  isLayoutPanelShown: boolean;
17
17
  };
18
- declare const Layouts: ({ gridFormat, setGridFormat, settings, shapes, removeShape, toggleShapeVisibility, toggleShapeLock, selectedShape, moveShapes, selectShape, isLayoutPanelShown }: LayoutsType) => import("react/jsx-runtime").JSX.Element | null;
18
+ declare const Layouts: ({ gridFormat, setGridFormat, settings, shapes, removeShape, toggleShapeVisibility, toggleShapeLock, selectedShapes, moveShapes, selectShapes, isLayoutPanelShown }: LayoutsType) => import("react/jsx-runtime").JSX.Element | null;
19
19
  export default Layouts;
@@ -3,7 +3,7 @@ import './LineArrowField.css';
3
3
  type LineArrowType = {
4
4
  selectedSettings: string | undefined;
5
5
  setSelectedSettings: React.Dispatch<React.SetStateAction<string | undefined>>;
6
- disabled?: boolean;
6
+ disabled?: boolean | undefined;
7
7
  values: number[];
8
8
  defaultValue?: number | string | undefined;
9
9
  valueChanged: (field: string, value: string | number) => void;