@yorab/react-paint 0.11.1 → 0.11.3

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.0
1
+ # React Paint V0.11.3
2
2
 
3
3
  An open-source canvas-based library for React used for image annotation or as a digital whiteboard
4
4
 
@@ -150,6 +150,9 @@ you will find other usages in <a href="https://github.com/YoRab/react-paint-edit
150
150
  | `brushAlgo` | `'simple' \| 'quadratic'` | *Optional*. Choose which algorithm to display brush shape. `simple` displays path as is, `quadratic` uses quadratic bézier curves | `simple` |
151
151
  | `isBrushShapeDoneOnMouseUp` | `boolean` | *Optional*. Choose whether drawing brush shape after releasing mouse should create a new shape or not | `true` |
152
152
  | `canvasSelectionPadding` | `boolean` | *Optional*. Padding between shape and selection frame | `0` |
153
+ | `availableTools` | `CustomToolInput[]` | *Optional*. List of available tools. See CustomTool for more details | `` |
154
+
155
+
153
156
 
154
157
 
155
158
  #### Canvas
@@ -181,6 +184,194 @@ you will find other usages in <a href="https://github.com/YoRab/react-paint-edit
181
184
  #### `DrawableShape`
182
185
  #### `StateData`
183
186
 
187
+ #### `CustomTool`
188
+
189
+ ```
190
+ type CustomTool = {
191
+ id: string
192
+ icon: string
193
+ label: string
194
+ } & (
195
+ | {
196
+ type: 'brush'
197
+ settings: ToolsSettingsType<'brush'>
198
+ }
199
+ | {
200
+ type: 'circle'
201
+ settings: ToolsSettingsType<'circle'>
202
+ }
203
+ | {
204
+ type: 'ellipse'
205
+ settings: ToolsSettingsType<'ellipse'>
206
+ }
207
+ | {
208
+ type: 'rect'
209
+ settings: ToolsSettingsType<'rect'>
210
+ }
211
+ | {
212
+ type: 'square'
213
+ settings: ToolsSettingsType<'square'>
214
+ }
215
+ | {
216
+ type: 'line'
217
+ settings: ToolsSettingsType<'line'>
218
+ }
219
+ | {
220
+ type: 'polygon'
221
+ settings: ToolsSettingsType<'polygon'>
222
+ }
223
+ | {
224
+ type: 'curve'
225
+ settings: ToolsSettingsType<'curve'>
226
+ }
227
+ | {
228
+ type: 'text'
229
+ settings: ToolsSettingsType<'text'>
230
+ }
231
+ | {
232
+ type: 'picture'
233
+ settings: ToolsSettingsType<'picture'>
234
+ }
235
+ )
236
+
237
+ type SettingsOpacity = {
238
+ opacity: {
239
+ min: number
240
+ max: number
241
+ step: number
242
+ default: number
243
+ hidden?: boolean
244
+ }
245
+ }
246
+
247
+ type SettingsStrokeColor = {
248
+ strokeColor: {
249
+ values: string[]
250
+ default: string
251
+ hidden?: boolean
252
+ }
253
+ }
254
+
255
+ type SettingsFillColor = {
256
+ fillColor: {
257
+ values: string[]
258
+ default: string
259
+ hidden?: boolean
260
+ }
261
+ }
262
+
263
+ type SettingsLineWidth = {
264
+ lineWidth: {
265
+ min: number
266
+ max: number
267
+ step: number
268
+ default: number
269
+ hidden?: boolean
270
+ }
271
+ }
272
+
273
+ type SettingsLineDash = {
274
+ lineDash: {
275
+ values: number[]
276
+ default: number
277
+ hidden?: boolean
278
+ }
279
+ }
280
+
281
+ type SettingsLineArrow = {
282
+ lineArrow: {
283
+ values: number[]
284
+ default: number
285
+ hidden?: boolean
286
+ }
287
+ }
288
+
289
+ type SettingsFont = {
290
+ fontFamily: {
291
+ values: string[]
292
+ default: string
293
+ hidden?: boolean
294
+ }
295
+ fontBold: {
296
+ values: boolean[]
297
+ default: boolean
298
+ hidden?: boolean
299
+ }
300
+ fontItalic: {
301
+ values: boolean[]
302
+ default: boolean
303
+ hidden?: boolean
304
+ }
305
+ }
306
+
307
+ type SettingsPointsCount = {
308
+ pointsCount: {
309
+ min: number
310
+ max: number
311
+ step: number
312
+ default: number
313
+ hidden?: boolean
314
+ }
315
+ }
316
+
317
+ type ToolsRectSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash
318
+
319
+ type ToolsSquareSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash
320
+
321
+ type ToolsCircleSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash
322
+
323
+ type ToolsEllipseSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash
324
+
325
+ type ToolsTextSettings = SettingsOpacity & SettingsStrokeColor & SettingsFont
326
+
327
+ type ToolsLineSettings = SettingsOpacity & SettingsStrokeColor & SettingsLineWidth & SettingsLineDash & SettingsLineArrow
328
+
329
+ type ToolsBrushSettings = SettingsOpacity & SettingsStrokeColor & SettingsLineWidth & SettingsLineDash
330
+
331
+ type ToolsPolygonSettings = SettingsOpacity &
332
+ SettingsStrokeColor &
333
+ SettingsFillColor &
334
+ SettingsLineWidth &
335
+ SettingsLineDash &
336
+ SettingsPointsCount
337
+
338
+ type ToolsCurveSettings = SettingsOpacity &
339
+ SettingsStrokeColor &
340
+ SettingsFillColor &
341
+ SettingsLineWidth &
342
+ SettingsLineDash &
343
+ SettingsPointsCount
344
+
345
+ type ToolsTriangleSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash
346
+
347
+ type ToolsPictureSettings = SettingsOpacity
348
+
349
+ type ToolsSettingsType<T extends ShapeType> = T extends 'rect'
350
+ ? ToolsRectSettings
351
+ : T extends 'square'
352
+ ? ToolsSquareSettings
353
+ : T extends 'circle'
354
+ ? ToolsCircleSettings
355
+ : T extends 'ellipse'
356
+ ? ToolsEllipseSettings
357
+ : T extends 'text'
358
+ ? ToolsTextSettings
359
+ : T extends 'line'
360
+ ? ToolsLineSettings
361
+ : T extends 'brush'
362
+ ? ToolsBrushSettings
363
+ : T extends 'polygon'
364
+ ? ToolsPolygonSettings
365
+ : T extends 'curve'
366
+ ? ToolsCurveSettings
367
+ : T extends 'triangle'
368
+ ? ToolsTriangleSettings
369
+ : T extends 'picture'
370
+ ? ToolsPictureSettings
371
+ : never
372
+
373
+ ```
374
+
184
375
  ## Changelog
185
376
  https://github.com/YoRab/react-paint-editor/blob/main/Changelog.md
186
377
 
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { UtilsSettings } from './../../canvas/constants/app';
3
2
  import type { ShapeEntity } from './../../common/types/Shapes';
4
3
  type UseKeyboardType = {
@@ -1,6 +1,5 @@
1
- /// <reference types="react" />
2
1
  import { type OptionalOptions, type UtilsSettings } from './../../canvas/constants/app';
3
- import type { DrawableShape, StateData, Point, ShapeEntity } from './../../common/types/Shapes';
2
+ import type { DrawableShape, Point, ShapeEntity, StateData } from './../../common/types/Shapes';
4
3
  import type { ToolsType } from './../../common/types/tools';
5
4
  type UseReactPaintProps = {
6
5
  width?: number;
@@ -13,7 +12,7 @@ type UseReactPaintProps = {
13
12
  declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disabled, options }: UseReactPaintProps) => {
14
13
  editorProps: {
15
14
  shapesRef: import("react").MutableRefObject<ShapeEntity[]>;
16
- addPictureShape: (fileOrUrl: string | File, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity<"picture">>;
15
+ addPictureShape: (fileOrUrl: File | string, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity<"picture">>;
17
16
  moveShapes: (firstShapeId: string, lastShapeId: string) => void;
18
17
  toggleShapeVisibility: (shape: ShapeEntity) => void;
19
18
  toggleShapeLock: (shape: ShapeEntity) => void;
@@ -110,7 +109,7 @@ declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disa
110
109
  };
111
110
  };
112
111
  registerEvent: (event: "dataChanged", fn: (data: StateData, source: "user" | "remote") => void) => void;
113
- unregisterEvent: (event: "dataChanged", fn?: ((data: StateData, source: "user" | "remote") => void) | undefined) => void;
112
+ unregisterEvent: (event: "dataChanged", fn?: (data: StateData, source: "user" | "remote") => void) => void;
114
113
  resetCanvas: (json?: DrawableShape[], clearHistory?: boolean) => void;
115
114
  getCurrentImage: () => string | undefined;
116
115
  getCurrentData: () => StateData;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type UseResizeObserverType = {
3
2
  element: React.RefObject<HTMLElement>;
4
3
  onResized: (width: number, height: number) => unknown;
@@ -1,9 +1,8 @@
1
- /// <reference types="react" />
2
1
  import { type UtilsSettings } from './../../canvas/constants/app';
3
- import type { StateData, Point, ShapeEntity } from './../../common/types/Shapes';
2
+ import type { Point, ShapeEntity, StateData } from './../../common/types/Shapes';
4
3
  declare const useShapes: (settings: UtilsSettings) => {
5
- registerEvent: (event: 'dataChanged', fn: (data: StateData, source: 'user' | 'remote') => void) => void;
6
- unregisterEvent: (event: 'dataChanged', fn?: (data: StateData, source: 'user' | 'remote') => void) => void;
4
+ registerEvent: (event: "dataChanged", fn: (data: StateData, source: "user" | "remote") => void) => void;
5
+ unregisterEvent: (event: "dataChanged", fn?: (data: StateData, source: "user" | "remote") => void) => void;
7
6
  shapesRef: import("react").MutableRefObject<ShapeEntity[]>;
8
7
  selectedShape: ShapeEntity | undefined;
9
8
  hoveredShape: ShapeEntity | undefined;
@@ -24,7 +23,7 @@ declare const useShapes: (settings: UtilsSettings) => {
24
23
  forwardShape: () => void;
25
24
  clearShapes: (shapesToInit: ShapeEntity[], options: {
26
25
  clearHistory: boolean;
27
- source: 'user' | 'remote';
26
+ source: "user" | "remote";
28
27
  }) => void;
29
28
  canGoBackward: boolean;
30
29
  canGoForward: boolean;
@@ -1,5 +1,5 @@
1
1
  import type { UtilsSettings } from './../../canvas/constants/app';
2
- import type { DrawableShape, StateData, ShapeEntity } from './../../common/types/Shapes';
2
+ import type { DrawableShape, ShapeEntity, StateData } from './../../common/types/Shapes';
3
3
  export declare const cleanShapesBeforeExport: (shapes: DrawableShape[]) => DrawableShape[];
4
4
  export declare const buildDataToExport: (shapes: DrawableShape[], width: number, height: number) => StateData;
5
5
  export declare const addDefaultAndTempShapeProps: (shape: DrawableShape, settings: UtilsSettings) => ShapeEntity;
@@ -5,6 +5,7 @@ export declare const isSvg: (fileOrUrl: File | string) => boolean;
5
5
  export declare const fetchAndStringify: (url: string) => Promise<string>;
6
6
  export declare const downloadFile: (content: string, fileName: string) => void;
7
7
  export declare const getBase64Image: (img: HTMLImageElement) => string;
8
+ export declare const getStringifiedImage: (shape: DrawableShape<"picture">) => string;
8
9
  export declare const getCanvasImage: (shapes: DrawableShape[], width: number, height: number, settings: UtilsSettings) => string;
9
10
  export declare const encodeShapesInString: (shapes: DrawableShape[], width: number, height: number) => string;
10
11
  export declare const decodeJson: (file: File) => Promise<unknown>;
@@ -1,11 +1,11 @@
1
1
  import type { UtilsSettings } from './../../../canvas/constants/app';
2
2
  import type { DrawableShape, Point, SelectionLinesType } from './../../../common/types/Shapes';
3
- export declare const createLineSelectionPath: (path: Path2D | undefined, shape: DrawableShape<'line' | 'polygon' | 'curve'> & {
3
+ export declare const createLineSelectionPath: (path: Path2D | undefined, shape: DrawableShape<"line" | "polygon" | "curve"> & {
4
4
  points: readonly Point[];
5
5
  }, settings: UtilsSettings, gravityAnchors?: boolean) => SelectionLinesType;
6
6
  export declare const drawLineSelection: ({ ctx, shape, withAnchors, selectionWidth, selectionColor, settings }: {
7
7
  ctx: CanvasRenderingContext2D;
8
- shape: DrawableShape<'line'> | DrawableShape<'polygon'> | DrawableShape<'curve'>;
8
+ shape: DrawableShape<"line"> | DrawableShape<"polygon"> | DrawableShape<"curve">;
9
9
  withAnchors: boolean;
10
10
  selectionWidth: number;
11
11
  selectionColor: string;
@@ -5,15 +5,15 @@ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshBrush: <T extends DrawableShape<"brush">>(brush: T, settings: UtilsSettings) => T;
6
6
  export declare const createBrush: (shape: {
7
7
  id: string;
8
- type: 'brush';
9
- settings: ToolsSettingsType<'brush'>;
10
- }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<'brush'>;
11
- export declare const drawBrush: (ctx: CanvasRenderingContext2D, shape: DrawableShape<'brush'>) => void;
12
- export declare const getBrushBorder: (brush: DrawableShape<'brush'>, { selectionPadding }: UtilsSettings) => Rect;
8
+ type: "brush";
9
+ settings: ToolsSettingsType<"brush">;
10
+ }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"brush">;
11
+ export declare const drawBrush: (ctx: CanvasRenderingContext2D, shape: DrawableShape<"brush">) => void;
12
+ export declare const getBrushBorder: (brush: DrawableShape<"brush">, { selectionPadding }: UtilsSettings) => Rect;
13
13
  export declare const translateBrush: <U extends DrawableShape<"brush">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
14
14
  points: Point[][];
15
15
  };
16
- export declare const resizeBrush: (cursorPosition: Point, originalShape: DrawableShape<'brush'>, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio: boolean) => DrawableShape<'brush'>;
16
+ export declare const resizeBrush: (cursorPosition: Point, originalShape: DrawableShape<"brush">, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio: boolean) => DrawableShape<"brush">;
17
17
  export declare const addNewPointToShape: <T extends DrawableShape<"brush">>(shape: T, cursorPosition: Point, settings: UtilsSettings) => T & {
18
18
  points: Point[][];
19
19
  };
@@ -5,13 +5,13 @@ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshCircle: <T extends DrawableShape<"circle">>(shape: T, settings: UtilsSettings) => T;
6
6
  export declare const createCircle: (shape: {
7
7
  id: string;
8
- type: 'circle';
9
- settings: ToolsSettingsType<'circle'>;
10
- }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<'circle'>;
11
- export declare const drawCircle: (ctx: CanvasRenderingContext2D, circle: DrawableShape<'circle'>) => void;
8
+ type: "circle";
9
+ settings: ToolsSettingsType<"circle">;
10
+ }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"circle">;
11
+ export declare const drawCircle: (ctx: CanvasRenderingContext2D, circle: DrawableShape<"circle">) => void;
12
12
  export declare const getCircleBorder: (circle: Circle, settings: UtilsSettings) => Rect;
13
13
  export declare const translateCircle: <U extends DrawableShape<"circle">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
14
14
  x: number;
15
15
  y: number;
16
16
  };
17
- export declare const resizeCircle: (cursorPosition: Point, originalShape: DrawableShape<'circle'>, selectionMode: SelectionModeResize, settings: UtilsSettings) => DrawableShape<'circle'>;
17
+ export declare const resizeCircle: (cursorPosition: Point, originalShape: DrawableShape<"circle">, selectionMode: SelectionModeResize, settings: UtilsSettings) => DrawableShape<"circle">;
@@ -5,11 +5,11 @@ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshCurve: <T extends DrawableShape<"curve">>(shape: T, settings: UtilsSettings) => T;
6
6
  export declare const createCurve: (shape: {
7
7
  id: string;
8
- type: 'curve';
9
- settings: ToolsSettingsType<'curve'>;
10
- }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<'curve'>;
11
- export declare const resizeCurve: (cursorPosition: Point, originalShape: DrawableShape<'curve'>, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => DrawableShape<'curve'>;
12
- export declare const drawCurve: (ctx: CanvasRenderingContext2D, curve: DrawableShape<'curve'>) => void;
8
+ type: "curve";
9
+ settings: ToolsSettingsType<"curve">;
10
+ }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"curve">;
11
+ export declare const resizeCurve: (cursorPosition: Point, originalShape: DrawableShape<"curve">, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => DrawableShape<"curve">;
12
+ export declare const drawCurve: (ctx: CanvasRenderingContext2D, curve: DrawableShape<"curve">) => void;
13
13
  export declare const getCurveBorder: (polygon: import("./../../../common/types/Shapes").Polygon, settings: UtilsSettings) => import("./../../../common/types/Shapes").Rect;
14
14
  export declare const translateCurve: <U extends DrawableShape<"curve">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
15
15
  points: [number, number][];
@@ -5,13 +5,13 @@ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshEllipse: <T extends DrawableShape<"ellipse">>(shape: T, settings: UtilsSettings) => T;
6
6
  export declare const createEllipse: (shape: {
7
7
  id: string;
8
- type: 'ellipse';
9
- settings: ToolsSettingsType<'ellipse'>;
10
- }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<'ellipse'>;
11
- export declare const drawEllipse: (ctx: CanvasRenderingContext2D, ellipse: DrawableShape<'ellipse'>) => void;
8
+ type: "ellipse";
9
+ settings: ToolsSettingsType<"ellipse">;
10
+ }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"ellipse">;
11
+ export declare const drawEllipse: (ctx: CanvasRenderingContext2D, ellipse: DrawableShape<"ellipse">) => void;
12
12
  export declare const getEllipseBorder: (ellipse: Ellipse, settings: UtilsSettings) => Rect;
13
13
  export declare const translateEllipse: <U extends DrawableShape<"ellipse">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
14
14
  x: number;
15
15
  y: number;
16
16
  };
17
- export declare const resizeEllipse: (cursorPosition: Point, originalShape: DrawableShape<'ellipse'>, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio?: boolean) => DrawableShape<'ellipse'>;
17
+ export declare const resizeEllipse: (cursorPosition: Point, originalShape: DrawableShape<"ellipse">, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio?: boolean) => DrawableShape<"ellipse">;
@@ -3,7 +3,7 @@ import type { SelectionModeData } from './../../../common/types/Mode';
3
3
  import type { DrawableShape, Point, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
4
  import type { CustomTool } from './../../../common/types/tools';
5
5
  export declare const createShape: (ctx: CanvasRenderingContext2D, shape: Exclude<CustomTool, {
6
- type: 'picture';
6
+ type: "picture";
7
7
  }>, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity;
8
8
  export declare const drawShape: (ctx: CanvasRenderingContext2D, shape: DrawableShape, settings: UtilsSettings) => void;
9
9
  export declare const getShapeInfos: (shape: DrawableShape, settings: UtilsSettings) => {
@@ -5,11 +5,11 @@ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshLine: <T extends DrawableShape<"line">>(line: T, settings: UtilsSettings) => T;
6
6
  export declare const createLine: (shape: {
7
7
  id: string;
8
- type: 'line';
9
- settings: ToolsSettingsType<'line'>;
10
- }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<'line'>;
8
+ type: "line";
9
+ settings: ToolsSettingsType<"line">;
10
+ }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"line">;
11
11
  export declare const buildTriangleOnLine: (center: Point, rotation: number, lineStyle: StyleShape) => Triangle;
12
- export declare const drawLine: (ctx: CanvasRenderingContext2D, shape: DrawableShape<'line'>) => void;
12
+ export declare const drawLine: (ctx: CanvasRenderingContext2D, shape: DrawableShape<"line">) => void;
13
13
  export declare const getLineBorder: (line: Line, settings: UtilsSettings) => Rect;
14
14
  export declare const translateLine: <U extends DrawableShape<"line">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
15
15
  points: [Point, Point];
@@ -2,9 +2,9 @@ import type { UtilsSettings } from './../../../canvas/constants/app';
2
2
  import type { Circle, DrawableShape, Line, Rect } from './../../../common/types/Shapes';
3
3
  export declare const createRecPath: (rect: Rect) => Path2D;
4
4
  export declare const createCirclePath: (shape: Circle) => Path2D;
5
- export declare const createEllipsePath: (ellipse: DrawableShape<'ellipse'>) => Path2D;
5
+ export declare const createEllipsePath: (ellipse: DrawableShape<"ellipse">) => Path2D;
6
6
  export declare const createLinePath: (line: Line) => Path2D;
7
- export declare const createBrushPath: (brush: DrawableShape<'brush'>, settings: UtilsSettings) => Path2D | undefined;
8
- export declare const createCurvePath: (curve: DrawableShape<'curve'>) => Path2D | undefined;
9
- export declare const createPolygonPath: (polygon: DrawableShape<'polygon'>) => Path2D | undefined;
10
- export declare const createTrianglePath: (triangle: DrawableShape<'triangle'>) => Path2D;
7
+ export declare const createBrushPath: (brush: DrawableShape<"brush">, settings: UtilsSettings) => Path2D | undefined;
8
+ export declare const createCurvePath: (curve: DrawableShape<"curve">) => Path2D | undefined;
9
+ export declare const createPolygonPath: (polygon: DrawableShape<"polygon">) => Path2D | undefined;
10
+ export declare const createTrianglePath: (triangle: DrawableShape<"triangle">) => Path2D;
@@ -3,10 +3,10 @@ import type { SelectionModeResize } from './../../../common/types/Mode';
3
3
  import type { DrawableShape, Picture, Point, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
4
  export declare const refreshPicture: <T extends DrawableShape<"picture">>(shape: T, settings: UtilsSettings) => T;
5
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;
6
+ export declare const drawPicture: (ctx: CanvasRenderingContext2D, picture: DrawableShape<"picture">) => void;
7
7
  export declare const getPictureBorder: (picture: Picture, settings: UtilsSettings) => Rect;
8
8
  export declare const translatePicture: <U extends DrawableShape<"picture">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
9
9
  x: number;
10
10
  y: number;
11
11
  };
12
- export declare const resizePicture: (cursorPosition: Point, originalShape: DrawableShape<'picture'>, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio: boolean) => DrawableShape<'picture'>;
12
+ export declare const resizePicture: (cursorPosition: Point, originalShape: DrawableShape<"picture">, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio: boolean) => DrawableShape<"picture">;
@@ -5,13 +5,13 @@ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshPolygon: <T extends DrawableShape<"polygon">>(shape: T, settings: UtilsSettings) => T;
6
6
  export declare const createPolygon: (shape: {
7
7
  id: string;
8
- type: 'polygon';
9
- settings: ToolsSettingsType<'polygon'>;
10
- }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<'polygon'>;
11
- export declare const drawPolygon: (ctx: CanvasRenderingContext2D, polygon: DrawableShape<'polygon'>) => void;
8
+ type: "polygon";
9
+ settings: ToolsSettingsType<"polygon">;
10
+ }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"polygon">;
11
+ export declare const drawPolygon: (ctx: CanvasRenderingContext2D, polygon: DrawableShape<"polygon">) => void;
12
12
  export declare const getPolygonBorder: (polygon: Polygon, settings: UtilsSettings) => Rect;
13
13
  export declare const translatePolygon: <U extends DrawableShape<"polygon">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
14
14
  points: [number, number][];
15
15
  };
16
- export declare const resizePolygon: (cursorPosition: Point, originalShape: DrawableShape<'polygon'>, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => DrawableShape<'polygon'>;
16
+ export declare const resizePolygon: (cursorPosition: Point, originalShape: DrawableShape<"polygon">, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => DrawableShape<"polygon">;
17
17
  export declare const updatePolygonLinesCount: <T extends DrawableShape<"polygon">>(shape: T, newPointsCount: number, settings: UtilsSettings) => T;
@@ -9,7 +9,7 @@ export declare const createRectangle: <T extends "rect" | "square">(shape: {
9
9
  type: T;
10
10
  settings: ToolsSettingsType<T>;
11
11
  }, cursorPosition: Point, settings: UtilsSettings, width?: number, height?: number) => ShapeEntity<T>;
12
- export declare const drawRect: (ctx: CanvasRenderingContext2D, shape: DrawableShape<'rect' | 'square'>) => void;
12
+ export declare const drawRect: (ctx: CanvasRenderingContext2D, shape: DrawableShape<"rect" | "square">) => void;
13
13
  export declare const getRectBorder: (rect: Rect, settings: UtilsSettings) => Rect;
14
14
  export declare const getRectOppositeAnchorAbsolutePosition: <T extends DrawableShape & Rect>(anchor: Point, center: Point, shape: T, settings: UtilsSettings, [negW, negH]?: [boolean, boolean]) => Point;
15
15
  export declare const translateRect: <T extends "rect" | "square", U extends DrawableShape<T>>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
@@ -6,14 +6,14 @@ export declare const refreshText: <T extends DrawableShape<"text">>(shape: T, se
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: {
8
8
  id: string;
9
- type: 'text';
10
- settings: ToolsSettingsType<'text'>;
11
- }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<'text'>;
12
- export declare const drawText: (ctx: CanvasRenderingContext2D, text: DrawableShape<'text'>) => void;
9
+ type: "text";
10
+ settings: ToolsSettingsType<"text">;
11
+ }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<"text">;
12
+ export declare const drawText: (ctx: CanvasRenderingContext2D, text: DrawableShape<"text">) => void;
13
13
  export declare const getTextBorder: (text: Text, settings: UtilsSettings) => Rect;
14
14
  export declare const translateText: <U extends DrawableShape<"text">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
15
15
  x: number;
16
16
  y: number;
17
17
  };
18
- export declare const resizeText: (ctx: CanvasRenderingContext2D, cursorPosition: Point, originalShape: DrawableShape<'text'>, selectionMode: SelectionModeResize, settings: UtilsSettings) => DrawableShape<'text'>;
18
+ export declare const resizeText: (ctx: CanvasRenderingContext2D, cursorPosition: Point, originalShape: DrawableShape<"text">, selectionMode: SelectionModeResize, settings: UtilsSettings) => DrawableShape<"text">;
19
19
  export declare const resizeTextShapeWithNewContent: <U extends DrawableShape<"text">>(ctx: CanvasRenderingContext2D, shape: U, newValue: string[], settings: UtilsSettings) => U;
@@ -1,3 +1,3 @@
1
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;
2
+ export declare const createTriangle: (triangle: Triangle) => DrawableShape<"triangle">;
3
+ export declare const drawTriangle: (ctx: CanvasRenderingContext2D, triangle: DrawableShape<"triangle">) => void;
@@ -9,7 +9,7 @@ export declare const roundRotationForGrid: (rotation: number, settings: UtilsSet
9
9
  export declare const transformShape: (ctx: CanvasRenderingContext2D, shape: ShapeEntity, cursorPosition: Point, selectionMode: SelectionModeData<Point | number>, settings: UtilsSettings, isShiftPressed: boolean) => ShapeEntity;
10
10
  export declare const fitContentInsideContainer: (contentWidth: number, contentHeight: number, containerWidth: number, containerHeight: number, shouldFillContainer?: boolean) => number[];
11
11
  export declare const shortenLine: ({ line, size, direction }: {
12
- line: DrawableShape<'line'>;
12
+ line: DrawableShape<"line">;
13
13
  size: number;
14
- direction: 'start' | 'end' | 'both';
14
+ direction: "start" | "end" | "both";
15
15
  }) => Line;
@@ -1,11 +1,39 @@
1
1
  import type { ShapeType } from './Shapes';
2
2
  export type CustomToolInput = {
3
3
  id: string;
4
- type: ShapeType;
5
4
  icon?: string;
6
5
  label?: string;
7
- settings?: ToolsSettingsType<ShapeType>;
8
- };
6
+ } & ({
7
+ type: 'brush';
8
+ settings: ToolsSettingsType<'brush'>;
9
+ } | {
10
+ type: 'circle';
11
+ settings: ToolsSettingsType<'circle'>;
12
+ } | {
13
+ type: 'ellipse';
14
+ settings: ToolsSettingsType<'ellipse'>;
15
+ } | {
16
+ type: 'rect';
17
+ settings: ToolsSettingsType<'rect'>;
18
+ } | {
19
+ type: 'square';
20
+ settings: ToolsSettingsType<'square'>;
21
+ } | {
22
+ type: 'line';
23
+ settings: ToolsSettingsType<'line'>;
24
+ } | {
25
+ type: 'polygon';
26
+ settings: ToolsSettingsType<'polygon'>;
27
+ } | {
28
+ type: 'curve';
29
+ settings: ToolsSettingsType<'curve'>;
30
+ } | {
31
+ type: 'text';
32
+ settings: ToolsSettingsType<'text'>;
33
+ } | {
34
+ type: 'picture';
35
+ settings: ToolsSettingsType<'picture'>;
36
+ });
9
37
  export type CustomTool = {
10
38
  id: string;
11
39
  icon: string;
@@ -47,18 +75,21 @@ export type SettingsOpacity = {
47
75
  max: number;
48
76
  step: number;
49
77
  default: number;
78
+ hidden?: boolean;
50
79
  };
51
80
  };
52
81
  export type SettingsStrokeColor = {
53
82
  strokeColor: {
54
83
  values: string[];
55
84
  default: string;
85
+ hidden?: boolean;
56
86
  };
57
87
  };
58
88
  export type SettingsFillColor = {
59
89
  fillColor: {
60
90
  values: string[];
61
91
  default: string;
92
+ hidden?: boolean;
62
93
  };
63
94
  };
64
95
  export type SettingsLineWidth = {
@@ -67,32 +98,38 @@ export type SettingsLineWidth = {
67
98
  max: number;
68
99
  step: number;
69
100
  default: number;
101
+ hidden?: boolean;
70
102
  };
71
103
  };
72
104
  export type SettingsLineDash = {
73
105
  lineDash: {
74
106
  values: number[];
75
107
  default: number;
108
+ hidden?: boolean;
76
109
  };
77
110
  };
78
111
  export type SettingsLineArrow = {
79
112
  lineArrow: {
80
113
  values: number[];
81
114
  default: number;
115
+ hidden?: boolean;
82
116
  };
83
117
  };
84
118
  export type SettingsFont = {
85
119
  fontFamily: {
86
120
  values: string[];
87
121
  default: string;
122
+ hidden?: boolean;
88
123
  };
89
124
  fontBold: {
90
125
  values: boolean[];
91
126
  default: boolean;
127
+ hidden?: boolean;
92
128
  };
93
129
  fontItalic: {
94
130
  values: boolean[];
95
131
  default: boolean;
132
+ hidden?: boolean;
96
133
  };
97
134
  };
98
135
  export type SettingsPointsCount = {
@@ -101,6 +138,7 @@ export type SettingsPointsCount = {
101
138
  max: number;
102
139
  step: number;
103
140
  default: number;
141
+ hidden?: boolean;
104
142
  };
105
143
  };
106
144
  export type ToolsRectSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash;
@@ -114,7 +152,7 @@ export type ToolsPolygonSettings = SettingsOpacity & SettingsStrokeColor & Setti
114
152
  export type ToolsCurveSettings = SettingsOpacity & SettingsStrokeColor & SettingsFillColor & SettingsLineWidth & SettingsLineDash & SettingsPointsCount;
115
153
  export type ToolsTriangleSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash;
116
154
  export type ToolsPictureSettings = SettingsOpacity;
117
- 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 : unknown;
155
+ 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;
118
156
  export type ActionsType = 'selection' | 'undo' | 'redo' | 'clear' | 'export' | 'loadfile' | 'savefile' | 'move' | 'uploadpicture' | 'addurlpicture';
119
157
  export type ActionsTool = {
120
158
  id: string;