@yorab/react-paint 0.18.1 → 1.0.0-beta.1

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 (247) hide show
  1. package/README.md +266 -22
  2. package/dist/_chunks/canvas-CDYlr833.js +1 -0
  3. package/dist/_chunks/editor-BARYd5Od.js +1 -0
  4. package/dist/canvas/components/Canvas.d.ts +15 -3
  5. package/dist/canvas/components/EditTextBox.d.ts +4 -4
  6. package/dist/canvas/constants/app.d.ts +32 -17
  7. package/dist/canvas/constants/grid.d.ts +7 -0
  8. package/dist/canvas/constants/picture.d.ts +8 -0
  9. package/dist/canvas/constants/shapes.d.ts +2 -2
  10. package/dist/canvas/constants/tools.d.ts +12 -2
  11. package/dist/canvas/constants/zoom.d.ts +4 -2
  12. package/dist/canvas/context/PaintContext.d.ts +9 -0
  13. package/dist/canvas/hooks/useAnnotationsStyle.d.ts +5 -0
  14. package/dist/canvas/hooks/useAutoScroll.d.ts +4 -0
  15. package/dist/canvas/hooks/useCanvasRenderer.d.ts +17 -0
  16. package/dist/canvas/hooks/useDrawableCanvas.d.ts +8 -5
  17. package/dist/canvas/hooks/useDropPicture.d.ts +7 -0
  18. package/dist/canvas/hooks/useKeyboard.d.ts +6 -32
  19. package/dist/canvas/hooks/usePaintState.d.ts +9 -0
  20. package/dist/canvas/hooks/usePinchZoomAndMove.d.ts +3 -13
  21. package/dist/canvas/hooks/useReactPaint.d.ts +11 -163
  22. package/dist/canvas/hooks/useResizeObserver.d.ts +1 -0
  23. package/dist/canvas/hooks/useShapeEvents.d.ts +7 -0
  24. package/dist/canvas/hooks/useZoom.d.ts +4 -17
  25. package/dist/canvas/index.d.ts +24 -17
  26. package/dist/canvas/index.js +1 -1
  27. package/dist/canvas/store/createStore.d.ts +14 -0
  28. package/dist/canvas/store/eventEmitter.d.ts +11 -0
  29. package/dist/canvas/store/internal.d.ts +5 -0
  30. package/dist/canvas/store/paintStore.d.ts +898 -0
  31. package/dist/canvas/store/selectors.d.ts +855 -0
  32. package/dist/canvas/store/shapesReducer.d.ts +66 -0
  33. package/dist/canvas/store/types.d.ts +72 -0
  34. package/dist/canvas/types/Canvas.d.ts +19 -0
  35. package/dist/{src/common → canvas}/types/Mode.d.ts +8 -15
  36. package/dist/{common → canvas}/types/Settings.d.ts +6 -1
  37. package/dist/{common → canvas}/types/Shapes.d.ts +27 -21
  38. package/dist/canvas/types/editor.d.ts +388 -0
  39. package/dist/{common → canvas}/types/tools.d.ts +10 -6
  40. package/dist/{common → canvas}/utils/array.d.ts +2 -0
  41. package/dist/canvas/utils/canvas.d.ts +18 -2
  42. package/dist/canvas/utils/click.d.ts +17 -0
  43. package/dist/canvas/utils/data.d.ts +6 -5
  44. package/dist/canvas/utils/equality.d.ts +5 -0
  45. package/dist/canvas/utils/file.d.ts +36 -266
  46. package/dist/canvas/utils/grid.d.ts +1 -1
  47. package/dist/canvas/utils/intersect.d.ts +24 -14
  48. package/dist/canvas/utils/object.d.ts +11 -0
  49. package/dist/{src/common/utils/selection.d.ts → canvas/utils/selectedShapes.d.ts} +2 -2
  50. package/dist/canvas/utils/selection/anchors.d.ts +16 -0
  51. package/dist/canvas/utils/selection/groupSelection.d.ts +3 -3
  52. package/dist/canvas/utils/selection/lineSelection.d.ts +3 -10
  53. package/dist/canvas/utils/selection/rectSelection.d.ts +6 -11
  54. package/dist/canvas/utils/selection/selectionFrame.d.ts +2 -2
  55. package/dist/canvas/utils/selection.d.ts +7 -5
  56. package/dist/canvas/utils/shapeInput.d.ts +45 -0
  57. package/dist/canvas/utils/shapePatch.d.ts +10 -0
  58. package/dist/canvas/utils/shapes/brush.d.ts +6 -6
  59. package/dist/canvas/utils/shapes/circle.d.ts +5 -5
  60. package/dist/canvas/utils/shapes/curve.d.ts +4 -4
  61. package/dist/canvas/utils/shapes/ellipse.d.ts +5 -5
  62. package/dist/canvas/utils/shapes/group.d.ts +9 -3
  63. package/dist/canvas/utils/shapes/index.d.ts +31 -5
  64. package/dist/canvas/utils/shapes/line.d.ts +5 -5
  65. package/dist/canvas/utils/shapes/path.d.ts +16 -8
  66. package/dist/canvas/utils/shapes/picture.d.ts +7 -5
  67. package/dist/canvas/utils/shapes/polygon.d.ts +4 -4
  68. package/dist/canvas/utils/shapes/rectangle.d.ts +5 -5
  69. package/dist/canvas/utils/shapes/text.d.ts +12 -6
  70. package/dist/canvas/utils/shapes/triangle.d.ts +2 -2
  71. package/dist/canvas/utils/tools.d.ts +12 -3
  72. package/dist/canvas/utils/transform.d.ts +5 -4
  73. package/dist/canvas/utils/trigo.d.ts +17 -1
  74. package/dist/canvas/utils/util.d.ts +14 -0
  75. package/dist/canvas/utils/zoom.d.ts +29 -15
  76. package/dist/editor/components/common/Button.d.ts +0 -1
  77. package/dist/editor/components/common/FileInput.d.ts +0 -1
  78. package/dist/editor/components/common/Loading.d.ts +1 -2
  79. package/dist/editor/components/common/Menu.d.ts +3 -2
  80. package/dist/editor/components/common/Modal.d.ts +1 -2
  81. package/dist/editor/components/common/Panel.d.ts +1 -2
  82. package/dist/editor/components/common/Snackbar.d.ts +2 -3
  83. package/dist/editor/components/settings/ClosedPointsField.d.ts +1 -1
  84. package/dist/editor/components/settings/ColorField.d.ts +1 -2
  85. package/dist/editor/components/settings/DeleteButton.d.ts +3 -4
  86. package/dist/editor/components/settings/FontFamilyField.d.ts +1 -2
  87. package/dist/editor/components/settings/LayoutButton.d.ts +1 -2
  88. package/dist/editor/components/settings/Layouts.d.ts +4 -15
  89. package/dist/editor/components/settings/LineArrowField.d.ts +1 -2
  90. package/dist/editor/components/settings/LineTypeField.d.ts +2 -3
  91. package/dist/editor/components/settings/RangeField.d.ts +1 -2
  92. package/dist/editor/components/settings/SelectField.d.ts +1 -2
  93. package/dist/editor/components/settings/SettingsBar.d.ts +3 -18
  94. package/dist/editor/components/settings/ToggleField.d.ts +2 -1
  95. package/dist/editor/components/settings/ZoomButton.d.ts +1 -2
  96. package/dist/editor/components/settings/ZoomPanel.d.ts +4 -0
  97. package/dist/editor/components/toolbox/ActionButton.d.ts +9 -0
  98. package/dist/editor/components/toolbox/ContextMenu.d.ts +5 -24
  99. package/dist/editor/components/toolbox/ExportModal.d.ts +1 -2
  100. package/dist/editor/components/toolbox/LoadFileTool.d.ts +4 -4
  101. package/dist/editor/components/toolbox/MenuGroup.d.ts +1 -7
  102. package/dist/editor/components/toolbox/PictureUrlInput.d.ts +2 -2
  103. package/dist/editor/components/toolbox/Tool.d.ts +3 -3
  104. package/dist/editor/components/toolbox/Toolbar.d.ts +5 -16
  105. package/dist/editor/components/toolbox/ToolbarGroup.d.ts +2 -3
  106. package/dist/editor/constants/options.d.ts +11 -1
  107. package/dist/editor/constants/snackbar.d.ts +1 -1
  108. package/dist/editor/constants/style.d.ts +0 -9
  109. package/dist/editor/constants/tools.d.ts +12 -32
  110. package/dist/editor/editor.css +1 -0
  111. package/dist/editor/hooks/useDrag.d.ts +3 -3
  112. package/dist/editor/hooks/useMenu.d.ts +3 -2
  113. package/dist/editor/hooks/usePressOutside.d.ts +7 -0
  114. package/dist/editor/hooks/useSnackbar.d.ts +1 -1
  115. package/dist/editor/index.d.ts +12 -22
  116. package/dist/editor/index.js +1 -1
  117. package/dist/editor/types/tools.d.ts +7 -0
  118. package/dist/editor/utils/dom.d.ts +1 -0
  119. package/dist/editor/utils/style.d.ts +7 -1
  120. package/dist/editor/utils/toolbar.d.ts +1 -2
  121. package/dist/editor/utils/util.d.ts +5 -0
  122. package/dist/index.d.ts +2 -5
  123. package/dist/react-paint.css +1 -1
  124. package/dist/react-paint.js +1 -1
  125. package/dist/react-paint.umd.cjs +1 -1
  126. package/package.json +37 -26
  127. package/dist/_chunks/array-DuJem3vg.js +0 -1
  128. package/dist/_chunks/canvas-DF1RWuxW.js +0 -1
  129. package/dist/_chunks/editor-DuVskl0R.js +0 -1
  130. package/dist/canvas/context/CanvasContext.d.ts +0 -55
  131. package/dist/canvas/hooks/useComponent.d.ts +0 -12
  132. package/dist/canvas/hooks/useDoubleClick.d.ts +0 -5
  133. package/dist/canvas/hooks/useEventListener.d.ts +0 -2
  134. package/dist/canvas/hooks/useShapes.d.ts +0 -44
  135. package/dist/common/hooks/useDebounce.d.ts +0 -2
  136. package/dist/common/types/Canvas.d.ts +0 -8
  137. package/dist/common/types/Mode.d.ts +0 -64
  138. package/dist/common/types/react.d.ts +0 -6
  139. package/dist/common/utils/dom.d.ts +0 -1
  140. package/dist/common/utils/object.d.ts +0 -4
  141. package/dist/common/utils/selection.d.ts +0 -4
  142. package/dist/common/utils/util.d.ts +0 -3
  143. package/dist/editor/constants/grid.d.ts +0 -7
  144. package/dist/src/canvas/components/Canvas.d.ts +0 -4
  145. package/dist/src/canvas/components/EditTextBox.d.ts +0 -13
  146. package/dist/src/canvas/constants/app.d.ts +0 -37
  147. package/dist/src/canvas/constants/grid.d.ts +0 -1
  148. package/dist/src/canvas/constants/keyboard.d.ts +0 -27
  149. package/dist/src/canvas/constants/picture.d.ts +0 -1
  150. package/dist/src/canvas/constants/rendering.d.ts +0 -3
  151. package/dist/src/canvas/constants/shapes.d.ts +0 -10
  152. package/dist/src/canvas/constants/tools.d.ts +0 -4
  153. package/dist/src/canvas/constants/zoom.d.ts +0 -5
  154. package/dist/src/canvas/context/CanvasContext.d.ts +0 -55
  155. package/dist/src/canvas/hooks/useComponent.d.ts +0 -12
  156. package/dist/src/canvas/hooks/useDoubleClick.d.ts +0 -5
  157. package/dist/src/canvas/hooks/useDrawableCanvas.d.ts +0 -6
  158. package/dist/src/canvas/hooks/useEventListener.d.ts +0 -2
  159. package/dist/src/canvas/hooks/useKeyboard.d.ts +0 -33
  160. package/dist/src/canvas/hooks/usePinchZoomAndMove.d.ts +0 -17
  161. package/dist/src/canvas/hooks/useReactPaint.d.ts +0 -164
  162. package/dist/src/canvas/hooks/useResizeObserver.d.ts +0 -6
  163. package/dist/src/canvas/hooks/useShapes.d.ts +0 -44
  164. package/dist/src/canvas/hooks/useZoom.d.ts +0 -22
  165. package/dist/src/canvas/index.d.ts +0 -19
  166. package/dist/src/canvas/utils/canvas.d.ts +0 -15
  167. package/dist/src/canvas/utils/data.d.ts +0 -5
  168. package/dist/src/canvas/utils/file.d.ts +0 -274
  169. package/dist/src/canvas/utils/grid.d.ts +0 -2
  170. package/dist/src/canvas/utils/intersect.d.ts +0 -27
  171. package/dist/src/canvas/utils/selection/groupSelection.d.ts +0 -4
  172. package/dist/src/canvas/utils/selection/lineSelection.d.ts +0 -19
  173. package/dist/src/canvas/utils/selection/rectSelection.d.ts +0 -20
  174. package/dist/src/canvas/utils/selection/selectionFrame.d.ts +0 -3
  175. package/dist/src/canvas/utils/selection.d.ts +0 -12
  176. package/dist/src/canvas/utils/shapes/brush.d.ts +0 -21
  177. package/dist/src/canvas/utils/shapes/circle.d.ts +0 -18
  178. package/dist/src/canvas/utils/shapes/curve.d.ts +0 -17
  179. package/dist/src/canvas/utils/shapes/ellipse.d.ts +0 -18
  180. package/dist/src/canvas/utils/shapes/group.d.ts +0 -33
  181. package/dist/src/canvas/utils/shapes/index.d.ts +0 -35
  182. package/dist/src/canvas/utils/shapes/line.d.ts +0 -19
  183. package/dist/src/canvas/utils/shapes/path.d.ts +0 -29
  184. package/dist/src/canvas/utils/shapes/picture.d.ts +0 -13
  185. package/dist/src/canvas/utils/shapes/polygon.d.ts +0 -18
  186. package/dist/src/canvas/utils/shapes/rectangle.d.ts +0 -22
  187. package/dist/src/canvas/utils/shapes/text.d.ts +0 -27
  188. package/dist/src/canvas/utils/shapes/triangle.d.ts +0 -4
  189. package/dist/src/canvas/utils/transform.d.ts +0 -15
  190. package/dist/src/canvas/utils/trigo.d.ts +0 -19
  191. package/dist/src/canvas/utils/zoom.d.ts +0 -58
  192. package/dist/src/common/hooks/useDebounce.d.ts +0 -2
  193. package/dist/src/common/types/Canvas.d.ts +0 -8
  194. package/dist/src/common/types/Settings.d.ts +0 -24
  195. package/dist/src/common/types/Shapes.d.ts +0 -153
  196. package/dist/src/common/types/react.d.ts +0 -6
  197. package/dist/src/common/types/tools.d.ts +0 -164
  198. package/dist/src/common/types/utils.d.ts +0 -4
  199. package/dist/src/common/utils/array.d.ts +0 -2
  200. package/dist/src/common/utils/dom.d.ts +0 -1
  201. package/dist/src/common/utils/object.d.ts +0 -4
  202. package/dist/src/common/utils/util.d.ts +0 -3
  203. package/dist/src/editor/components/common/Button.d.ts +0 -16
  204. package/dist/src/editor/components/common/FileInput.d.ts +0 -13
  205. package/dist/src/editor/components/common/Loading.d.ts +0 -6
  206. package/dist/src/editor/components/common/Menu.d.ts +0 -10
  207. package/dist/src/editor/components/common/Modal.d.ts +0 -11
  208. package/dist/src/editor/components/common/Panel.d.ts +0 -15
  209. package/dist/src/editor/components/common/Snackbar.d.ts +0 -7
  210. package/dist/src/editor/components/settings/ClosedPointsField.d.ts +0 -10
  211. package/dist/src/editor/components/settings/ColorField.d.ts +0 -15
  212. package/dist/src/editor/components/settings/DeleteButton.d.ts +0 -8
  213. package/dist/src/editor/components/settings/FontFamilyField.d.ts +0 -12
  214. package/dist/src/editor/components/settings/LayoutButton.d.ts +0 -7
  215. package/dist/src/editor/components/settings/Layouts.d.ts +0 -19
  216. package/dist/src/editor/components/settings/LineArrowField.d.ts +0 -12
  217. package/dist/src/editor/components/settings/LineTypeField.d.ts +0 -16
  218. package/dist/src/editor/components/settings/RangeField.d.ts +0 -19
  219. package/dist/src/editor/components/settings/SelectField.d.ts +0 -18
  220. package/dist/src/editor/components/settings/SettingsBar.d.ts +0 -26
  221. package/dist/src/editor/components/settings/ToggleField.d.ts +0 -13
  222. package/dist/src/editor/components/settings/ZoomButton.d.ts +0 -8
  223. package/dist/src/editor/components/toolbox/ContextMenu.d.ts +0 -25
  224. package/dist/src/editor/components/toolbox/ExportModal.d.ts +0 -7
  225. package/dist/src/editor/components/toolbox/LoadFileTool.d.ts +0 -11
  226. package/dist/src/editor/components/toolbox/MenuGroup.d.ts +0 -27
  227. package/dist/src/editor/components/toolbox/PictureUrlInput.d.ts +0 -7
  228. package/dist/src/editor/components/toolbox/Tool.d.ts +0 -11
  229. package/dist/src/editor/components/toolbox/Toolbar.d.ts +0 -26
  230. package/dist/src/editor/components/toolbox/ToolbarGroup.d.ts +0 -14
  231. package/dist/src/editor/constants/grid.d.ts +0 -7
  232. package/dist/src/editor/constants/icons.d.ts +0 -43
  233. package/dist/src/editor/constants/loading.d.ts +0 -1
  234. package/dist/src/editor/constants/options.d.ts +0 -13
  235. package/dist/src/editor/constants/snackbar.d.ts +0 -7
  236. package/dist/src/editor/constants/style.d.ts +0 -14
  237. package/dist/src/editor/constants/tools.d.ts +0 -32
  238. package/dist/src/editor/hooks/useDrag.d.ts +0 -15
  239. package/dist/src/editor/hooks/useMenu.d.ts +0 -11
  240. package/dist/src/editor/hooks/useSnackbar.d.ts +0 -10
  241. package/dist/src/editor/index.d.ts +0 -25
  242. package/dist/src/editor/types/snackbar.d.ts +0 -7
  243. package/dist/src/editor/utils/style.d.ts +0 -2
  244. package/dist/src/editor/utils/toolbar.d.ts +0 -11
  245. package/dist/src/index.d.ts +0 -5
  246. /package/dist/{common → canvas}/types/utils.d.ts +0 -0
  247. /package/dist/{canvas → editor}/hooks/useDebounce.d.ts +0 -0
@@ -1,5 +1,7 @@
1
- export declare const ZOOM_STEPS: number[];
2
- export declare const ZOOM_STEP_DEFAULT = 4;
1
+ /** Levels of setZoom, from the smallest to the largest zoom: every zoom stays between them */
2
+ export declare const ZOOM_LEVELS: readonly [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8];
3
+ /** Index of the zoom 1 in ZOOM_LEVELS */
4
+ export declare const ZOOM_LEVEL_DEFAULT = 4;
3
5
  export declare const ZOOM_BG_COLOR = "#f5f5f5";
4
6
  export declare const ZOOM_DETECTION_OFFSET = 30;
5
7
  export declare const IOS_TRACKPAD_PINCH_FACTOR = 5;
@@ -0,0 +1,9 @@
1
+ import type { ReactPaint } from './../../canvas/types/editor.js';
2
+ import { type ReactNode } from 'react';
3
+ /** Gives a canvas handle to the components below, which read it with usePaint. The Editor component already provides it */
4
+ export declare const PaintProvider: ({ paint, children }: {
5
+ paint: ReactPaint;
6
+ children?: ReactNode;
7
+ }) => import("react").JSX.Element;
8
+ /** Returns the canvas handle given by the closest PaintProvider or Editor */
9
+ export declare const usePaint: () => ReactPaint;
@@ -0,0 +1,5 @@
1
+ import type { ReactPaint } from './../../canvas/types/editor.js';
2
+ import { type CSSProperties } from 'react';
3
+ /** Style of an element laid over the canvas, like a picture to annotate, so that it follows the zoom and the moves of the view */
4
+ declare const useAnnotationsStyle: (paint: ReactPaint) => CSSProperties;
5
+ export default useAnnotationsStyle;
@@ -0,0 +1,4 @@
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
2
+ /** Scrolls the view while a selection frame is drawn close to the borders of the canvas, once per frame */
3
+ declare const useAutoScroll: (store: PaintStore) => void;
4
+ export default useAutoScroll;
@@ -0,0 +1,17 @@
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
2
+ import type { CanvasSize } from './../../canvas/types/Canvas.js';
3
+ import type React from 'react';
4
+ type UseCanvasRendererProps = {
5
+ store: PaintStore;
6
+ drawCanvas: HTMLCanvasElement | null;
7
+ selectionCanvasRef: React.RefObject<HTMLCanvasElement | null>;
8
+ selectionColor: string;
9
+ selectionWidth: number;
10
+ canvasSize: CanvasSize;
11
+ };
12
+ /**
13
+ * Draws the two layers of the canvas when their inputs change, outside of the renders of React:
14
+ * each layer is drawn at most once per frame, with the last state.
15
+ */
16
+ declare const useCanvasRenderer: ({ store, drawCanvas, selectionCanvasRef, selectionColor, selectionWidth, canvasSize }: UseCanvasRendererProps) => void;
17
+ export default useCanvasRenderer;
@@ -1,6 +1,9 @@
1
- import type { HoverModeData } from './../../common/types/Mode';
2
- import type React from 'react';
3
- declare const useDrawableCanvas: (drawCanvasRef: React.RefObject<HTMLCanvasElement | null>) => {
4
- hoverMode: HoverModeData;
5
- };
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
2
+ /**
3
+ * Pointer interactions of the draw canvas, for the mouse, the touch and the pen. The listeners are set once and read the state
4
+ * of the store when an event happens: the gestures do not need any render of React.
5
+ * They are set on the canvas only, so that a page with many canvases only notifies the one under the pointer:
6
+ * a gesture captures its pointer, to keep receiving its moves outside of the canvas.
7
+ */
8
+ declare const useDrawableCanvas: (store: PaintStore, canvas: HTMLCanvasElement | null) => void;
6
9
  export default useDrawableCanvas;
@@ -0,0 +1,7 @@
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
2
+ /**
3
+ * Adds the image files dropped from the file explorer on the canvas as pictures, centered on the cursor. Without this,
4
+ * the browser would open the file. Nothing is prevented when the drop is not allowed (withDropPicture, edition, picture tool).
5
+ */
6
+ declare const useDropPicture: (store: PaintStore, canvas: HTMLCanvasElement | null) => void;
7
+ export default useDropPicture;
@@ -1,33 +1,7 @@
1
- import type { UtilsSettings } from './../../canvas/constants/app';
2
- import type { SelectionModeData } from './../../common/types/Mode';
3
- import type { Point, SelectionType, ShapeEntity } from './../../common/types/Shapes';
4
- import type { ToolsType } from './../../common/types/tools';
5
- type UseKeyboardType = {
6
- isInsideComponent: boolean;
7
- isInsideCanvas: boolean;
8
- selectedShape: SelectionType | undefined;
9
- pasteShapes: (shape: ShapeEntity[]) => void;
10
- updateShapes: (shapes: ShapeEntity[]) => void;
11
- setSelectedShape: (value: React.SetStateAction<SelectionType | undefined>) => void;
12
- selectAllShapes: () => void;
13
- removeShape: (shape: ShapeEntity[]) => void;
14
- backwardShape: () => void;
15
- forwardShape: () => void;
16
- setShiftPressed: (value: React.SetStateAction<boolean>) => void;
17
- setAltPressed: (value: React.SetStateAction<boolean>) => void;
18
- setIsSpacePressed: (value: React.SetStateAction<boolean>) => void;
19
- isEditingText: boolean;
20
- setActiveTool: (tool: ToolsType) => void;
21
- setSelectionMode: (mode: SelectionModeData<number | Point>) => void;
22
- setSelectionFrame: (args: {
23
- oldSelection: SelectionType | undefined;
24
- frame: [Point, Point];
25
- } | undefined) => void;
26
- settings: UtilsSettings;
27
- setCanvasZoom: (action: 'unzoom' | 'zoom' | 'default') => void;
28
- resetZoom: () => void;
29
- copiedShape: SelectionType | undefined;
30
- setCopiedShape: (shape: React.SetStateAction<SelectionType | undefined>) => void;
31
- };
32
- declare const useKeyboard: ({ isInsideComponent, isInsideCanvas, selectedShape, isEditingText, settings, copiedShape, setCopiedShape, setSelectedShape, setActiveTool, setCanvasZoom, resetZoom, setSelectionMode, setSelectionFrame, selectAllShapes, removeShape, pasteShapes, updateShapes, backwardShape, forwardShape, setShiftPressed, setAltPressed, setIsSpacePressed }: UseKeyboardType) => {};
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
2
+ /**
3
+ * Keyboard shortcuts and modifiers. The listeners are set once on the scope (the Canvas, or the area set by scopeRef),
4
+ * which only receives the events while the focus is inside it, and read the state when an event happens.
5
+ */
6
+ declare const useKeyboard: (store: PaintStore) => void;
33
7
  export default useKeyboard;
@@ -0,0 +1,9 @@
1
+ import type { EditorState, ReactPaint } from './../../canvas/types/editor.js';
2
+ /**
3
+ * Reads the state of a canvas during the render, and renders again only when the selected value changes.
4
+ * Without selector, returns the whole state. A selector building an object or an array needs an equality
5
+ * function, like shallowEqual, otherwise the component renders on each change of the state.
6
+ */
7
+ declare function usePaintState(paint: ReactPaint): EditorState;
8
+ declare function usePaintState<T>(paint: ReactPaint, selector: (state: EditorState) => T, isEqual?: (a: T, b: T) => boolean): T;
9
+ export default usePaintState;
@@ -1,17 +1,7 @@
1
- import type { CanvasSize, Size } from './../../common/types/Canvas';
2
- import type { Point } from './../../common/types/Shapes';
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
3
2
  type UsePinchZoomProps = {
3
+ store: PaintStore;
4
4
  canvasElt: HTMLElement | null;
5
- canvasTransformation: {
6
- offset: Point;
7
- zoom: number;
8
- };
9
- canvasSize: CanvasSize;
10
- size: Size;
11
- setCanvasTransformation: (transformation: {
12
- offset: Point;
13
- zoom: number;
14
- }) => void;
15
5
  };
16
- declare const usePinchZoomAndMove: ({ canvasElt, canvasTransformation, canvasSize, size, setCanvasTransformation }: UsePinchZoomProps) => void;
6
+ declare const usePinchZoomAndMove: ({ store, canvasElt }: UsePinchZoomProps) => void;
17
7
  export default usePinchZoomAndMove;
@@ -1,164 +1,12 @@
1
- import { type OptionalOptions, type UtilsSettings } from './../../canvas/constants/app';
2
- import { calculateTextFontSize } from './../../canvas/utils/shapes/text';
3
- import type { CanvasSize } from './../../common/types/Canvas';
4
- import type { SelectionModeData } from './../../common/types/Mode';
5
- import type { ExportedDrawableShape, Point, SelectionType, ShapeEntity, StateData } from './../../common/types/Shapes';
6
- import type { CustomTool, ToolsType } from './../../common/types/tools';
7
- import { type CSSProperties } from 'react';
8
- type UseReactPaintProps = {
9
- width?: number | undefined;
10
- height?: number | undefined;
11
- shapes?: ExportedDrawableShape[] | undefined;
12
- mode?: 'editor' | 'viewer' | undefined;
13
- disabled?: boolean | undefined;
14
- options?: OptionalOptions | undefined;
15
- };
16
- export type EditorProps = {
17
- shapes: ShapeEntity[];
18
- addPictureShape: (fileOrUrl: File | string, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity>;
19
- swapShapes: (startPositionShapeId: string, endPositionShapeId: string) => void;
20
- moveShapes: (shapes: ShapeEntity[], action: 'first' | 'last' | 'forward' | 'backward') => void;
21
- toggleShapeVisibility: (shapes: ShapeEntity[]) => void;
22
- toggleShapeLock: (shapeGroup: ShapeEntity[]) => void;
23
- canGoBackward: boolean;
24
- canGoForward: boolean;
25
- canClear: boolean;
26
- selectedShape: SelectionType | undefined;
27
- copiedShape: SelectionType | undefined;
28
- setCopiedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
29
- pasteShapes: (shapes: ShapeEntity[]) => void;
30
- saveShapes: () => void;
31
- removeShape: (shapes: ShapeEntity[]) => void;
32
- updateShape: (updatedShapes: ShapeEntity[], withSave?: boolean) => void;
33
- duplicateShapes: (shapesToDuplicate: ShapeEntity[], translate?: boolean, selectNewOnes?: boolean) => void;
34
- backwardShape: () => void;
35
- forwardShape: () => void;
36
- removeShapePoint: (shape: ShapeEntity<'curve' | 'polygon'>, pointIndex: number) => void;
37
- transformShape: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], center: Point, action: 'flipHorizontally' | 'flipVertically' | 'rotateClockwise' | 'rotateCounterclockwise') => void;
38
- refs: {
39
- canvas: React.RefObject<HTMLCanvasElement | null>;
40
- editor: React.RefObject<HTMLElement | null>;
41
- setEditor: (node: HTMLElement | null) => void;
42
- };
43
- width: number;
44
- height: number;
45
- selectTool: (tool: ToolsType) => void;
46
- selectShapes: (shapes: ShapeEntity[]) => void;
47
- selectAllShapes: () => void;
48
- activeTool: ToolsType;
49
- setActiveTool: React.Dispatch<React.SetStateAction<ToolsType>>;
50
- setAvailableTools: React.Dispatch<React.SetStateAction<CustomTool[]>>;
51
- isEditMode: boolean;
52
- availableTools: CustomTool[];
53
- gridGap: number;
54
- setGridGap: React.Dispatch<React.SetStateAction<number>>;
55
- loadFile: (file: File) => Promise<void>;
56
- exportPicture: (view: 'fitToShapes' | 'defaultView' | 'currentZoom') => void;
57
- exportData: () => void;
58
- clearCanvas: () => void;
59
- selectionMode: SelectionModeData<number | Point>;
60
- setSelectionMode: React.Dispatch<React.SetStateAction<SelectionModeData<number | Point>>>;
61
- settings: UtilsSettings;
62
- setCanvasZoom: (action: 'unzoom' | 'zoom' | 'default') => void;
63
- resetZoom: () => void;
64
- buildShapesGroup: (shapes: ShapeEntity[]) => SelectionType | undefined;
65
- copyShapes: (selection: SelectionType) => ShapeEntity[];
66
- refreshShape: (shape: ShapeEntity) => ShapeEntity;
67
- calculateTextFontSize: typeof calculateTextFontSize;
68
- canvas: {
69
- canGrow: boolean;
70
- canShrink: boolean;
71
- layersManipulation: boolean;
72
- withExport: boolean;
73
- withLoadAndSave: boolean;
74
- withUploadPicture: boolean;
75
- withUrlPicture: boolean;
76
- withContextMenu: boolean;
77
- };
78
- };
79
- type CanvasProps = {
80
- shapes: ShapeEntity[];
81
- selectedShape: SelectionType | undefined;
82
- copiedShape: SelectionType | undefined;
83
- setCopiedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
84
- pasteShapes: (shapes: ShapeEntity[]) => void;
85
- selectionFrame: {
86
- oldSelection: SelectionType | undefined;
87
- frame: [Point, Point];
88
- } | undefined;
89
- hoveredShape: ShapeEntity | undefined;
90
- addShape: (newShapes: ShapeEntity[]) => void;
91
- setSelectedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
92
- setSelectionFrame: React.Dispatch<React.SetStateAction<{
93
- oldSelection: SelectionType | undefined;
94
- frame: [Point, Point];
95
- } | undefined>>;
96
- refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
97
- refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point, isInsideMask: boolean) => void;
98
- removeShape: (shapes: ShapeEntity[]) => void;
99
- updateShape: (updatedShapes: ShapeEntity[], withSave?: boolean) => void;
100
- duplicateShapes: (shapesToDuplicate: ShapeEntity[], translate?: boolean, selectNewOnes?: boolean) => void;
101
- backwardShape: () => void;
102
- forwardShape: () => void;
103
- saveShapes: () => void;
104
- refs: {
105
- canvas: React.RefObject<HTMLCanvasElement | null>;
106
- editor: React.RefObject<HTMLElement | null>;
107
- setEditor: (node: HTMLElement | null) => void;
108
- };
109
- width: number;
110
- height: number;
111
- selectShapes: (shapes: ShapeEntity[]) => void;
112
- selectAllShapes: () => void;
113
- activeTool: ToolsType;
114
- setActiveTool: React.Dispatch<React.SetStateAction<ToolsType>>;
115
- isEditMode: boolean;
116
- settings: UtilsSettings;
117
- setCanvasZoom: (action: 'unzoom' | 'zoom' | 'default') => void;
118
- resetZoom: () => void;
119
- setCanvasSize: React.Dispatch<React.SetStateAction<CanvasSize>>;
120
- setCanvasOffset: (offset: Point) => void;
121
- isInsideComponent: boolean;
122
- isInsideCanvas: boolean;
123
- canvas: {
124
- withContextMenu: boolean;
125
- withSkeleton: boolean;
126
- withFrameSelection: boolean;
127
- canGrow: boolean;
128
- canShrink: boolean;
129
- };
130
- canvasOffsetStartData: {
131
- start: Point;
132
- originalOffset: Point;
133
- } | undefined;
134
- setCanvasOffsetStartData: React.Dispatch<React.SetStateAction<{
135
- start: Point;
136
- originalOffset: Point;
137
- } | undefined>>;
138
- selectionMode: SelectionModeData<number | Point>;
139
- setSelectionMode: React.Dispatch<React.SetStateAction<SelectionModeData<number | Point>>>;
140
- setCanvasMoveAcceleration: React.Dispatch<React.SetStateAction<Point>>;
141
- isShiftPressed: boolean;
142
- isAltPressed: boolean;
143
- isSpacePressed: boolean;
144
- setShiftPressed: React.Dispatch<React.SetStateAction<boolean>>;
145
- setAltPressed: React.Dispatch<React.SetStateAction<boolean>>;
146
- setIsSpacePressed: React.Dispatch<React.SetStateAction<boolean>>;
147
- };
148
- export type UseReactPaintReturnType = {
149
- annotationsProps: {
150
- style: CSSProperties;
151
- };
152
- editorProps: EditorProps;
153
- canvasProps: CanvasProps;
154
- registerEvent: (event: 'dataChanged', fn: (data: StateData, source: 'user' | 'remote') => void) => void;
155
- unregisterEvent: (event: 'dataChanged', fn?: (data: StateData, source: 'user' | 'remote') => void) => void;
156
- resetCanvas: (json?: ExportedDrawableShape[], clearHistory?: boolean) => void;
157
- resetZoom: () => void;
158
- getCurrentImage: (view: 'fitToShapes' | 'defaultView' | 'currentZoom') => string;
159
- getCurrentData: () => StateData;
160
- setCanvasOffset: (offset: Point) => void;
161
- setCanvasZoom: (action: 'unzoom' | 'zoom' | 'default') => void;
162
- };
163
- declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disabled, options }?: UseReactPaintProps) => UseReactPaintReturnType;
1
+ import type { UseReactPaintProps } from './../../canvas/store/types.js';
2
+ import type { ReactPaint } from './../../canvas/types/editor.js';
3
+ export type { UseReactPaintProps } from './../../canvas/store/types.js';
4
+ /** Alias of ReactPaint */
5
+ export type UseReactPaintReturnType = ReactPaint;
6
+ /**
7
+ * Creates a canvas and returns its handle, to give to the Canvas and Editor components.
8
+ * The handle keeps its identity, and the component calling the hook does not render again when the state changes:
9
+ * read it with usePaintState.
10
+ */
11
+ declare const useReactPaint: (props?: UseReactPaintProps) => ReactPaint;
164
12
  export default useReactPaint;
@@ -2,5 +2,6 @@ type UseResizeObserverType = {
2
2
  element: React.RefObject<HTMLElement | null>;
3
3
  onResized: (width: number, height: number) => unknown;
4
4
  };
5
+ /** The element is observed before the first paint: its first size is given before it is shown */
5
6
  declare const useResizeObserver: ({ onResized, element }: UseResizeObserverType) => void;
6
7
  export default useResizeObserver;
@@ -0,0 +1,7 @@
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
2
+ /**
3
+ * Emits shapeClicked, canvasClicked, canvasDoubleClicked and shapeHovered, in every mode: in viewer mode the shapes can
4
+ * still be clicked. The listeners are independent of the gestures, and the shapes are only searched while these events are listened.
5
+ */
6
+ declare const useShapeEvents: (store: PaintStore, canvas: HTMLCanvasElement | null) => void;
7
+ export default useShapeEvents;
@@ -1,22 +1,9 @@
1
- import type { CanvasSize, Size } from './../../common/types/Canvas';
2
- import type { Point } from './../../common/types/Shapes';
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
3
2
  type UseZoomProps = {
4
- canvasSize: CanvasSize;
5
- size: Size;
3
+ store: PaintStore;
6
4
  canvasElt: HTMLCanvasElement | null;
7
5
  zoomEnabled: boolean;
8
6
  };
9
- declare const useZoom: ({ canvasSize, size, zoomEnabled, canvasElt }: UseZoomProps) => {
10
- setCanvasTransformation: import("react").Dispatch<import("react").SetStateAction<{
11
- offset: Point;
12
- zoom: number;
13
- }>>;
14
- setCanvasOffset: (newOffset: Point) => void;
15
- setCanvasZoom: (action: "unzoom" | "zoom" | "default") => void;
16
- resetZoom: () => void;
17
- canvasTransformation: {
18
- offset: Point;
19
- zoom: number;
20
- };
21
- };
7
+ /** Zooms and scrolls the canvas with the wheel, and with a pinch on touch screens */
8
+ declare const useZoom: ({ store, zoomEnabled, canvasElt }: UseZoomProps) => void;
22
9
  export default useZoom;
@@ -1,19 +1,26 @@
1
- import type { UseReactPaintReturnType } from './../canvas/hooks/useReactPaint';
1
+ import { type CanvasOptions } from './../canvas/constants/app.js';
2
+ import type { ReactPaint } from './../canvas/types/editor.js';
2
3
  import { type CSSProperties } from 'react';
3
- import './index.css';
4
- type AppProps = {
5
- canvasProps: UseReactPaintReturnType['canvasProps'];
6
- className?: string;
7
- style?: CSSProperties;
8
- options?: {
9
- canvasBackgroundColor?: string | undefined;
10
- canvasSelectionColor?: string | undefined;
11
- canvasSelectionWidth?: number | undefined;
12
- };
4
+ type CanvasComponentProps = {
5
+ /** Handle returned by useReactPaint */
6
+ paint: ReactPaint;
7
+ className?: string | undefined;
8
+ style?: CSSProperties | undefined;
9
+ options?: CanvasOptions | undefined;
13
10
  };
14
- declare const App: ({ options, className, style, canvasProps }: AppProps) => import("react/jsx-runtime").JSX.Element;
15
- export default App;
16
- export type { OptionalOptions } from './../canvas/constants/app';
17
- export { DEFAULT_OPTIONS } from './../canvas/constants/app';
18
- export { default as useReactPaint } from './../canvas/hooks/useReactPaint';
19
- export type { ExportedDrawableShape as DrawableShape, StateData } from './../common/types/Shapes';
11
+ declare const Canvas: ({ paint, options, className, style }: CanvasComponentProps) => import("react").JSX.Element;
12
+ export { type CanvasOptions, DEFAULT_OPTIONS, type OptionalOptions, type OptionalOptions as UseReactPaintOptions, type PictureSrcResolver } from './../canvas/constants/app.js';
13
+ export { GRID_PRESETS } from './../canvas/constants/grid.js';
14
+ export { DEFAULT_TOOLS, MOVE_TOOL, SELECTION_TOOL } from './../canvas/constants/tools.js';
15
+ export { ZOOM_LEVELS } from './../canvas/constants/zoom.js';
16
+ export { PaintProvider, usePaint } from './../canvas/context/PaintContext.js';
17
+ export { default as useAnnotationsStyle } from './../canvas/hooks/useAnnotationsStyle.js';
18
+ export { default as usePaintState } from './../canvas/hooks/usePaintState.js';
19
+ export { default as useReactPaint, type UseReactPaintProps, type UseReactPaintReturnType } from './../canvas/hooks/useReactPaint.js';
20
+ export type { ChangeSource, ContextMenuState, DataChanges, EditorActions, EditorState, ExportImageFormat, ExportImageOptions, ExportView, InteractionMode, InteractionState, ReactPaint, ReactPaintEventName, ReactPaintEvents, ResolvedOptions, SelectionHover, SelectionUpdateMode, ShapePointerInfo, ShapeStyleField, ShapesActionOptions, ShapesBounds, ShapesOrderAction, ShapesTransformAction, ToolSettingValue, ZoomAction } from './../canvas/types/editor.js';
21
+ export type { EditableShapeType, ExportedDrawableShape as DrawableShape, ExportedDrawableShape, ExportedShape, Point, Rect, ShapeData, ShapeEntity, ShapeInput, ShapePatch, ShapeType, StateData, StyleShape, TextShapeInput } from './../canvas/types/Shapes.js';
22
+ export type { ActionsTool, CustomTool, CustomToolInput, ToolsType } from './../canvas/types/tools.js';
23
+ export { shallowEqual } from './../canvas/utils/equality.js';
24
+ export { getSelectedShapes, getSelectedShapesTools } from './../canvas/utils/selectedShapes.js';
25
+ export type { CanvasComponentProps };
26
+ export { Canvas };
@@ -1 +1 @@
1
- import{n as e,r as t,t as n}from"../_chunks/canvas-DF1RWuxW.js";export{t as DEFAULT_OPTIONS,n as default,e as useReactPaint};
1
+ export{t as Canvas,f as DEFAULT_OPTIONS,p as DEFAULT_TOOLS,c as GRID_PRESETS,m as MOVE_TOOL,a as PaintProvider,h as SELECTION_TOOL,s as ZOOM_LEVELS,l as getSelectedShapes,u as getSelectedShapesTools,d as shallowEqual,r as useAnnotationsStyle,o as usePaint,i as usePaintState,n as useReactPaint}from"../_chunks/canvas-CDYlr833.js";
@@ -0,0 +1,14 @@
1
+ type StoreListener = () => void;
2
+ type Store<T> = {
3
+ getState: () => T;
4
+ /** Replaces the state. Listeners are notified when it changes, once at the end of the outermost batch */
5
+ setState: (updater: T | ((state: T) => T)) => void;
6
+ subscribe: (listener: StoreListener) => () => void;
7
+ /** Calls onChange with the new and the previous value when the selected value changes, compared with isEqual. Returns the function that unsubscribes it */
8
+ watch: <S>(select: (state: T) => S, onChange: (value: S, previous: S) => void, isEqual?: (a: S, b: S) => boolean) => () => void;
9
+ /** Runs the function and notifies the listeners only once at the end, if the state changed */
10
+ batch: <R>(fn: () => R) => R;
11
+ };
12
+ /** Minimal external store, usable with useSyncExternalStore. It knows nothing about React */
13
+ export declare const createStore: <T>(initialState: T) => Store<T>;
14
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { ReactPaint, ReactPaintEventArgs, ReactPaintEventName } from './../../canvas/types/editor.js';
2
+ type EmitEvent = <E extends ReactPaintEventName>(event: E, ...args: ReactPaintEventArgs[E]) => void;
3
+ type EventEmitter = {
4
+ registerEvent: ReactPaint['registerEvent'];
5
+ unregisterEvent: ReactPaint['unregisterEvent'];
6
+ emit: EmitEvent;
7
+ /** Whether a listener is registered, to skip the work of an event nobody listens to */
8
+ hasListeners: (event: ReactPaintEventName) => boolean;
9
+ };
10
+ export declare const createEventEmitter: () => EventEmitter;
11
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { PaintStore } from './../../canvas/store/paintStore.js';
2
+ import type { ReactPaint } from './../../canvas/types/editor.js';
3
+ /** Creates the public handle of a store */
4
+ export declare const createReactPaint: (store: PaintStore) => ReactPaint;
5
+ export declare const getPaintStore: (paint: ReactPaint) => PaintStore;