@yorab/react-paint 0.9.2 → 0.10.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 (38) hide show
  1. package/README.md +1 -1
  2. package/dist/components/App.d.ts +1 -1
  3. package/dist/components/Canvas.d.ts +9 -2
  4. package/dist/components/settings/RangeField.d.ts +1 -1
  5. package/dist/constants/app.d.ts +4 -0
  6. package/dist/hooks/useDrawableCanvas.d.ts +7 -3
  7. package/dist/hooks/useShapes.d.ts +6 -1
  8. package/dist/react-paint.css +1 -1
  9. package/dist/react-paint.js +1202 -8720
  10. package/dist/react-paint.umd.cjs +1 -27
  11. package/dist/types/Mode.d.ts +6 -1
  12. package/dist/types/Shapes.d.ts +5 -3
  13. package/dist/types/react.d.ts +0 -1
  14. package/dist/utils/array.d.ts +1 -0
  15. package/dist/utils/canvas.d.ts +3 -2
  16. package/dist/utils/intersect.d.ts +6 -2
  17. package/dist/utils/object.d.ts +4 -0
  18. package/dist/utils/selection/lineSelection.d.ts +2 -2
  19. package/dist/utils/selection/rectSelection.d.ts +3 -3
  20. package/dist/utils/selection/selectionFrame.d.ts +2 -0
  21. package/dist/utils/selection.d.ts +1 -1
  22. package/dist/utils/shapes/brush.d.ts +1 -1
  23. package/dist/utils/shapes/circle.d.ts +1 -1
  24. package/dist/utils/shapes/curve.d.ts +2 -1
  25. package/dist/utils/shapes/ellipse.d.ts +1 -1
  26. package/dist/utils/shapes/index.d.ts +8 -2
  27. package/dist/utils/shapes/line.d.ts +1 -1
  28. package/dist/utils/shapes/path.d.ts +1 -1
  29. package/dist/utils/shapes/picture.d.ts +2 -2
  30. package/dist/utils/shapes/polygon.d.ts +2 -2
  31. package/dist/utils/shapes/rectangle.d.ts +2 -2
  32. package/dist/utils/shapes/text.d.ts +3 -3
  33. package/dist/utils/style.d.ts +1 -1
  34. package/dist/utils/transform.d.ts +8 -2
  35. package/dist/utils/trigo.d.ts +2 -1
  36. package/dist/utils/util.d.ts +1 -0
  37. package/package.json +55 -72
  38. package/dist/utils/migration.d.ts +0 -147
@@ -2,6 +2,9 @@ import type { Point, ShapeEntity } from './Shapes';
2
2
  export type SelectionModeDefault = {
3
3
  mode: 'default';
4
4
  };
5
+ export type SelectionModeSelectionFrame = {
6
+ mode: 'selectionFrame';
7
+ };
5
8
  export type SelectionModeBrush = {
6
9
  mode: 'brush';
7
10
  };
@@ -26,9 +29,11 @@ export type SelectionModeTranslate = {
26
29
  cursorStartPosition: Point;
27
30
  originalShape: ShapeEntity;
28
31
  };
29
- export type SelectionModeData<AnchorType extends Point | number> = SelectionModeDefault | SelectionModeBrush | SelectionModeResize<AnchorType> | SelectionModeRotate | SelectionModeTranslate | SelectionModeEditText;
32
+ export type SelectionModeData<AnchorType extends Point | number> = SelectionModeDefault | SelectionModeSelectionFrame | SelectionModeBrush | SelectionModeResize<AnchorType> | SelectionModeRotate | SelectionModeTranslate | SelectionModeEditText;
30
33
  export type HoverModeData = {
31
34
  mode: 'default';
35
+ } | {
36
+ mode: 'selectionFrame';
32
37
  } | {
33
38
  mode: 'resize';
34
39
  anchor: Point | number;
@@ -1,5 +1,5 @@
1
1
  import { ShapeTypeArray } from '../constants/shapes';
2
- export type ShapeType = typeof ShapeTypeArray[number];
2
+ export type ShapeType = (typeof ShapeTypeArray)[number];
3
3
  export type Point = [number, number];
4
4
  export type Rect = {
5
5
  x: number;
@@ -42,7 +42,7 @@ export type Ellipse = {
42
42
  };
43
43
  export type StyleShape = {
44
44
  fillColor?: string;
45
- globalAlpha?: number;
45
+ opacity?: number;
46
46
  strokeColor?: string;
47
47
  lineWidth?: number;
48
48
  lineDash?: number;
@@ -55,10 +55,12 @@ export type StyleShape = {
55
55
  export type SelectionDefaultType = {
56
56
  border: Path2D;
57
57
  line: Path2D;
58
+ shapePath: Path2D | undefined;
58
59
  anchors: Path2D[];
59
60
  };
60
61
  export type SelectionLinesType = {
61
62
  border: Path2D;
63
+ shapePath: Path2D | undefined;
62
64
  anchors: Path2D[];
63
65
  };
64
66
  export type DrawableShape<T extends ShapeType = ShapeType> = {
@@ -120,7 +122,7 @@ export type ShapeEntity<T extends Exclude<ShapeType, 'triangle'> = Exclude<Shape
120
122
  toolId?: string;
121
123
  } & DrawableShape<T>;
122
124
  export type ExportDataType = {
123
- shapes: DrawableShapeJson[];
125
+ shapes?: DrawableShapeJson[];
124
126
  config?: {
125
127
  width: number;
126
128
  height: number;
@@ -4,4 +4,3 @@ declare module 'react' {
4
4
  [key: `--${string}`]: string | number;
5
5
  }
6
6
  }
7
- export {};
@@ -0,0 +1 @@
1
+ export declare const compact: <T>(array: (T | null | undefined)[]) => T[];
@@ -2,9 +2,10 @@ import type { Point } from '../types/Shapes';
2
2
  export declare const initCanvasContext: (ctx: CanvasRenderingContext2D) => void;
3
3
  export declare const updateCanvasContext: (ctx: CanvasRenderingContext2D, style?: {
4
4
  fillColor?: string;
5
- globalAlpha?: number;
5
+ opacity?: number;
6
6
  strokeColor?: string;
7
7
  lineWidth?: number;
8
8
  lineDash?: number;
9
+ lineCap?: CanvasLineCap;
9
10
  }) => void;
10
- export declare const transformCanvas: (ctx: CanvasRenderingContext2D, responsiveScale: number, canvasOffset: Point, rotation: number, translation: Point) => void;
11
+ export declare const transformCanvas: (ctx: CanvasRenderingContext2D, responsiveScale: number, canvasOffset: Point, rotation?: number, translation?: Point) => void;
@@ -1,6 +1,10 @@
1
1
  import type { HoverModeData } from '../types/Mode';
2
- import type { Point, DrawableShape } from '../types/Shapes';
2
+ import type { DrawableShape, Point, Rect } from '../types/Shapes';
3
3
  export declare const getCursorPosition: (e: MouseEvent | TouchEvent, canvas: HTMLCanvasElement | null, givenWidth: number, givenHeight: number, scaleRatio?: number) => Point;
4
+ export declare const isTouchGesture: (e: MouseEvent | TouchEvent) => e is TouchEvent;
4
5
  export declare const getPointPositionAfterCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point, [canvasOffsetX, canvasOffsetY]: Point) => Point;
5
6
  export declare const getPointPositionBeforeCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point, [canvasOffsetX, canvasOffsetY]: Point) => Point;
6
- export declare const checkPositionIntersection: (shape: DrawableShape, position: Point, canvasOffset: Point, selectionPadding: number, currentScale?: number, checkAnchors?: boolean) => false | HoverModeData;
7
+ export declare const checkSelectionIntersection: (shape: DrawableShape, position: Point, canvasOffset: Point, selectionPadding: number, currentScale: number, checkAnchors?: boolean, radius?: number) => false | HoverModeData;
8
+ export declare const checkPositionIntersection: (ctx: CanvasRenderingContext2D, shape: DrawableShape, position: Point, canvasOffset: Point, selectionPadding: number, currentScale: number) => false | HoverModeData;
9
+ export declare function getRectIntersection(rect1: Rect, rect2: Rect): Rect | undefined;
10
+ export declare const checkSelectionFrameCollision: (ctx: CanvasRenderingContext2D, shape: DrawableShape, selectionFrame: [Point, Point], canvasOffset: Point, selectionPadding: number) => boolean;
@@ -0,0 +1,4 @@
1
+ export declare const omit: <T extends Record<string, unknown>>(keys: string[], obj: T) => T;
2
+ export declare const set: <T extends Record<string, any> | unknown[]>(path: string | number | (string | number)[], value: unknown, obj: T) => T;
3
+ export declare const mergeWith: (customMergeFn: (objValue: unknown, srcValue: unknown, key: string) => unknown, target: unknown, source: unknown) => unknown;
4
+ export declare const isEqual: (a: unknown, b: unknown) => boolean;
@@ -1,5 +1,5 @@
1
- import { DrawableShape, Point, SelectionLinesType } from "src/types/Shapes";
2
- export declare const createLineSelectionPath: (shape: DrawableShape & {
1
+ import { DrawableShape, Point, SelectionLinesType } from 'src/types/Shapes';
2
+ export declare const createLineSelectionPath: (path: Path2D | undefined, shape: DrawableShape<'line' | 'polygon' | 'curve'> & {
3
3
  points: readonly Point[];
4
4
  }, currentScale: number, selectionPadding: number, gravityAnchors?: boolean) => SelectionLinesType;
5
5
  export declare const drawLineSelection: ({ ctx, shape, withAnchors, selectionWidth, selectionColor, currentScale }: {
@@ -1,7 +1,7 @@
1
- import type { Point, DrawableShape, SelectionDefaultType } from '../../types/Shapes';
2
- import type { SelectionModeResize } from '../../types/Mode';
3
1
  import type { GridFormatType } from '../../constants/app';
4
- export declare const createRecSelectionPath: (rect: DrawableShape, currentScale: number, selectionPadding: number) => SelectionDefaultType;
2
+ import type { SelectionModeResize } from '../../types/Mode';
3
+ import type { DrawableShape, Point, SelectionDefaultType } from '../../types/Shapes';
4
+ export declare const createRecSelectionPath: (path: Path2D | undefined, rect: DrawableShape, currentScale: number, selectionPadding: number) => SelectionDefaultType;
5
5
  export declare const drawSelectionRect: (ctx: CanvasRenderingContext2D, shape: DrawableShape & {
6
6
  selection?: SelectionDefaultType;
7
7
  }, selectionColor: string, selectionWidth: number, currentScale: number, withAnchors: boolean) => void;
@@ -0,0 +1,2 @@
1
+ import type { Point } from '../../types/Shapes';
2
+ export declare const drawFrame: (ctx: CanvasRenderingContext2D, selectionFrame: [Point, Point], currentScale: number) => void;
@@ -1,7 +1,7 @@
1
1
  import type { HoverModeData, SelectionModeData } from '../types/Mode';
2
2
  import type { Point, ShapeEntity } from '../types/Shapes';
3
3
  export declare const getNewSelectionData: (hoverMode: HoverModeData, selectedShape: ShapeEntity, cursorPosition: Point, selectionPadding: number) => SelectionModeData<Point | number> | undefined;
4
- export declare const selectShape: (shapes: ShapeEntity[], cursorPosition: Point, currentScale: number, canvasOffset: Point, selectedShape: ShapeEntity | undefined, selectionPadding: number) => {
4
+ export declare const selectShape: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], cursorPosition: Point, currentScale: number, canvasOffset: Point, selectedShape: ShapeEntity | undefined, selectionPadding: number, isTouchGesture: boolean, withFrameSelection: boolean) => {
5
5
  mode: SelectionModeData<Point | number>;
6
6
  shape: ShapeEntity | undefined;
7
7
  };
@@ -1,6 +1,6 @@
1
1
  import { GridFormatType } from '../../constants/app';
2
2
  import { SelectionModeResize } from '../../types/Mode';
3
- import type { Point, Rect, DrawableShape, ShapeEntity } from '../../types/Shapes';
3
+ import type { DrawableShape, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
4
  import type { ToolsSettingsType } from '../../types/tools';
5
5
  export declare const refreshBrush: <T extends DrawableShape<"brush">>(brush: T, currentScale: number, selectionPadding: number) => T;
6
6
  export declare const createBrush: (shape: {
@@ -1,6 +1,6 @@
1
1
  import { GridFormatType } from '../../constants/app';
2
2
  import { SelectionModeResize } from '../../types/Mode';
3
- import type { Point, Circle, Rect, DrawableShape, ShapeEntity } from '../../types/Shapes';
3
+ import type { Circle, DrawableShape, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
4
  import type { ToolsSettingsType } from '../../types/tools';
5
5
  export declare const refreshCircle: <T extends DrawableShape<"circle">>(shape: T, currentScale: number, selectionPadding: number) => T;
6
6
  export declare const createCircle: (shape: {
@@ -1,6 +1,6 @@
1
1
  import { GridFormatType } from '../../constants/app';
2
2
  import { SelectionModeResize } from '../../types/Mode';
3
- import type { Point, DrawableShape, ShapeEntity } from '../../types/Shapes';
3
+ import type { DrawableShape, Point, ShapeEntity } from '../../types/Shapes';
4
4
  import type { ToolsSettingsType } from '../../types/tools';
5
5
  export declare const refreshCurve: <T extends DrawableShape<"curve">>(shape: T, currentScale: number, selectionPadding: number) => T;
6
6
  export declare const createCurve: (shape: {
@@ -14,3 +14,4 @@ export declare const getCurveBorder: (polygon: import("../../types/Shapes").Poly
14
14
  export declare const translateCurve: <U extends DrawableShape<"curve">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, gridFormat: GridFormatType, currentScale: number, selectionPadding: number) => U & {
15
15
  points: [number, number][];
16
16
  };
17
+ export declare const updateCurveLinesCount: <T extends DrawableShape<"curve">>(shape: T, newPointsCount: number, currentScale: number, selectionPadding: number) => T;
@@ -1,6 +1,6 @@
1
1
  import { GridFormatType } from '../../constants/app';
2
2
  import { SelectionModeResize } from '../../types/Mode';
3
- import type { Point, Ellipse, Rect, DrawableShape, ShapeEntity } from '../../types/Shapes';
3
+ import type { DrawableShape, Ellipse, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
4
  import type { ToolsSettingsType } from '../../types/tools';
5
5
  export declare const refreshEllipse: <T extends DrawableShape<"ellipse">>(shape: T, currentScale: number, selectionPadding: number) => T;
6
6
  export declare const createEllipse: (shape: {
@@ -1,7 +1,7 @@
1
- import type { Point, DrawableShape, Rect, ShapeEntity } from '../../types/Shapes';
2
- import type { CustomTool } from '../../types/tools';
3
1
  import type { GridFormatType } from '../../constants/app';
4
2
  import { SelectionModeData } from '../../types/Mode';
3
+ import type { DrawableShape, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
+ import type { CustomTool } from '../../types/tools';
5
5
  export declare const createShape: (ctx: CanvasRenderingContext2D, shape: Exclude<CustomTool, {
6
6
  type: 'picture';
7
7
  }>, cursorPosition: Point, gridFormat: GridFormatType, currentScale: number, selectionPadding: number) => ShapeEntity;
@@ -26,4 +26,10 @@ export declare const drawShapeSelection: ({ ctx, shape, currentScale, canvasOffs
26
26
  selectionColor: string;
27
27
  withAnchors?: boolean | undefined;
28
28
  }) => void;
29
+ export declare const drawSelectionFrame: ({ ctx, selectionFrame, currentScale, canvasOffset }: {
30
+ ctx: CanvasRenderingContext2D;
31
+ selectionFrame: [Point, Point];
32
+ currentScale: number;
33
+ canvasOffset: Point;
34
+ }) => void;
29
35
  export declare const copyShape: (shape: ShapeEntity, gridFormat: GridFormatType, currentScale: number, selectionPadding: number) => ShapeEntity;
@@ -1,6 +1,6 @@
1
1
  import { GridFormatType } from '../../constants/app';
2
2
  import { SelectionModeResize } from '../../types/Mode';
3
- import type { Point, DrawableShape, Line, Triangle, ShapeEntity, Rect, StyleShape } from '../../types/Shapes';
3
+ import type { DrawableShape, Line, Point, Rect, ShapeEntity, StyleShape, Triangle } from '../../types/Shapes';
4
4
  import type { ToolsSettingsType } from '../../types/tools';
5
5
  export declare const refreshLine: <T extends DrawableShape<"line">>(line: T, currentScale: number, selectionPadding: number) => T;
6
6
  export declare const createLine: (shape: {
@@ -1,4 +1,4 @@
1
- import { Circle, DrawableShape, Line, Rect } from "../../types/Shapes";
1
+ import { Circle, DrawableShape, Line, Rect } from '../../types/Shapes';
2
2
  export declare const createRecPath: (rect: Rect) => Path2D;
3
3
  export declare const createCirclePath: (shape: Circle) => Path2D;
4
4
  export declare const createEllipsePath: (ellipse: DrawableShape<'ellipse'>) => Path2D;
@@ -1,6 +1,6 @@
1
- import type { DrawableShape, Picture, Point, Rect, ShapeEntity } from '../../types/Shapes';
2
- import { SelectionModeResize } from '../../types/Mode';
3
1
  import { GridFormatType } from '../../constants/app';
2
+ import { SelectionModeResize } from '../../types/Mode';
3
+ import type { DrawableShape, Picture, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
4
  export declare const refreshPicture: <T extends DrawableShape<"picture">>(shape: T, currentScale: number, selectionPadding: number) => T;
5
5
  export declare const createPicture: (fileOrUrl: File | string, maxPictureWidth: number, maxPictureHeight: number, currentScale: number, selectionPadding: number) => Promise<ShapeEntity<"picture">>;
6
6
  export declare const drawPicture: (ctx: CanvasRenderingContext2D, picture: DrawableShape<'picture'>) => void;
@@ -1,6 +1,6 @@
1
1
  import { GridFormatType } from '../../constants/app';
2
2
  import { SelectionModeResize } from '../../types/Mode';
3
- import type { Point, DrawableShape, Polygon, Rect, ShapeEntity } from '../../types/Shapes';
3
+ import type { DrawableShape, Point, Polygon, Rect, ShapeEntity } from '../../types/Shapes';
4
4
  import type { ToolsSettingsType } from '../../types/tools';
5
5
  export declare const refreshPolygon: <T extends DrawableShape<"polygon">>(shape: T, currentScale: number, selectionPadding: number) => T;
6
6
  export declare const createPolygon: (shape: {
@@ -11,7 +11,7 @@ export declare const createPolygon: (shape: {
11
11
  export declare const drawPolygon: (ctx: CanvasRenderingContext2D, polygon: DrawableShape<'polygon'>) => void;
12
12
  export declare const getPolygonBorder: (polygon: Polygon, selectionPadding: number) => Rect;
13
13
  export declare const translatePolygon: <U extends DrawableShape<"polygon">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, gridFormat: GridFormatType, currentScale: number, selectionPadding: number) => U & {
14
- points: Point[];
14
+ points: [number, number][];
15
15
  };
16
16
  export declare const resizePolygon: (cursorPosition: Point, canvasOffset: Point, originalShape: DrawableShape<'polygon'>, selectionMode: SelectionModeResize<number>, gridFormat: GridFormatType, selectionPadding: number, currentScale: number) => DrawableShape<'polygon'>;
17
17
  export declare const updatePolygonLinesCount: <T extends DrawableShape<"polygon">>(shape: T, newPointsCount: number, currentScale: number, selectionPadding: number) => T;
@@ -1,6 +1,6 @@
1
1
  import type { GridFormatType } from '../../constants/app';
2
2
  import type { SelectionModeResize } from '../../types/Mode';
3
- import type { Point, DrawableShape, ShapeEntity, Rect } from '../../types/Shapes';
3
+ import type { DrawableShape, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
4
  import type { ToolsSettingsType } from '../../types/tools';
5
5
  type rectish = 'text' | 'rect' | 'square' | 'picture';
6
6
  export declare const refreshRect: <T extends DrawableShape<rectish>>(rect: T, currentScale: number, selectionPadding: number) => T;
@@ -8,7 +8,7 @@ export declare const createRectangle: <T extends "rect" | "square">(shape: {
8
8
  id: string;
9
9
  type: T;
10
10
  settings: ToolsSettingsType<T>;
11
- }, cursorPosition: Point, currentScale: number, selectionPadding: number) => ShapeEntity<T>;
11
+ }, cursorPosition: Point, currentScale: number, selectionPadding: number, width?: number, height?: number) => ShapeEntity<T>;
12
12
  export declare const drawRect: (ctx: CanvasRenderingContext2D, shape: DrawableShape<'rect' | 'square'>) => void;
13
13
  export declare const getRectBorder: (rect: Rect, selectionPadding: number) => Rect;
14
14
  export declare const getRectOppositeAnchorAbsolutePosition: <T extends DrawableShape & Rect>(anchor: Point, center: Point, shape: T, canvasOffset: Point, [negW, negH]?: [boolean, boolean]) => Point;
@@ -1,7 +1,7 @@
1
- import type { Point, DrawableShape, Text, Rect, ShapeEntity } from '../../types/Shapes';
2
- import type { ToolsSettingsType } from '../../types/tools';
3
- import { SelectionModeResize } from '../../types/Mode';
4
1
  import { GridFormatType } from '../../constants/app';
2
+ import { SelectionModeResize } from '../../types/Mode';
3
+ import type { DrawableShape, Point, Rect, ShapeEntity, Text } from '../../types/Shapes';
4
+ import type { ToolsSettingsType } from '../../types/tools';
5
5
  export declare const refreshText: <T extends DrawableShape<"text">>(shape: T, currentScale: number, selectionPadding: number) => T;
6
6
  export declare const calculateTextFontSize: (ctx: CanvasRenderingContext2D, text: string[], maxWidth: number, fontBold: boolean, fontItalic: boolean, fontFamily?: string | undefined) => number;
7
7
  export declare const createText: (ctx: CanvasRenderingContext2D, shape: {
@@ -1,2 +1,2 @@
1
1
  import type { ShapeType } from '../types/Shapes';
2
- export declare const getShapePicture: (shape: ShapeType) => "" | "<svg><path d=\"M5.146 17.5Q4.146 17.5 3.208 17Q2.271 16.5 1.667 15.708Q2.208 15.75 2.802 15.344Q3.396 14.938 3.396 14.104Q3.396 13.042 4.135 12.292Q4.875 11.542 5.958 11.542Q7.021 11.542 7.76 12.292Q8.5 13.042 8.5 14.104Q8.5 15.5 7.51 16.5Q6.521 17.5 5.146 17.5ZM9.917 12.5 7.562 10.146 14.917 2.729Q15.146 2.5 15.469 2.5Q15.792 2.5 16.021 2.729L17.271 3.958Q17.5 4.188 17.5 4.531Q17.5 4.875 17.271 5.125Z\"/></svg>" | "<svg><path d=\"M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z\"/></svg>" | "<svg><path d=\"M10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333ZM10 16.583Q12.75 16.583 14.667 14.667Q16.583 12.75 16.583 10Q16.583 7.25 14.667 5.333Q12.75 3.417 10 3.417Q7.25 3.417 5.333 5.333Q3.417 7.25 3.417 10Q3.417 12.75 5.333 14.667Q7.25 16.583 10 16.583ZM10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Z\"/></svg>" | "<svg><path d=\"M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z\"/></svg>" | "<svg><path d=\"M4.792 15.083 8.333 11.542 9.833 13.021 11.667 10.708 15.167 15.083ZM6.667 8.417Q5.938 8.417 5.427 7.906Q4.917 7.396 4.917 6.667Q4.917 5.938 5.427 5.427Q5.938 4.917 6.667 4.917Q7.396 4.917 7.906 5.427Q8.417 5.938 8.417 6.667Q8.417 7.396 7.906 7.906Q7.396 8.417 6.667 8.417ZM4.167 18.333Q3.125 18.333 2.396 17.604Q1.667 16.875 1.667 15.833V4.167Q1.667 3.125 2.396 2.396Q3.125 1.667 4.167 1.667H15.833Q16.875 1.667 17.604 2.396Q18.333 3.125 18.333 4.167V15.833Q18.333 16.875 17.604 17.604Q16.875 18.333 15.833 18.333ZM4.167 16.583H15.833Q16.146 16.583 16.365 16.365Q16.583 16.146 16.583 15.833V4.167Q16.583 3.854 16.365 3.635Q16.146 3.417 15.833 3.417H4.167Q3.854 3.417 3.635 3.635Q3.417 3.854 3.417 4.167V15.833Q3.417 16.146 3.635 16.365Q3.854 16.583 4.167 16.583Z\"/></svg>" | "<svg><path d=\"M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z\"/></svg>" | "<svg><path d=\"M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z\"/></svg>" | "<svg><path d=\"M7.521 17.5Q6.125 17.5 5.146 16.51Q4.167 15.521 4.167 14.125V7.417Q3.438 7.125 2.969 6.49Q2.5 5.854 2.5 5.042Q2.5 3.979 3.24 3.24Q3.979 2.5 5.042 2.5Q6.104 2.5 6.844 3.24Q7.583 3.979 7.583 5.042Q7.583 5.854 7.115 6.49Q6.646 7.125 5.917 7.417V14.125Q5.917 14.792 6.385 15.271Q6.854 15.75 7.521 15.75Q8.188 15.75 8.656 15.271Q9.125 14.792 9.125 14.125V5.875Q9.125 4.479 10.104 3.49Q11.083 2.5 12.479 2.5Q13.875 2.5 14.854 3.49Q15.833 4.479 15.833 5.875V12.583Q16.562 12.875 17.031 13.51Q17.5 14.146 17.5 14.958Q17.5 16.021 16.76 16.76Q16.021 17.5 14.958 17.5Q13.896 17.5 13.156 16.76Q12.417 16.021 12.417 14.958Q12.417 14.146 12.885 13.5Q13.354 12.854 14.083 12.583V5.875Q14.083 5.208 13.615 4.729Q13.146 4.25 12.479 4.25Q11.812 4.25 11.344 4.729Q10.875 5.208 10.875 5.875V14.125Q10.875 15.521 9.896 16.51Q8.917 17.5 7.521 17.5Z\"/></svg>";
2
+ export declare const getShapePicture: (shape: ShapeType) => "<svg><path d=\"M5.146 17.5Q4.146 17.5 3.208 17Q2.271 16.5 1.667 15.708Q2.208 15.75 2.802 15.344Q3.396 14.938 3.396 14.104Q3.396 13.042 4.135 12.292Q4.875 11.542 5.958 11.542Q7.021 11.542 7.76 12.292Q8.5 13.042 8.5 14.104Q8.5 15.5 7.51 16.5Q6.521 17.5 5.146 17.5ZM9.917 12.5 7.562 10.146 14.917 2.729Q15.146 2.5 15.469 2.5Q15.792 2.5 16.021 2.729L17.271 3.958Q17.5 4.188 17.5 4.531Q17.5 4.875 17.271 5.125Z\"/></svg>" | "<svg><path d=\"M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z\"/></svg>" | "<svg><path d=\"M10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333ZM10 16.583Q12.75 16.583 14.667 14.667Q16.583 12.75 16.583 10Q16.583 7.25 14.667 5.333Q12.75 3.417 10 3.417Q7.25 3.417 5.333 5.333Q3.417 7.25 3.417 10Q3.417 12.75 5.333 14.667Q7.25 16.583 10 16.583ZM10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Z\"/></svg>" | "<svg><path d=\"M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z\"/></svg>" | "<svg><path d=\"M4.792 15.083 8.333 11.542 9.833 13.021 11.667 10.708 15.167 15.083ZM6.667 8.417Q5.938 8.417 5.427 7.906Q4.917 7.396 4.917 6.667Q4.917 5.938 5.427 5.427Q5.938 4.917 6.667 4.917Q7.396 4.917 7.906 5.427Q8.417 5.938 8.417 6.667Q8.417 7.396 7.906 7.906Q7.396 8.417 6.667 8.417ZM4.167 18.333Q3.125 18.333 2.396 17.604Q1.667 16.875 1.667 15.833V4.167Q1.667 3.125 2.396 2.396Q3.125 1.667 4.167 1.667H15.833Q16.875 1.667 17.604 2.396Q18.333 3.125 18.333 4.167V15.833Q18.333 16.875 17.604 17.604Q16.875 18.333 15.833 18.333ZM4.167 16.583H15.833Q16.146 16.583 16.365 16.365Q16.583 16.146 16.583 15.833V4.167Q16.583 3.854 16.365 3.635Q16.146 3.417 15.833 3.417H4.167Q3.854 3.417 3.635 3.635Q3.417 3.854 3.417 4.167V15.833Q3.417 16.146 3.635 16.365Q3.854 16.583 4.167 16.583Z\"/></svg>" | "<svg><path d=\"M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z\"/></svg>" | "<svg><path d=\"M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z\"/></svg>" | "<svg><path d=\"M7.521 17.5Q6.125 17.5 5.146 16.51Q4.167 15.521 4.167 14.125V7.417Q3.438 7.125 2.969 6.49Q2.5 5.854 2.5 5.042Q2.5 3.979 3.24 3.24Q3.979 2.5 5.042 2.5Q6.104 2.5 6.844 3.24Q7.583 3.979 7.583 5.042Q7.583 5.854 7.115 6.49Q6.646 7.125 5.917 7.417V14.125Q5.917 14.792 6.385 15.271Q6.854 15.75 7.521 15.75Q8.188 15.75 8.656 15.271Q9.125 14.792 9.125 14.125V5.875Q9.125 4.479 10.104 3.49Q11.083 2.5 12.479 2.5Q13.875 2.5 14.854 3.49Q15.833 4.479 15.833 5.875V12.583Q16.562 12.875 17.031 13.51Q17.5 14.146 17.5 14.958Q17.5 16.021 16.76 16.76Q16.021 17.5 14.958 17.5Q13.896 17.5 13.156 16.76Q12.417 16.021 12.417 14.958Q12.417 14.146 12.885 13.5Q13.354 12.854 14.083 12.583V5.875Q14.083 5.208 13.615 4.729Q13.146 4.25 12.479 4.25Q11.812 4.25 11.344 4.729Q10.875 5.208 10.875 5.875V14.125Q10.875 15.521 9.896 16.51Q8.917 17.5 7.521 17.5Z\"/></svg>" | "";
@@ -1,9 +1,15 @@
1
- import type { SelectionModeData } from '../types/Mode';
2
- import type { Point, ShapeEntity } from '../types/Shapes';
3
1
  import type { GridFormatType } from '../constants/app';
2
+ import type { SelectionModeData } from '../types/Mode';
3
+ import type { DrawableShape, Line, Point, ShapeEntity } from '../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
+ export declare const scalePoint: (point: Point, minX: number, minY: number, scaleX?: number, scaleY?: number) => Point;
6
7
  export declare const roundForGrid: (value: number, gridFormat: GridFormatType, gridOffset?: number) => number;
7
8
  export declare const roundRotationForGrid: (rotation: number, gridFormat: GridFormatType, gridOffset?: number) => number;
8
9
  export declare const transformShape: (ctx: CanvasRenderingContext2D, shape: ShapeEntity, cursorPosition: Point, gridFormat: GridFormatType, canvasOffset: Point, selectionMode: SelectionModeData<Point | number>, selectionPadding: number, isShiftPressed: boolean, currentScale: number) => ShapeEntity;
9
10
  export declare const fitContentInsideContainer: (contentWidth: number, contentHeight: number, containerWidth: number, containerHeight: number, shouldFillContainer?: boolean) => number[];
11
+ export declare const shortenLine: ({ line, size, direction }: {
12
+ line: DrawableShape<'line'>;
13
+ size: number;
14
+ direction: 'start' | 'end' | 'both';
15
+ }) => Line;
@@ -1,8 +1,9 @@
1
- import { Point, Rect } from '../types/Shapes';
1
+ import { Circle, Point, Rect } from '../types/Shapes';
2
2
  type Vector = [Point, Point];
3
3
  export declare const degreesToRadians: (degrees: number) => number;
4
4
  export declare const radiansToDegrees: (radians: number) => number;
5
5
  export declare const isPointInsideRect: (rect: Rect, point: Point) => boolean;
6
+ export declare const isCircleIntersectRect: (rect: Rect, circle: Circle) => boolean;
6
7
  export declare const rotatePoint: ({ origin, point, rotation }: {
7
8
  origin?: Point | undefined;
8
9
  point: Point;
@@ -0,0 +1 @@
1
+ export declare const uniqueId: (prefix?: string) => string;
package/package.json CHANGED
@@ -1,73 +1,56 @@
1
1
  {
2
- "name": "@yorab/react-paint",
3
- "version": "0.9.2",
4
- "type": "module",
5
- "keywords": [],
6
- "author": "Yohann Rabatel",
7
- "license": "MIT",
8
- "main": "./dist/react-paint.umd.cjs",
9
- "module": "./dist/react-paint.js",
10
- "types": "./dist/components/App.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/react-paint.js",
14
- "require": "./dist/react-paint.umd.cjs",
15
- "types": "./dist/components/App.d.ts"
16
- },
17
- "./react-paint.css": "./dist/react-paint.css"
18
- },
19
- "files": [
20
- "README.md",
21
- "LICENSE.txt",
22
- "package.json",
23
- "dist/"
24
- ],
25
- "dependencies": {
26
- "lodash": "4.17.21"
27
- },
28
- "devDependencies": {
29
- "@storybook/addon-essentials": "7.6.3",
30
- "@storybook/addon-interactions": "7.6.3",
31
- "@storybook/addon-links": "7.6.3",
32
- "@storybook/blocks": "7.6.3",
33
- "@storybook/react": "7.6.3",
34
- "@storybook/react-vite": "7.6.3",
35
- "@storybook/test": "^7.6.3",
36
- "@storybook/testing-library": "0.2.2",
37
- "@types/lodash": "4.14.196",
38
- "@types/node": "20.4.5",
39
- "@types/react": "18.2.17",
40
- "@types/react-dom": "18.2.7",
41
- "@typescript-eslint/eslint-plugin": "6.0.0",
42
- "@typescript-eslint/parser": "6.0.0",
43
- "@vitejs/plugin-react": "4.2.0",
44
- "eslint": "8.45.0",
45
- "eslint-config-prettier": "8.9.0",
46
- "eslint-import-resolver-typescript": "3.5.5",
47
- "eslint-plugin-import": "2.28.0",
48
- "eslint-plugin-prettier": "5.0.0",
49
- "eslint-plugin-react-hooks": "4.6.0",
50
- "eslint-plugin-storybook": "0.6.15",
51
- "lightningcss": "1.21.5",
52
- "prettier": "3.0.0",
53
- "react": "18.2.0",
54
- "react-dom": "18.2.0",
55
- "storybook": "7.6.3",
56
- "typescript": "5.3.2",
57
- "vite": "5.0.5",
58
- "vite-tsconfig-paths": "4.2.0"
59
- },
60
- "peerDependencies": {
61
- "react": "18.x",
62
- "react-dom": "18.x"
63
- },
64
- "scripts": {
65
- "declarationfiles": "npx tsc --project tsconfig.prod.json",
66
- "start": "storybook dev -p 6006",
67
- "build-storybook": "storybook build",
68
- "test": "echo \"Error: no test specified\" && exit 1",
69
- "build": "vite build && npm run declarationfiles",
70
- "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
71
- "publishnpm": "npm run build && npm publish --access public"
72
- }
73
- }
2
+ "name": "@yorab/react-paint",
3
+ "version": "0.10.0",
4
+ "type": "module",
5
+ "keywords": [],
6
+ "author": "Yohann Rabatel",
7
+ "license": "MIT",
8
+ "main": "./dist/react-paint.umd.cjs",
9
+ "module": "./dist/react-paint.js",
10
+ "types": "./dist/components/App.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/react-paint.js",
14
+ "require": "./dist/react-paint.umd.cjs",
15
+ "types": "./dist/components/App.d.ts"
16
+ },
17
+ "./react-paint.css": "./dist/react-paint.css"
18
+ },
19
+ "files": ["README.md", "LICENSE.txt", "package.json", "dist/"],
20
+ "devDependencies": {
21
+ "@biomejs/biome": "1.5.3",
22
+ "@rollup/plugin-terser": "0.4.4",
23
+ "@storybook/addon-essentials": "7.6.3",
24
+ "@storybook/addon-interactions": "7.6.3",
25
+ "@storybook/addon-links": "7.6.3",
26
+ "@storybook/blocks": "7.6.3",
27
+ "@storybook/react": "7.6.3",
28
+ "@storybook/react-vite": "7.6.3",
29
+ "@storybook/test": "7.6.3",
30
+ "@storybook/testing-library": "0.2.2",
31
+ "@types/node": "20.4.5",
32
+ "@types/react": "18.2.17",
33
+ "@types/react-dom": "18.2.7",
34
+ "@vitejs/plugin-react": "4.2.0",
35
+ "lightningcss": "1.21.5",
36
+ "react": "18.2.0",
37
+ "react-dom": "18.2.0",
38
+ "storybook": "7.6.3",
39
+ "typescript": "5.3.2",
40
+ "vite": "5.0.12",
41
+ "vite-tsconfig-paths": "4.2.0"
42
+ },
43
+ "peerDependencies": {
44
+ "react": "18.x",
45
+ "react-dom": "18.x"
46
+ },
47
+ "scripts": {
48
+ "declarationfiles": "npx tsc --project tsconfig.prod.json",
49
+ "start": "storybook dev -p 6006",
50
+ "build-storybook": "storybook build",
51
+ "test": "echo \"Error: no test specified\" && exit 1",
52
+ "build": "vite build && npm run declarationfiles",
53
+ "lint": "npx @biomejs/biome check --apply src stories",
54
+ "publishnpm": "npm run build && npm publish --access public"
55
+ }
56
+ }
@@ -1,147 +0,0 @@
1
- import { DrawableShapeJson, Point } from '../types/Shapes';
2
- export declare const migrateShapesV065: (shapes: DrawableShapeJson[]) => (({
3
- visible?: boolean | undefined;
4
- locked?: boolean | undefined;
5
- rotation: number;
6
- style?: import("../types/Shapes").StyleShape | undefined;
7
- } & import("../types/Shapes").Triangle & {
8
- type: "triangle";
9
- path?: Path2D | undefined;
10
- } & {
11
- translation?: Point | undefined;
12
- }) | ({
13
- visible?: boolean | undefined;
14
- locked?: boolean | undefined;
15
- rotation: number;
16
- style?: import("../types/Shapes").StyleShape | undefined;
17
- } & import("../types/Shapes").Line & {
18
- type: "line";
19
- selection?: import("../types/Shapes").SelectionLinesType | undefined;
20
- path?: Path2D | undefined;
21
- arrows?: import("../types/Shapes").DrawableShape<"triangle">[] | undefined;
22
- } & {
23
- translation?: Point | undefined;
24
- }) | ({
25
- visible?: boolean | undefined;
26
- locked?: boolean | undefined;
27
- rotation: number;
28
- style?: import("../types/Shapes").StyleShape | undefined;
29
- } & import("../types/Shapes").Rect & {
30
- src: string;
31
- } & {
32
- type: "picture";
33
- img: HTMLImageElement;
34
- selection?: import("../types/Shapes").SelectionDefaultType | undefined;
35
- } & {
36
- translation?: Point | undefined;
37
- }) | ({
38
- visible?: boolean | undefined;
39
- locked?: boolean | undefined;
40
- rotation: number;
41
- style?: import("../types/Shapes").StyleShape | undefined;
42
- } & import("../types/Shapes").Rect & {
43
- value: string[];
44
- fontSize: number;
45
- } & {
46
- type: "text";
47
- selection?: import("../types/Shapes").SelectionDefaultType | undefined;
48
- } & {
49
- translation?: Point | undefined;
50
- }) | ({
51
- visible?: boolean | undefined;
52
- locked?: boolean | undefined;
53
- rotation: number;
54
- style?: import("../types/Shapes").StyleShape | undefined;
55
- } & import("../types/Shapes").Rect & {
56
- type: "rect";
57
- selection?: import("../types/Shapes").SelectionDefaultType | undefined;
58
- path?: Path2D | undefined;
59
- } & {
60
- translation?: Point | undefined;
61
- }) | ({
62
- visible?: boolean | undefined;
63
- locked?: boolean | undefined;
64
- rotation: number;
65
- style?: import("../types/Shapes").StyleShape | undefined;
66
- } & import("../types/Shapes").Rect & {
67
- type: "square";
68
- selection?: import("../types/Shapes").SelectionDefaultType | undefined;
69
- path?: Path2D | undefined;
70
- } & {
71
- translation?: Point | undefined;
72
- }) | ({
73
- visible?: boolean | undefined;
74
- locked?: boolean | undefined;
75
- rotation: number;
76
- style?: import("../types/Shapes").StyleShape | undefined;
77
- } & import("../types/Shapes").Circle & {
78
- type: "circle";
79
- selection?: import("../types/Shapes").SelectionDefaultType | undefined;
80
- path?: Path2D | undefined;
81
- } & {
82
- translation?: Point | undefined;
83
- }) | ({
84
- visible?: boolean | undefined;
85
- locked?: boolean | undefined;
86
- rotation: number;
87
- style?: import("../types/Shapes").StyleShape | undefined;
88
- } & import("../types/Shapes").Ellipse & {
89
- type: "ellipse";
90
- selection?: import("../types/Shapes").SelectionDefaultType | undefined;
91
- path?: Path2D | undefined;
92
- } & {
93
- translation?: Point | undefined;
94
- }) | ({
95
- visible?: boolean | undefined;
96
- locked?: boolean | undefined;
97
- rotation: number;
98
- style?: import("../types/Shapes").StyleShape | undefined;
99
- } & import("../types/Shapes").Polygon & {
100
- type: "polygon";
101
- selection?: import("../types/Shapes").SelectionLinesType | undefined;
102
- path?: Path2D | undefined;
103
- } & {
104
- translation?: Point | undefined;
105
- }) | ({
106
- visible?: boolean | undefined;
107
- locked?: boolean | undefined;
108
- rotation: number;
109
- style?: import("../types/Shapes").StyleShape | undefined;
110
- } & import("../types/Shapes").Curve & {
111
- type: "curve";
112
- selection?: import("../types/Shapes").SelectionLinesType | undefined;
113
- path?: Path2D | undefined;
114
- } & {
115
- translation?: Point | undefined;
116
- }) | ({
117
- visible?: boolean | undefined;
118
- locked?: boolean | undefined;
119
- rotation: number;
120
- style?: import("../types/Shapes").StyleShape | undefined;
121
- } & import("../types/Shapes").Brush & {
122
- type: "brush";
123
- selection?: import("../types/Shapes").SelectionDefaultType | undefined;
124
- path?: Path2D | undefined;
125
- scaleX?: number | undefined;
126
- scaleY?: number | undefined;
127
- } & {
128
- translation?: Point | undefined;
129
- }) | {
130
- x: number;
131
- y: number;
132
- selection?: import("../types/Shapes").SelectionDefaultType | undefined;
133
- style?: import("../types/Shapes").StyleShape | undefined;
134
- type: "rect" | "square" | "circle" | "ellipse" | "picture";
135
- rotation: number;
136
- visible?: boolean | undefined;
137
- locked?: boolean | undefined;
138
- } | {
139
- points: Point[];
140
- selection?: import("../types/Shapes").SelectionLinesType | undefined;
141
- style?: import("../types/Shapes").StyleShape | undefined;
142
- type: "polygon" | "curve";
143
- rotation: number;
144
- path?: Path2D | undefined;
145
- visible?: boolean | undefined;
146
- locked?: boolean | undefined;
147
- } | undefined)[];