@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
@@ -0,0 +1,45 @@
1
+ import type { PictureSrcResolver, UtilsSettings } from './../../canvas/constants/app.js';
2
+ import type { EditableShapeType, ShapeEntity, ShapeInput } from './../../canvas/types/Shapes.js';
3
+ import type { CustomTool } from './../../canvas/types/tools.js';
4
+ export declare const isEditableShapeType: (type: unknown) => type is EditableShapeType;
5
+ /** Checks that a shape, or a patch, only has the fields of its type */
6
+ export declare const getUnknownFieldError: (shape: Record<string, unknown>, type: EditableShapeType) => string | undefined;
7
+ /** Checks the types of the common fields given to create or update a shape */
8
+ export declare const getCommonFieldsError: (shape: Record<string, unknown>) => string | undefined;
9
+ /** Checks the geometry of a shape of the type: other fields are not read */
10
+ export declare const getGeometryError: (shape: Record<string, unknown>, type: EditableShapeType) => string | undefined;
11
+ /**
12
+ * Checks a shape given to create or update a shape: its type, the fields allowed for this type and its geometry.
13
+ * Returns the error message, or undefined when the shape is valid.
14
+ */
15
+ export declare const getShapeInputError: (shape: unknown) => string | undefined;
16
+ /** Throws an error naming the faulty shape when one of them is invalid */
17
+ export declare const assertValidShapes: (shapes: unknown[], action: string) => void;
18
+ type BuildShapeOptions = {
19
+ ctx: CanvasRenderingContext2D;
20
+ settings: UtilsSettings;
21
+ tools: CustomTool[];
22
+ /** Ids already taken: an id given with the shape is kept when it is free. The id of the new shape is added to it */
23
+ usedIds: Set<string>;
24
+ /** Completes the style with the default style of the tool of the shape. Loaded shapes keep their own style */
25
+ completeStyle: boolean;
26
+ };
27
+ /** Builds the entity of a shape given by the consumer. The image of a picture is created empty: see loadPicture */
28
+ export declare const buildShapeEntity: (input: ShapeInput, { ctx, settings, tools, usedIds, completeStyle }: BuildShapeOptions) => ShapeEntity;
29
+ type DecodeOptions = Omit<BuildShapeOptions, 'completeStyle'> & {
30
+ resolvePictureSrc: PictureSrcResolver | undefined;
31
+ };
32
+ /** A picture of loaded data whose image cannot be loaded, and the reason */
33
+ type FailedPicture = {
34
+ shape: ShapeEntity<'picture'>;
35
+ error: unknown;
36
+ };
37
+ /**
38
+ * Builds the shapes of loaded data and waits for their pictures. The shapes of an unknown type are left out, like the
39
+ * pictures which cannot be loaded, with a warning: these pictures are returned apart. The others keep their style.
40
+ */
41
+ export declare const decodeImportedData: (inputs: ShapeInput[], { resolvePictureSrc, ...options }: DecodeOptions) => Promise<{
42
+ shapes: ShapeEntity[];
43
+ failedPictures: FailedPicture[];
44
+ }>;
45
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { UtilsSettings } from './../../canvas/constants/app.js';
2
+ import type { ShapeEntity, ShapePatch } from './../../canvas/types/Shapes.js';
3
+ /** Throws an error naming the faulty patch when one of them is invalid. The patches of unknown shapes are ignored */
4
+ export declare const assertValidPatches: (patches: unknown[], shapesById: ReadonlyMap<string, ShapeEntity>) => void;
5
+ /**
6
+ * Applies a patch to a shape: its fields replace the current ones, except the style which is merged. A square keeps
7
+ * equal sides. The box of a text follows its new content or font size; its font size follows a new width or font,
8
+ * like in the editor. The image of a picture whose source changes is reloaded by the caller.
9
+ */
10
+ export declare const applyShapePatch: (ctx: CanvasRenderingContext2D, shape: ShapeEntity, patch: ShapePatch, settings: UtilsSettings) => ShapeEntity;
@@ -1,12 +1,12 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, Rect, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
4
- import type { ToolsSettingsType } from './../../../common/types/tools';
5
- import { type GroupResizeContext } from './group';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, Rect, SelectionType, ShapeEntity } from './../../../canvas/types/Shapes.js';
4
+ import type { ToolsSettingsType } from './../../../canvas/types/tools.js';
5
+ import { type GroupResizeContext } from './group.js';
6
6
  export declare const getBrushBorder: (brush: DrawableShape<"brush">, { selectionPadding }: Pick<UtilsSettings, "selectionPadding">) => Rect;
7
7
  export declare const refreshBrush: <T extends DrawableShape<"brush">>(brush: T & {
8
8
  id: string;
9
- }, settings: UtilsSettings) => ShapeEntity<"brush">;
9
+ }, settings: UtilsSettings, path?: Path2D) => ShapeEntity<"brush">;
10
10
  export declare const createBrush: (shape: {
11
11
  id: string;
12
12
  type: "brush";
@@ -1,8 +1,8 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
4
- import type { ToolsSettingsType } from './../../../common/types/tools';
5
- import { type GroupResizeContext } from './group';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, SelectionType, ShapeEntity } from './../../../canvas/types/Shapes.js';
4
+ import type { ToolsSettingsType } from './../../../canvas/types/tools.js';
5
+ import { type GroupResizeContext } from './group.js';
6
6
  export declare const refreshCircle: <T extends DrawableShape<"circle">>(shape: T & {
7
7
  id: string;
8
8
  }, settings: UtilsSettings) => ShapeEntity<"circle">;
@@ -1,7 +1,7 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, ShapeEntity } from './../../../common/types/Shapes';
4
- import type { ToolsSettingsType } from './../../../common/types/tools';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, ShapeEntity } from './../../../canvas/types/Shapes.js';
4
+ import type { ToolsSettingsType } from './../../../canvas/types/tools.js';
5
5
  export declare const refreshCurve: <T extends DrawableShape<"curve">>(shape: T & {
6
6
  id: string;
7
7
  }, settings: UtilsSettings) => ShapeEntity<"curve">;
@@ -1,8 +1,8 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
4
- import type { ToolsSettingsType } from './../../../common/types/tools';
5
- import { type GroupResizeContext } from './group';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, SelectionType, ShapeEntity } from './../../../canvas/types/Shapes.js';
4
+ import type { ToolsSettingsType } from './../../../canvas/types/tools.js';
5
+ import { type GroupResizeContext } from './group.js';
6
6
  export declare const refreshEllipse: <T extends DrawableShape<"ellipse">>(shape: T & {
7
7
  id: string;
8
8
  }, settings: UtilsSettings) => ShapeEntity<"ellipse">;
@@ -1,6 +1,6 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { Point, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { Point, Rect, SelectionType, ShapeEntity } from './../../../canvas/types/Shapes.js';
4
4
  /** Shared context when resizing shapes inside a group */
5
5
  export type GroupResizeContext = {
6
6
  newBorderX: number;
@@ -21,6 +21,12 @@ export type GroupResizeContext = {
21
21
  height: number;
22
22
  };
23
23
  };
24
+ /** Context to resize the shapes of a group (or a single shape) so that the borders of the group become the new ones */
25
+ export declare const buildGroupResizeContext: (group: SelectionType, newBorders: Rect, settings: UtilsSettings, { isXinverted, isYinverted, rotation }?: {
26
+ isXinverted?: boolean;
27
+ isYinverted?: boolean;
28
+ rotation?: number;
29
+ }) => GroupResizeContext;
24
30
  export declare const getGroupResizeContext: (cursorPosition: Point, group: SelectionType & {
25
31
  type: "group";
26
32
  }, selectionMode: SelectionModeResize, settings: UtilsSettings, keepRatio: boolean, isAltPressed: boolean) => GroupResizeContext;
@@ -1,19 +1,43 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { HoverModeData, SelectionModeData, SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, Rect, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
4
- import type { CustomTool } from './../../../common/types/tools';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { HoverModeData, SelectionModeData, SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, Rect, SelectionType, ShapeEntity, StyleShape } from './../../../canvas/types/Shapes.js';
4
+ import type { CustomTool } from './../../../canvas/types/tools.js';
5
+ import { type GroupResizeContext } from './group.js';
5
6
  export declare const createShape: (ctx: CanvasRenderingContext2D, shape: Exclude<CustomTool, {
6
7
  type: "picture";
7
8
  }>, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity | undefined;
8
9
  export declare const drawShape: (ctx: CanvasRenderingContext2D, shape: ShapeEntity, settings: UtilsSettings, currentView?: Rect) => void;
9
10
  export declare const rotateShape: <T extends ShapeEntity>(shape: T, rotationToApply: number, selectionCenter: Point) => T;
10
11
  export declare const resizeShape: <T extends ShapeEntity>(ctx: CanvasRenderingContext2D, cursorPosition: Point, originalShape: T, selectionMode: SelectionModeData<Point | number>, settings: UtilsSettings, isShiftPressed: boolean, isAltPressed: boolean) => T;
12
+ /**
13
+ * Whether shapes resized together keep their proportions: a group with a shape keeping its ratio, or with shapes
14
+ * turned differently, cannot be stretched
15
+ */
16
+ export declare const mustKeepRatio: (shapes: ShapeEntity[]) => boolean;
17
+ /** Resizes a shape of a group (or a single shape) to the new borders of the group described by the context */
18
+ export declare const resizeShapeInGroup: (ctx: CanvasRenderingContext2D, shape: ShapeEntity, group: SelectionType, groupCtx: GroupResizeContext) => ShapeEntity;
11
19
  export declare const resizeShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point, originalShape: SelectionType, selectionMode: SelectionModeResize<Point | number>, settings: UtilsSettings, isShiftPressed: boolean, isAltPressed: boolean) => ShapeEntity[];
12
- export declare const flipShapes: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], selectedShapes: ShapeEntity[], center: Point, action: "flipHorizontally" | "flipVertically", settings: UtilsSettings) => ShapeEntity[];
20
+ /** Content box of a selection: its borders without the padding of the selection */
21
+ export declare const getSelectionBounds: (selection: SelectionType, settings: UtilsSettings) => Rect;
22
+ /**
23
+ * Resizes shapes so that the content box of their selection becomes the given box. When they must keep their
24
+ * proportions, the box is reduced to keep them, from its top left corner
25
+ */
26
+ export declare const resizeShapesToBounds: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], bounds: Rect, settings: UtilsSettings) => ShapeEntity[];
27
+ /** Flips shapes around the center of their group */
28
+ export declare const flipShapes: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], action: "flipHorizontally" | "flipVertically", settings: UtilsSettings) => ShapeEntity[];
29
+ export declare const translateShape: (shape: ShapeEntity, translationX: number, translationY: number, settings: UtilsSettings) => ShapeEntity;
13
30
  export declare const translateShapes: (cursorPosition: Point, originalShape: SelectionType, originalCursorPosition: Point, settings: UtilsSettings, isShiftPressed: boolean) => ShapeEntity[];
14
31
  export declare const refreshShape: (shape: DrawableShape & {
15
32
  id: string;
16
33
  }, settings: UtilsSettings) => ShapeEntity;
34
+ /** A point can only be removed from a polygon or a curve keeping at least 2 points */
35
+ export declare const canRemoveShapePoint: (shape: ShapeEntity | undefined, pointIndex: number | undefined) => shape is ShapeEntity<"polygon"> | ShapeEntity<"curve">;
36
+ /**
37
+ * Returns the shape with the new style values. Font fields only apply to texts, whose font size is fitted
38
+ * to their width: a shape is returned unchanged when no field applies to it.
39
+ */
40
+ export declare const updateShapeStyle: (ctx: CanvasRenderingContext2D, shape: ShapeEntity, style: StyleShape, settings: UtilsSettings) => ShapeEntity;
17
41
  export declare const drawShapeSelection: ({ ctx, shape, settings, selectionWidth, selectionColor, hoverMode, selectionMode, withAnchors }: {
18
42
  ctx: CanvasRenderingContext2D;
19
43
  shape: SelectionType;
@@ -32,4 +56,6 @@ export declare const drawSelectionFrame: ({ ctx, selectionFrame, settings }: {
32
56
  };
33
57
  settings: UtilsSettings;
34
58
  }) => void;
59
+ /** Copy of a shape with a new id. The copy does not share the data of the application with the original */
60
+ export declare const cloneShape: <T extends ShapeEntity>(shape: T) => T;
35
61
  export declare const copyShapes: (groupShape: SelectionType, settings: UtilsSettings) => ShapeEntity[];
@@ -1,8 +1,8 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, SelectionType, ShapeEntity, StyleShape, Triangle } from './../../../common/types/Shapes';
4
- import type { ToolsSettingsType } from './../../../common/types/tools';
5
- import { type GroupResizeContext } from './group';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, SelectionType, ShapeEntity, StyleShape, Triangle } from './../../../canvas/types/Shapes.js';
4
+ import type { ToolsSettingsType } from './../../../canvas/types/tools.js';
5
+ import { type GroupResizeContext } from './group.js';
6
6
  export declare const refreshLine: <T extends DrawableShape<"line">>(line: T & {
7
7
  id: string;
8
8
  }, settings: UtilsSettings) => ShapeEntity<"line">;
@@ -1,17 +1,25 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { Circle, DrawableShape, Line, Point, Rect } from './../../../common/types/Shapes';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { Circle, DrawableShape, Line, Point, Rect, ShapeEntity } from './../../../canvas/types/Shapes.js';
3
+ import { type Bounds } from './../../../canvas/utils/trigo.js';
3
4
  export declare const createRecPath: (rect: Rect) => Path2D;
4
5
  export declare const createCirclePath: (shape: Circle) => Path2D;
5
6
  export declare const createEllipsePath: (ellipse: DrawableShape<"ellipse">) => Path2D;
6
7
  export declare const createLinePath: (line: Line) => Path2D;
8
+ /** Bounds of the points of a brush, without its scale */
9
+ export declare const getBrushPointsBounds: (points: Point[][]) => Bounds;
10
+ /** The points of a brush with a new point at the end of a stroke, or in a new stroke when the index is the number of strokes */
11
+ export declare const addBrushPoint: (points: Point[][], strokeIndex: number, point: Point) => Point[][];
12
+ /** Places the points of a brush as they are drawn: scaled from the top left corner of the brush */
13
+ export declare const getBrushPointScaler: (brush: DrawableShape<"brush">) => ((point: Point) => Point);
14
+ /**
15
+ * The path of the brush with a new point at the end of its last stroke, extended instead of built again from all
16
+ * the points. Undefined when it must be built again: a single point is drawn as a square, and the end of a smoothed
17
+ * stroke changes with each point
18
+ */
19
+ export declare const extendBrushPath: (brush: ShapeEntity<"brush">, point: Point, { brushAlgo }: UtilsSettings) => Path2D | undefined;
7
20
  export declare const createBrushPath: (brush: DrawableShape<"brush">, { brushAlgo }: UtilsSettings) => Path2D;
8
21
  /** Bounding box of a cubic Bezier segment B(t) = (1-t)³P0 + 3(1-t)²t P1 + 3(1-t)t² P2 + t³ P3 */
9
- export declare const getCubicBezierBounds: (p0: Point, p1: Point, p2: Point, p3: Point) => {
10
- minX: number;
11
- maxX: number;
12
- minY: number;
13
- maxY: number;
14
- };
22
+ export declare const getCubicBezierBounds: (p0: Point, p1: Point, p2: Point, p3: Point) => Bounds;
15
23
  export declare const getCatmullRomPoints: (curve: DrawableShape<"curve">, points: Point[]) => Point[];
16
24
  export declare const catmullRomToBezier: (p0: Point, p1: Point, p2: Point, p3: Point) => {
17
25
  cp1: Point;
@@ -1,11 +1,13 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
4
- import { type GroupResizeContext } from './group';
1
+ import type { PictureSrcResolver, UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, SelectionType, ShapeEntity } from './../../../canvas/types/Shapes.js';
4
+ import { type GroupResizeContext } from './group.js';
5
5
  export declare const refreshPicture: <T extends DrawableShape<"picture">>(shape: T & {
6
6
  id: string;
7
7
  }, settings: UtilsSettings) => ShapeEntity<"picture">;
8
- export declare const createPicture: (fileOrUrl: File | string, maxPictureWidth: number, maxPictureHeight: number, settings: UtilsSettings) => Promise<ShapeEntity<"picture">>;
8
+ export declare const createPicture: (fileOrUrl: File | string, maxPictureWidth: number, maxPictureHeight: number, settings: UtilsSettings, resolvePictureSrc: PictureSrcResolver | undefined,
9
+ /** Center of the picture in the drawing, the center of the visible area by default */
10
+ center?: Point) => Promise<ShapeEntity<"picture">>;
9
11
  export declare const drawPicture: (ctx: CanvasRenderingContext2D, picture: ShapeEntity<"picture">) => void;
10
12
  export declare const resizePicture: (cursorPosition: Point, originalShape: ShapeEntity<"picture">, selectionMode: SelectionModeResize, settings: UtilsSettings, resizeFromCenter: boolean) => ShapeEntity<"picture">;
11
13
  export declare const resizePictureInGroup: (shape: ShapeEntity<"picture">, group: SelectionType & {
@@ -1,7 +1,7 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, Polygon, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
- import type { ToolsSettingsType } from './../../../common/types/tools';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, Polygon, Rect, ShapeEntity } from './../../../canvas/types/Shapes.js';
4
+ import type { ToolsSettingsType } from './../../../canvas/types/tools.js';
5
5
  export declare const refreshPolygon: <T extends DrawableShape<"polygon">>(shape: T & {
6
6
  id: string;
7
7
  }, settings: UtilsSettings) => ShapeEntity<"polygon">;
@@ -1,8 +1,8 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, Rect, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
4
- import type { ToolsSettingsType } from './../../../common/types/tools';
5
- import { type GroupResizeContext } from './group';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, Rect, SelectionType, ShapeEntity } from './../../../canvas/types/Shapes.js';
4
+ import type { ToolsSettingsType } from './../../../canvas/types/tools.js';
5
+ import { type GroupResizeContext } from './group.js';
6
6
  type rectish = 'rect' | 'square';
7
7
  export declare const refreshRect: <T extends rectish>(rect: DrawableShape<rectish> & {
8
8
  id: string;
@@ -1,8 +1,8 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { SelectionModeResize } from './../../../common/types/Mode';
3
- import type { DrawableShape, Point, Rect, SelectionType, ShapeEntity, Text } from './../../../common/types/Shapes';
4
- import type { ToolsSettingsType } from './../../../common/types/tools';
5
- import { type GroupResizeContext } from './group';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { SelectionModeResize } from './../../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Point, Rect, SelectionType, ShapeEntity, StyleShape, Text, TextShapeInput } from './../../../canvas/types/Shapes.js';
4
+ import type { ToolsSettingsType } from './../../../canvas/types/tools.js';
5
+ import { type GroupResizeContext } from './group.js';
6
6
  export declare const getComputedText: (text: DrawableShape<"text">, settings: UtilsSettings) => {
7
7
  borders: Rect;
8
8
  outerBorders: Rect;
@@ -12,7 +12,13 @@ export declare const getComputedText: (text: DrawableShape<"text">, settings: Ut
12
12
  export declare const refreshText: <T extends DrawableShape<"text">>(shape: T & {
13
13
  id: string;
14
14
  }, settings: UtilsSettings) => ShapeEntity<"text">;
15
- export declare const calculateTextFontSize: (ctx: CanvasRenderingContext2D, text: string[], maxWidth: number, fontBold: boolean, fontItalic: boolean, fontFamily?: string | undefined) => number;
15
+ /** A text without lines, emptied in the edition box, keeps the height of one */
16
+ export declare const getTextLineCount: (value: string[]) => number;
17
+ export declare const calculateTextFontSize: (ctx: CanvasRenderingContext2D, text: string[], maxWidth: number, fontBold: boolean, fontItalic: boolean, fontFamily?: string) => number;
18
+ export declare const isFontStyleField: (field: keyof StyleShape) => boolean;
19
+ export declare const fitTextFontSize: <T extends DrawableShape<"text">>(ctx: CanvasRenderingContext2D, text: T) => T;
20
+ /** Completes the size of a text which misses it: from its width, from its font size, or else with the default font size */
21
+ export declare const sizeText: <T extends TextShapeInput>(ctx: CanvasRenderingContext2D, text: T) => T & DrawableShape<"text">;
16
22
  export declare const createText: (ctx: CanvasRenderingContext2D, shape: {
17
23
  id: string;
18
24
  type: "text";
@@ -1,4 +1,4 @@
1
- import type { UtilsSettings } from './../../../canvas/constants/app';
2
- import type { Triangle, TriangleEntity } from './../../../common/types/Shapes';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app.js';
2
+ import type { Triangle, TriangleEntity } from './../../../canvas/types/Shapes.js';
3
3
  export declare const createTriangle: (triangle: Triangle, settings: UtilsSettings) => TriangleEntity;
4
4
  export declare const drawTriangle: (ctx: CanvasRenderingContext2D, triangle: TriangleEntity) => void;
@@ -1,3 +1,12 @@
1
- import type { CustomTool, CustomToolInput } from './../../common/types/tools';
2
- import type { RecursivePartial } from './../../common/types/utils';
3
- export declare const sanitizeTools: (tools: RecursivePartial<CustomToolInput>[]) => CustomTool[];
1
+ import type { DrawableShape, StyleShape } from './../../canvas/types/Shapes.js';
2
+ import type { CustomTool, CustomToolInput } from './../../canvas/types/tools.js';
3
+ import type { RecursivePartial } from './../../canvas/types/utils.js';
4
+ /**
5
+ * Builds the tools list used by the canvas. Each partial tool is merged with the default tool of the same type,
6
+ * arrays (like color values) being replaced instead of merged. Without input, default tools are returned.
7
+ */
8
+ export declare const buildAvailableTools: (tools: RecursivePartial<CustomToolInput>[] | undefined) => CustomTool[];
9
+ /** The tool of a shape: the one it was drawn with, or else the first tool of its type */
10
+ export declare const findShapeTool: (tools: CustomTool[], shape: Pick<DrawableShape, "toolId" | "type">) => CustomTool | undefined;
11
+ /** Style made of the default values of the settings of a tool */
12
+ export declare const getToolDefaultStyle: (tool: CustomTool | undefined) => StyleShape;
@@ -1,12 +1,13 @@
1
- import type { UtilsSettings } from './../../canvas/constants/app';
2
- import type { SelectionModeData } from './../../common/types/Mode';
3
- import type { DrawableShape, Line, Point, SelectionType } from './../../common/types/Shapes';
1
+ import type { UtilsSettings } from './../../canvas/constants/app.js';
2
+ import type { SelectionModeData } from './../../canvas/types/Mode.js';
3
+ import type { DrawableShape, Line, Point, SelectionType, ShapeEntity } from './../../canvas/types/Shapes.js';
4
4
  export declare const roundValues: (prop: number, precision?: number) => number;
5
5
  export declare const scalePoint: (point: Point, minX: number, minY: number, scaleX?: number, scaleY?: number) => Point;
6
6
  export declare const roundForGrid: (value: number, settings: UtilsSettings, gridOffset?: number) => number;
7
7
  export declare const roundRotationForGrid: (rotation: number, settings: UtilsSettings, isShiftPressed: boolean) => number;
8
8
  export declare const boundVectorToSingleAxis: (vector: Point, isShiftPressed: boolean) => Point;
9
- export declare const transformShape: (ctx: CanvasRenderingContext2D, selectedShape: SelectionType, cursorPosition: Point, selectionMode: SelectionModeData<Point | number>, settings: UtilsSettings, isShiftPressed: boolean, isAltPressed: boolean) => SelectionType;
9
+ /** The selected shapes, transformed by the gesture: the selection is built again from them when they are updated */
10
+ export declare const transformSelectedShapes: (ctx: CanvasRenderingContext2D, selectedShape: SelectionType, cursorPosition: Point, selectionMode: SelectionModeData<Point | number>, settings: UtilsSettings, isShiftPressed: boolean, isAltPressed: boolean) => ShapeEntity[];
10
11
  export declare const fitContentInsideContainer: (contentWidth: number, contentHeight: number, containerWidth: number, containerHeight: number, shouldFillContainer?: boolean) => Point;
11
12
  export declare const shortenLine: ({ line, size, direction }: {
12
13
  line: DrawableShape<"line">;
@@ -1,8 +1,24 @@
1
- import type { Circle, Point, Rect } from './../../common/types/Shapes';
1
+ import type { Circle, Point, Rect } from './../../canvas/types/Shapes.js';
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 type Bounds = {
7
+ minX: number;
8
+ minY: number;
9
+ maxX: number;
10
+ maxY: number;
11
+ };
12
+ /**
13
+ * Bounds of the points of several lists, in a single pass. Spreading the points into Math.min would allocate arrays,
14
+ * and fail beyond the maximum number of arguments of a call, which a long brush stroke reaches. Without points, the
15
+ * bounds are infinite, as Math.min() and Math.max()
16
+ */
17
+ export declare const getPointsBounds: (pointLists: readonly (readonly Point[])[]) => Bounds;
18
+ /** The 4 corners of a rectangle, clockwise from its top left corner */
19
+ export declare const getRectCorners: ({ x, y, width, height }: Rect) => Point[];
20
+ /** Smallest rectangle containing the rectangles */
21
+ export declare const getBoundingRect: (rects: Rect[]) => Rect;
6
22
  export declare const isCircleIntersectRect: (rect: Rect, circle: Circle) => boolean;
7
23
  export declare const rotatePoint: ({ origin, point, rotation }: {
8
24
  origin?: Point;
@@ -0,0 +1,14 @@
1
+ export declare const uniqueId: (prefix?: string) => string;
2
+ /**
3
+ * Id of a new shape. It is random, so that it does not collide with the ids of the shapes saved in another session:
4
+ * crypto.randomUUID only exists in secure contexts, otherwise the time, a random part and a counter are used.
5
+ */
6
+ export declare const createShapeId: (type: string) => string;
7
+ export declare const clamp: (value: number, min: number, max: number) => number;
8
+ export declare const isMacOs: () => boolean;
9
+ /**
10
+ * Value of a style property that a CSS variable set on any parent element overrides, without !important.
11
+ * The canvas never sets these variables itself, otherwise it would hide the ones of the parents.
12
+ * Without fallback, the property falls back to its inherited or initial value when the variable is not set.
13
+ */
14
+ export declare const cssVar: (name: `--${string}`, fallback?: string | number) => string;
@@ -1,18 +1,22 @@
1
- import type { UtilsSettings } from './../../canvas/constants/app';
2
- import type { CanvasSize, Size } from './../../common/types/Canvas';
3
- import type { Point, Rect } from './../../common/types/Shapes';
4
- export declare const getNewOffset: ({ size, zoom, newOffset: [x, y], canvasSize }: {
5
- zoom: number;
1
+ import type { UtilsSettings } from './../../canvas/constants/app.js';
2
+ import type { CanvasSize, Size } from './../../canvas/types/Canvas.js';
3
+ import type { Point, Rect } from './../../canvas/types/Shapes.js';
4
+ /** Keeps a zoom level between the smallest and the largest zoom levels */
5
+ export declare const clampZoom: (zoom: number) => number;
6
+ /** Bounds of the view: the visible area at zoom 1 and the size of the drawing, which limits the view when its size is fixed */
7
+ export type ViewBounds = {
6
8
  size: Size;
7
- newOffset: Point;
8
9
  canvasSize: CanvasSize;
10
+ drawingSize: UtilsSettings['drawingSize'];
11
+ };
12
+ export declare const getNewOffset: ({ size, zoom, newOffset: [x, y], canvasSize, drawingSize }: ViewBounds & {
13
+ zoom: number;
14
+ newOffset: Point;
9
15
  }) => {
10
16
  zoom: number;
11
17
  offset: Point;
12
18
  };
13
- export declare const calculateNewZoomAndOffset: ({ size, canvasSize, currentOffset, currentZoom, zoom, centerPoint: iCenterPoint }: {
14
- size: Size;
15
- canvasSize: CanvasSize;
19
+ export declare const calculateNewZoomAndOffset: ({ currentOffset, currentZoom, zoom, centerPoint, ...bounds }: ViewBounds & {
16
20
  currentOffset: Point;
17
21
  currentZoom: number;
18
22
  zoom: number;
@@ -21,9 +25,7 @@ export declare const calculateNewZoomAndOffset: ({ size, canvasSize, currentOffs
21
25
  offset: Point;
22
26
  zoom: number;
23
27
  };
24
- export declare const getNewZoomAndOffset: ({ size, canvasSize, currentOffset, currentZoom, action }: {
25
- size: Size;
26
- canvasSize: CanvasSize;
28
+ export declare const getNewZoomAndOffset: ({ currentOffset, currentZoom, action, ...bounds }: ViewBounds & {
27
29
  currentOffset: Point;
28
30
  currentZoom: number;
29
31
  action: "unzoom" | "zoom" | "default";
@@ -31,9 +33,7 @@ export declare const getNewZoomAndOffset: ({ size, canvasSize, currentOffset, cu
31
33
  offset: Point;
32
34
  zoom: number;
33
35
  };
34
- export declare const getNewZoomAndOffsetFromDelta: ({ size, canvasSize, currentOffset, currentZoom, delta, centerPoint }: {
35
- size: Size;
36
- canvasSize: CanvasSize;
36
+ export declare const getNewZoomAndOffsetFromDelta: ({ currentOffset, currentZoom, delta, centerPoint, ...bounds }: ViewBounds & {
37
37
  currentOffset: Point;
38
38
  currentZoom: number;
39
39
  delta: number;
@@ -42,13 +42,27 @@ export declare const getNewZoomAndOffsetFromDelta: ({ size, canvasSize, currentO
42
42
  offset: Point;
43
43
  zoom: number;
44
44
  };
45
+ /** Zoom and offset showing the whole box in the middle of the view, with a margin in pixels of the screen */
46
+ export declare const getZoomAndOffsetToFit: ({ box, padding, ...bounds }: ViewBounds & {
47
+ box: Rect;
48
+ padding: number;
49
+ }) => {
50
+ offset: Point;
51
+ zoom: number;
52
+ };
45
53
  export declare const getCurrentView: (settings: UtilsSettings) => Rect;
54
+ /** The drawing, in pixels of the canvas */
46
55
  export declare const getMaskRect: (settings: UtilsSettings) => {
47
56
  x: number;
48
57
  y: number;
49
58
  width: number;
50
59
  height: number;
51
60
  };
61
+ /**
62
+ * Whether a mask is drawn around the drawing: its size is fixed and it is smaller than the view. A drawing larger than
63
+ * the view on an axis covers it, its offset being kept inside the drawing
64
+ */
65
+ export declare const hasMask: ({ size, canvasZoom, canvasSize, drawingSize }: UtilsSettings) => boolean;
52
66
  export declare const clipMask: (ctx: CanvasRenderingContext2D, settings: UtilsSettings) => void;
53
67
  export declare const drawMask: (ctx: CanvasRenderingContext2D, settings: UtilsSettings) => void;
54
68
  export declare const isCursorInsideMask: (cursorPosition: Point, settings: UtilsSettings) => boolean;
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import './Button.css';
3
2
  type CommonType = {
4
3
  hidden?: boolean | undefined;
5
4
  disabled?: boolean | undefined;
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import './Button.css';
3
2
  declare const FileInput: React.ForwardRefExoticComponent<{
4
3
  hidden?: boolean | undefined;
5
4
  disabled?: boolean | undefined;
@@ -1,6 +1,5 @@
1
- import './Loading.css';
2
1
  export type LoadingType = {
3
2
  isLoading: boolean;
4
3
  };
5
- declare const Loading: ({ isLoading }: LoadingType) => import("react/jsx-runtime").JSX.Element | null;
4
+ declare const Loading: ({ isLoading }: LoadingType) => import("react").JSX.Element | null;
6
5
  export default Loading;
@@ -1,10 +1,11 @@
1
- import './Menu.css';
2
1
  type MenuType = {
3
2
  alignment?: 'left' | 'center' | 'right' | undefined;
4
3
  children: React.ReactNode;
5
4
  className?: string;
6
5
  style?: React.CSSProperties;
7
6
  position?: 'top' | 'bottom' | 'left' | 'right' | undefined;
7
+ /** Ref of the element of the menu, which contains its sub menus */
8
+ menuRef?: React.Ref<HTMLDivElement>;
8
9
  };
9
- declare const Menu: ({ alignment, children, className, style, position }: MenuType) => import("react/jsx-runtime").JSX.Element;
10
+ declare const Menu: ({ alignment, children, className, style, position, menuRef }: MenuType) => import("react").JSX.Element;
10
11
  export default Menu;
@@ -1,5 +1,4 @@
1
1
  import type { ReactNode } from 'react';
2
- import './Modal.css';
3
2
  type ModalType = {
4
3
  children: ReactNode;
5
4
  title: string;
@@ -7,5 +6,5 @@ type ModalType = {
7
6
  position?: 'center' | 'bottom';
8
7
  className?: string;
9
8
  };
10
- declare const Modal: ({ children, onClose, position, title, className }: ModalType) => import("react/jsx-runtime").JSX.Element;
9
+ declare const Modal: ({ children, onClose, position, title, className }: ModalType) => import("react").JSX.Element;
11
10
  export default Modal;
@@ -1,5 +1,4 @@
1
1
  import type React from 'react';
2
- import './Panel.css';
3
2
  import type { CSSProperties } from 'react';
4
3
  type PanelType = {
5
4
  vertical?: boolean;
@@ -11,5 +10,5 @@ type PanelType = {
11
10
  position?: 'bottom' | 'top' | 'left' | 'right' | undefined;
12
11
  alignment?: 'left' | 'right' | 'center' | undefined;
13
12
  };
14
- declare const Panel: ({ children, title, className, position, fitContainer, alignment, style, ...props }: PanelType) => import("react/jsx-runtime").JSX.Element;
13
+ declare const Panel: ({ children, title, className, position, fitContainer, alignment, style, ...props }: PanelType) => React.JSX.Element;
15
14
  export default Panel;
@@ -1,7 +1,6 @@
1
- import type { SnackBarType } from './../../../editor/types/snackbar';
2
- import './Snackbar.css';
1
+ import type { SnackBarType } from './../../../editor/types/snackbar.js';
3
2
  type SnackbarContainerType = {
4
3
  snackbarList: SnackBarType[];
5
4
  };
6
- declare const SnackbarContainer: ({ snackbarList }: SnackbarContainerType) => import("react/jsx-runtime").JSX.Element;
5
+ declare const SnackbarContainer: ({ snackbarList }: SnackbarContainerType) => import("react").JSX.Element;
7
6
  export default SnackbarContainer;
@@ -6,5 +6,5 @@ type ClosedPointsType = {
6
6
  defaultValue?: number | undefined;
7
7
  valueChanged: (field: string, value: string | number) => void;
8
8
  };
9
- declare const ClosedPointsField: ({ selectedSettings, setSelectedSettings, disabled, defaultValue, valueChanged }: ClosedPointsType) => import("react/jsx-runtime").JSX.Element;
9
+ declare const ClosedPointsField: ({ selectedSettings, setSelectedSettings, disabled, defaultValue, valueChanged }: ClosedPointsType) => React.JSX.Element;
10
10
  export default ClosedPointsField;
@@ -1,5 +1,4 @@
1
1
  import type React from 'react';
2
- import './ColorField.css';
3
2
  type ShapeStyleColorType = {
4
3
  selectedSettings: string | undefined;
5
4
  setSelectedSettings: React.Dispatch<React.SetStateAction<string | undefined>>;
@@ -11,5 +10,5 @@ type ShapeStyleColorType = {
11
10
  values: string[];
12
11
  valueChanged: (field: string, value: string | number) => void;
13
12
  };
14
- declare const ColorField: ({ selectedSettings, setSelectedSettings, title, mode, disabled, values, field, value, valueChanged }: ShapeStyleColorType) => import("react/jsx-runtime").JSX.Element | null;
13
+ declare const ColorField: ({ selectedSettings, setSelectedSettings, title, mode, disabled, values, field, value, valueChanged }: ShapeStyleColorType) => React.JSX.Element | null;
15
14
  export default ColorField;