@yorab/react-paint 0.11.7 → 0.11.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # React Paint V0.11.7
1
+ # React Paint
2
2
 
3
3
  An open-source canvas-based library for React used for image annotation or as a digital whiteboard
4
4
 
@@ -1,4 +1,4 @@
1
- import type { DrawableShape, Point } from './../../common/types/Shapes';
1
+ import type { ExportedDrawableShape, Point } from './../../common/types/Shapes';
2
2
  import type { CustomToolInput } from './../../common/types/tools';
3
3
  import type { RecursivePartial } from './../../common/types/utils';
4
4
  export declare const APP_NAME = "react_paint";
@@ -29,7 +29,7 @@ type AppOptionsType = {
29
29
  withUrlPicture: boolean;
30
30
  withFrameSelection: boolean;
31
31
  withSkeleton: boolean;
32
- clearCallback: 'empty' | 'defaultShapes' | (() => DrawableShape[]);
32
+ clearCallback: 'empty' | 'defaultShapes' | (() => ExportedDrawableShape[]);
33
33
  brushAlgo: BrushAlgo;
34
34
  isBrushShapeDoneOnMouseUp: boolean;
35
35
  canvasSelectionPadding: number;
@@ -1,19 +1,19 @@
1
1
  import { type OptionalOptions, type UtilsSettings } from './../../canvas/constants/app';
2
- import type { DrawableShape, Point, ShapeEntity, StateData } from './../../common/types/Shapes';
2
+ import type { ExportedDrawableShape, Point, ShapeEntity, StateData } from './../../common/types/Shapes';
3
3
  import type { ToolsType } from './../../common/types/tools';
4
4
  type UseReactPaintProps = {
5
5
  width?: number;
6
6
  height?: number;
7
- shapes?: DrawableShape[];
7
+ shapes?: ExportedDrawableShape[];
8
8
  mode?: 'editor' | 'viewer';
9
9
  disabled?: boolean;
10
10
  options?: OptionalOptions;
11
11
  };
12
- declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disabled, options }: UseReactPaintProps) => {
12
+ declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disabled, options }?: UseReactPaintProps) => {
13
13
  editorProps: {
14
14
  shapesRef: import("react").MutableRefObject<ShapeEntity[]>;
15
15
  addPictureShape: (fileOrUrl: File | string, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity<"picture">>;
16
- moveShapes: (firstShapeId: string, lastShapeId: string) => void;
16
+ moveShapes: (startPositionShapeId: string, endPositionShapeId: string) => void;
17
17
  toggleShapeVisibility: (shape: ShapeEntity) => void;
18
18
  toggleShapeLock: (shape: ShapeEntity) => void;
19
19
  canGoBackward: boolean;
@@ -110,7 +110,7 @@ declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disa
110
110
  };
111
111
  registerEvent: (event: "dataChanged", fn: (data: StateData, source: "user" | "remote") => void) => void;
112
112
  unregisterEvent: (event: "dataChanged", fn?: (data: StateData, source: "user" | "remote") => void) => void;
113
- resetCanvas: (json?: DrawableShape[], clearHistory?: boolean) => void;
113
+ resetCanvas: (json?: ExportedDrawableShape[], clearHistory?: boolean) => void;
114
114
  getCurrentImage: () => string | undefined;
115
115
  getCurrentData: () => StateData;
116
116
  };
@@ -11,7 +11,7 @@ declare const useShapes: (settings: UtilsSettings, width: number, height: number
11
11
  refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
12
12
  addShape: (newShape: ShapeEntity) => void;
13
13
  addPictureShape: (fileOrUrl: File | string, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity<"picture">>;
14
- moveShapes: (firstShapeId: string, lastShapeId: string) => void;
14
+ moveShapes: (startPositionShapeId: string, endPositionShapeId: string) => void;
15
15
  saveShapes: () => void;
16
16
  setSelectedShape: import("react").Dispatch<import("react").SetStateAction<ShapeEntity | undefined>>;
17
17
  refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
@@ -1,5 +1,5 @@
1
1
  import type { UtilsSettings } from './../../canvas/constants/app';
2
- import type { DrawableShape, ShapeEntity } from './../../common/types/Shapes';
2
+ import type { DrawableShape, ExportedDrawableShape, ShapeEntity } from './../../common/types/Shapes';
3
3
  export declare const addSizeAndConvertSvgToObjectUrl: (svgFileContent: string) => string;
4
4
  export declare const isSvg: (fileOrUrl: File | string) => boolean;
5
5
  export declare const fetchAndStringify: (url: string) => Promise<string>;
@@ -9,4 +9,4 @@ export declare const getStringifiedImage: (shape: DrawableShape<"picture">) => s
9
9
  export declare const getCanvasImage: (shapes: DrawableShape[], width: number, height: number, settings: UtilsSettings) => string;
10
10
  export declare const encodeShapesInString: (shapes: DrawableShape[], width: number, height: number) => string;
11
11
  export declare const decodeJson: (file: File) => Promise<unknown>;
12
- export declare const decodeImportedData: (shapesForJson: DrawableShape[], settings: UtilsSettings) => Promise<ShapeEntity[]>;
12
+ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[], settings: UtilsSettings) => Promise<ShapeEntity[]>;
@@ -115,6 +115,7 @@ export type DrawableShape<T extends ShapeType = ShapeType> = {
115
115
  scaleX?: number;
116
116
  scaleY?: number;
117
117
  } : never);
118
+ export type ExportedDrawableShape<T extends ShapeType = ShapeType> = T extends 'picture' ? Omit<DrawableShape<'picture'>, 'img'> : DrawableShape<T>;
118
119
  export type ShapeEntity<T extends Exclude<ShapeType, 'triangle'> = Exclude<ShapeType, 'triangle'>> = {
119
120
  id: string;
120
121
  toolId?: string;
@@ -1 +1,2 @@
1
1
  export declare const compact: <T>(array: (T | undefined | null)[]) => T[];
2
+ export declare const moveItemPosition: <T>(array: T[], positionToMove: number, positionToEnd: number) => T[];
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { OptionalOptions } from './canvas/constants/app';
2
2
  import useReactPaint from './canvas/hooks/useReactPaint';
3
3
  import Canvas from './canvas/index';
4
- import type { DrawableShape, StateData } from './common/types/Shapes';
4
+ import type { ExportedDrawableShape, StateData } from './common/types/Shapes';
5
5
  import Editor from './editor/index';
6
+ type DrawableShape = ExportedDrawableShape;
6
7
  export { Editor, Canvas, useReactPaint, type DrawableShape, type StateData, type OptionalOptions };